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 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; } Move move = game.GenMove(Player::OfString(player)); inout.out << move.GetLocation().ToCoords(); }
void Protocol::CTimeManagement(Gtp::Io& inout) { if (inout.IsEmpty()) { inout.out << game.GetTimeManager().management << '\n'; inout.out << kManagementPlayoutsPerMove << ' ' << "playouts per move\n"; inout.out << kManagementPlayoutMovesPerGame << ' ' << "playout moves per game\n"; inout.out << kManagementTime << ' ' << "time"; return; } uint choice = inout.Read<uint>(); inout.CheckEmpty(); game.GetTimeManager().management = TimeManagementType(choice); }
void Protocol::CShowBoard(Gtp::Io& inout) { inout.CheckEmpty(); inout.out << std::endl; std::string ascii_board; game.PrintBoard(ascii_board); inout.out << ascii_board; }
void Protocol::CShowTree(Gtp::Io& inout) { uint children = inout.Read<uint>(4); inout.CheckEmpty(); std::string ascii_tree; game.PrintTree(ascii_tree, children); inout.out << std::endl << ascii_tree; }
void Admin::CAddExperimentParam (Gtp::Io& io) { Param p; p.name = QString::fromStdString (io.Read<std::string>()); p.min_value = io.Read<double>(); p.max_value = io.Read<double>(); p.SetFun (QString::fromStdString (io.Read<std::string>())); io.CheckEmpty(); experiment_params.append (p); }
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; } ASSERT (Player::OfString(player) == game.CurrentPlayer()); Move move = game.GenMove(); 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::CAddExperiment (Gtp::Io& io) { QString game_setup = QString::fromStdString (io.Read<std::string>()); io.CheckEmpty(); QStringList ps; foreach (const Param& param, experiment_params) ps.append (param.name); experiment_id = db.AddExperiment (game_setup, first_engine, second_engine, experiment_description, ps); CHECK (experiment_id > 0); first_engine = ""; second_engine = ""; experiment_description = ""; // experiment_params.clear(); // TODO solve it better }
// A simple command. void CAdd (Gtp::Io& io) { io.out << io.Read<int>() + io.Read<int>(11); io.CheckEmpty (); }
void Protocol::CSetMaxTreeDepth(Gtp::Io& inout) { int depth = inout.Read<int>(); inout.CheckEmpty(); game.SetMaxUTCTreeDepth(depth); }
void Protocol::CClearBoard(Gtp::Io& inout) { inout.CheckEmpty(); game.ClearBoard(); }
void Protocol::CSetPlayoutsPerMove(Gtp::Io& inout) { uint playouts = inout.Read<uint>(); inout.CheckEmpty(); game.SetPlayoutsPerMove(playouts); }
void Admin::CSetExperimentDescription (Gtp::Io& io) { experiment_description = QString::fromStdString (io.ReadLine()); }
void Protocol::CAvoidingBridges(Gtp::Io& inout) { int value = inout.Read<int>(); inout.CheckEmpty(); if (value == 0) game.setAvoidingBridges(false); else game.setAvoidingBridges(true); }
void Admin::CAddEngineConfigLine (Gtp::Io& io) { config += "\n" + QString::fromStdString (io.ReadLine ()); io.CheckEmpty (); }
void Admin::CSetEngineCommandLine (Gtp::Io& io) { command_line = QString::fromStdString (io.ReadLine()); }
void Admin::CCloseAllExperiments (Gtp::Io& io) { io.CheckEmpty(); db.CloseAllExperiments(); }