Exemplo n.º 1
0
void Runner::run() {
    remoteProcessClient.writeTokenMessage(token);
    int teamSize = remoteProcessClient.readTeamSizeMessage();
    remoteProcessClient.writeProtocolVersionMessage();
    Game game = remoteProcessClient.readGameContextMessage();

    vector<Strategy*> strategies;

    for (int strategyIndex = 0; strategyIndex < teamSize; ++strategyIndex) {
        Strategy* strategy = new MyStrategy;
        strategies.push_back(strategy);
    }

    PlayerContext* playerContext;

    while ((playerContext = remoteProcessClient.readPlayerContextMessage()) != NULL) {
        vector<Hockeyist> playerHockeyists = playerContext->getHockeyists();
        if ((int) playerHockeyists.size() != teamSize) {
            break;
        }

        vector<Move> moves;

        for (int hockeyistIndex = 0; hockeyistIndex < teamSize; ++hockeyistIndex) {
            Hockeyist playerHockeyist = playerHockeyists[hockeyistIndex];

            Move move;
            strategies[playerHockeyist.getTeammateIndex()]
                    ->move(playerHockeyist, playerContext->getWorld(), game, move);
            moves.push_back(move);
        }

        remoteProcessClient.writeMovesMessage(moves);

        delete playerContext;
    }

    for (int strategyIndex = 0; strategyIndex < teamSize; ++strategyIndex) {
        delete strategies[strategyIndex];
    }
}