diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 25 |
1 files changed, 17 insertions, 8 deletions
@@ -257,14 +257,26 @@ static void playMatch(Player &p1, Player &p2, int index, const Params ¶ms) { procs[0].run(); procs[1].run(); + const auto handleWriteLines = [&referee, &procs]() { + for (const auto &p : referee.playerWriteLines()) { + assert(0 <= p.first && p.first < 2); + procs[p.first].writeLine(p.second); + } + }; + + // Received upon initialisation of referee + handleWriteLines(); + string lastMove = "Start"; while (true) { for (int i = 0; i < 2; i++) { - if (!procs[i].writeLine(lastMove)) { - cout << "ERROR writing move to player " << i+1 - << " (game " << gameCodeName(p1, p2, index) << ")" << endl; - throw StopCompetitionError(); + if (!referee.getFeatures().noLastMove) { + if (!procs[i].writeLine(lastMove)) { + cout << "ERROR writing move to player " << i+1 + << " (game " << gameCodeName(p1, p2, index) << ")" << endl; + throw StopCompetitionError(); + } } procs[i].unStop(); @@ -296,10 +308,7 @@ static void playMatch(Player &p1, Player &p2, int index, const Params ¶ms) { throw StopCompetitionError(); } - for (const auto &p : referee.playerWriteLines()) { - assert(0 <= p.first && p.first < 2); - procs[p.first].writeLine(p.second); - } + handleWriteLines(); if (referee.gameEnded()) { mres.status = MatchResult::Status::ok; |