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]; } }
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]; } }
void RemoteProcessClient::writePlayerContext(const PlayerContext& playerContext) { writeBoolean(true); writeCars(playerContext.getCars()); writeWorld(playerContext.getWorld()); }