Search in sources :

Example 1 with GameSequence

use of games.strategy.engine.data.GameSequence in project triplea by triplea-game.

the class ProUtils method getOtherPlayersInTurnOrder.

public static List<PlayerID> getOtherPlayersInTurnOrder(final PlayerID player) {
    final GameData data = ProData.getData();
    final List<PlayerID> players = new ArrayList<>();
    final GameSequence sequence = data.getSequence();
    final int startIndex = sequence.getStepIndex();
    for (int i = 0; i < sequence.size(); i++) {
        int currentIndex = startIndex + i;
        if (currentIndex >= sequence.size()) {
            currentIndex -= sequence.size();
        }
        final GameStep step = sequence.getStep(currentIndex);
        final PlayerID stepPlayer = step.getPlayerId();
        if (step.getName().endsWith("CombatMove") && stepPlayer != null && !stepPlayer.equals(player) && !players.contains(stepPlayer)) {
            players.add(step.getPlayerId());
        }
    }
    return players;
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) GameData(games.strategy.engine.data.GameData) ArrayList(java.util.ArrayList) GameStep(games.strategy.engine.data.GameStep) GameSequence(games.strategy.engine.data.GameSequence)

Example 2 with GameSequence

use of games.strategy.engine.data.GameSequence in project triplea by triplea-game.

the class PlayerOrderComparator method compare.

/**
 * sort based on first step that isn't a bid related step.
 */
@Override
public int compare(final PlayerID p1, final PlayerID p2) {
    if (p1.equals(p2)) {
        return 0;
    }
    gameData.acquireReadLock();
    final GameSequence sequence;
    try {
        sequence = gameData.getSequence();
    } finally {
        gameData.releaseReadLock();
    }
    for (final GameStep s : sequence) {
        if (s.getPlayerId() == null) {
            continue;
        }
        gameData.acquireReadLock();
        final IDelegate delegate;
        try {
            delegate = s.getDelegate();
        } finally {
            gameData.releaseReadLock();
        }
        if (delegate != null && delegate.getClass() != null) {
            final String delegateClassName = delegate.getClass().getName();
            if (delegateClassName.equals("games.strategy.triplea.delegate.InitializationDelegate") || delegateClassName.equals("games.strategy.triplea.delegate.BidPurchaseDelegate") || delegateClassName.equals("games.strategy.triplea.delegate.BidPlaceDelegate") || delegateClassName.equals("games.strategy.triplea.delegate.EndRoundDelegate")) {
                continue;
            }
        } else if (s.getName() != null && (s.getName().endsWith("Bid") || s.getName().endsWith("BidPlace"))) {
            continue;
        }
        if (s.getPlayerId().equals(p1)) {
            return -1;
        } else if (s.getPlayerId().equals(p2)) {
            return 1;
        }
    }
    return 0;
}
Also used : GameStep(games.strategy.engine.data.GameStep) IDelegate(games.strategy.engine.delegate.IDelegate) GameSequence(games.strategy.engine.data.GameSequence)

Aggregations

GameSequence (games.strategy.engine.data.GameSequence)2 GameStep (games.strategy.engine.data.GameStep)2 GameData (games.strategy.engine.data.GameData)1 PlayerID (games.strategy.engine.data.PlayerID)1 IDelegate (games.strategy.engine.delegate.IDelegate)1 ArrayList (java.util.ArrayList)1