void Protocol::CBoardSize(Gtp::Io& inout) { uint boardSize = inout.Read<uint>(); inout.CheckEmpty(); if (boardSize != Dim::board_size) { std::stringstream err; err << "the only supported board size is " << Dim::board_size; inout.SetError(err.str()); } }
void Admin::CAddGameSetup (Gtp::Io& io) { QString name = QString::fromStdString (io.Read<std::string>()); int board_size = io.Read<int>(); float komi = io.Read<float>(); io.CheckEmpty(); if (!db.AddGameSetup (name, board_size, komi)) io.SetError (""); }
void Protocol::CGenMove(Gtp::Io& inout) { std::string player = inout.Read<std::string>(); inout.CheckEmpty(); if (!Player::ValidPlayer(player)) { inout.SetError("invalid parameters"); return; } if (game.IsFinished()) { inout.SetError("game is finished"); return; } Move move = game.GenMove(Player::OfString(player)); game.Play(move); inout.out << move.GetLocation().ToCoords(); }
void Protocol::CPlay(Gtp::Io& inout) { std::string player = inout.Read<std::string>(); std::string location = inout.Read<std::string>(); inout.CheckEmpty(); if (!Player::ValidPlayer(player) || !Location::ValidLocation(location)) { inout.SetError("invalid parameters"); return; } Move move = Move(Player::OfString(player), Location::OfCoords(location)); if (game.IsValidMove(move)) { game.Play(move); } else { std::stringstream err; err << "invalid move: " << location; inout.SetError(err.str()); } }
void Admin::CSetExperimentEngine (Gtp::Io& io) { int num = io.Read<int> (); if (num != 1 && num != 2) { io.SetError ("wronge engine number"); return; } QString name = QString::fromStdString (io.Read<std::string>()); (num == 1 ? first_engine : second_engine) = name; }
void Admin::CAddEngine (Gtp::Io& io) { QString name = QString::fromStdString (io.Read<std::string>()); io.CheckEmpty(); if (!AddEngine (name, config, command_line)) io.SetError (""); name = ""; config = ""; command_line = ""; }
void Protocol::CGenMoveNoPlay(Gtp::Io& inout) { std::string player = inout.Read<std::string>(); inout.CheckEmpty(); if (game.IsFinished()) { inout.SetError("game is finished"); return; } ASSERT (Player::OfString(player) == game.CurrentPlayer()); Move move = game.GenMove(); inout.out << move.GetLocation().ToCoords(); }