Exemplo n.º 1
0
void Runner::run() {
    remoteProcessClient.writeToken(token);
    int teamSize = remoteProcessClient.readTeamSize();
    remoteProcessClient.writeProtocolVersion();
    Game game = remoteProcessClient.readGameContext();

    vector<Strategy*> strategies;

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

    PlayerContext* playerContext;

    while ((playerContext = remoteProcessClient.readPlayerContext()) != NULL) {
        Trooper playerTrooper = playerContext->getTrooper();

        Move move;
        strategies[playerTrooper.getTeammateIndex()]->move(playerTrooper, playerContext->getWorld(), game, move);
        remoteProcessClient.writeMove(move);

        delete playerContext;
    }

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