本文整理汇总了C++中HtpCommand类的典型用法代码示例。如果您正苦于以下问题:C++ HtpCommand类的具体用法?C++ HtpCommand怎么用?C++ HtpCommand使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HtpCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CmdSolveState
/** Solves the current state with dfpn using the current hashtable. */
void DfpnCommands::CmdSolveState(HtpCommand& cmd)
{
cmd.CheckNuArgLessEqual(3);
HexColor colorToMove = m_game.Board().WhoseTurn();
if (cmd.NuArg() >= 1)
colorToMove = HtpUtil::ColorArg(cmd, 0);
// DfpnBounds::MAX_WORK cannot be used as an argument to ArgMinMax()
// directly, because it is an integral constant class member that is not
// defined anywhere and arguments to ArgMinMax() are passed by reference.
// Older versions of GCC (including the current Cygwin GCC 4.3.4) generate
// and error ("undefined reference to DfpnBounds::MAX_WORK"), probably in
// accordance to the C++ standard. The best solution would be to change
// GtpCommand::ArgMinMax() in Fuego to pass arguments by value.
const DfpnBoundType maxWork = DfpnBounds::MAX_WORK;
DfpnBoundType maxPhi = maxWork;
DfpnBoundType maxDelta = maxWork;
if (cmd.NuArg() >= 2)
maxPhi = cmd.ArgMinMax<DfpnBoundType>(1, 0, maxWork);
if (cmd.NuArg() >= 3)
maxDelta = cmd.ArgMinMax<DfpnBoundType>(2, 0, maxWork);
DfpnBounds maxBounds(maxPhi, maxDelta);
PointSequence pv;
HexBoard& brd = m_env.SyncBoard(m_game.Board());
HexColor winner
= m_solver.StartSearch(HexState(m_game.Board(), colorToMove), brd,
m_positions, pv, maxBounds);
cmd << winner;
}
示例2: SaveGames
/** Saves games from last search to a SGF. */
void MoHexEngine::SaveGames(HtpCommand& cmd)
{
MoHexSearch& search = m_player.Search();
cmd.CheckNuArg(1);
std::string filename = cmd.Arg(0);
search.SaveGames(filename);
}
示例3: MoHexPolicyParam
void MoHexEngine::MoHexPolicyParam(HtpCommand& cmd)
{
MoHexPlayoutPolicyConfig& config = m_player.SharedPolicy().Config();
if (cmd.NuArg() == 0)
{
cmd << '\n'
<< "pattern_check_percent "
<< config.patternCheckPercent << '\n'
<< "pattern_heuristic "
<< config.patternHeuristic << '\n'
<< "response_heuristic "
<< config.responseHeuristic << '\n'
<< "response_threshold "
<< config.responseThreshold << '\n';
}
else if (cmd.NuArg() == 2)
{
std::string name = cmd.Arg(0);
if (name == "pattern_check_percent")
config.patternCheckPercent = cmd.ArgMinMax<int>(1, 0, 100);
else if (name == "pattern_heuristic")
config.patternHeuristic = cmd.Arg<bool>(1);
else if (name == "response_heuristic")
config.responseHeuristic = cmd.Arg<bool>(1);
else if (name == "response_threshold")
config.responseThreshold = cmd.ArgMin<std::size_t>(1, 0);
else
throw HtpFailure("Unknown option!");
}
else
throw HtpFailure("Expected 0 or 2 arguments!");
}
示例4: CmdParamSolverDB
void DfpnCommands::CmdParamSolverDB(HtpCommand& cmd)
{
SolverDBParameters& param = m_positions.Parameters();
if (cmd.NuArg() == 0)
{
cmd << '\n'
<< "[bool] use_flipped_states " << param.m_useFlippedStates << '\n'
<< "[bool] use_proof_transpositions "
<< param.m_useProofTranspositions << '\n'
<< "[string] max_stones " << param.m_maxStones << '\n'
<< "[string] trans_stones " << param.m_transStones << '\n';
}
else if (cmd.NuArg() == 2)
{
std::string name = cmd.Arg(0);
if (name == "use_flipped_states")
param.m_useFlippedStates = cmd.Arg<bool>(1);
else if (name == "use_proof_transpositions")
param.m_useProofTranspositions = cmd.Arg<bool>(1);
else if (name == "max_stones")
param.m_maxStones = cmd.ArgMin<int>(1, 0);
else if (name == "trans_stones")
param.m_transStones = cmd.ArgMin<int>(1, 0);
else
throw HtpFailure() << "unknown parameter: " << name;
}
else
throw HtpFailure("Expected 0 or 2 arguments");
}
示例5: HtpFailure
void BookBuilderCommands<PLAYER>::CmdBookExpand(HtpCommand& cmd)
{
if (m_book.get() == 0)
throw HtpFailure() << "No open book.";
cmd.CheckNuArg(1);
int iterations = cmd.IntArg(0, 1);
HexState state(m_game.Board(), m_game.Board().WhoseTurn());
HexBoard& brd = m_env.SyncBoard(m_game.Board());
m_bookBuilder.SetState(*m_book, state);
m_bookBuilder.SetWorkBoard(brd);
m_bookBuilder.Expand(iterations);
}
示例6: CmdOpenDB
/** Opens a database.
Usage: "db-open [filename]"
*/
void DfpnCommands::CmdOpenDB(HtpCommand& cmd)
{
cmd.CheckNuArgLessEqual(3);
std::string filename = cmd.Arg(0);
try {
m_db.reset(new DfpnDB(filename));
}
catch (BenzeneException& e) {
m_db.reset(0);
throw HtpFailure() << "Error opening db: '" << e.what() << "'\n";
}
}
示例7: SaveTree
/** Saves the search tree from the previous search to the specified
file. The optional second parameter sets the max depth to
output. If not given, entire tree is saved.
*/
void MoHexEngine::SaveTree(HtpCommand& cmd)
{
MoHexSearch& search = m_player.Search();
cmd.CheckNuArg(1);
std::string filename = cmd.Arg(0);
int maxDepth = -1;
std::ofstream file(filename.c_str());
if (!file)
throw HtpFailure() << "Could not open '" << filename << "'";
if (cmd.NuArg() == 2)
maxDepth = cmd.ArgMin<int>(1, 0);
search.SaveTree(file, maxDepth);
}
示例8: CmdFindWinning
/** Finds all winning moves in the current state with dfpn,
using the current hashtable. */
void DfpnCommands::CmdFindWinning(HtpCommand& cmd)
{
cmd.CheckNuArg(1);
HexColor colorToMove = HtpUtil::ColorArg(cmd, 0);
HexBoard& brd = m_env.SyncBoard(m_game.Board());
brd.ComputeAll(colorToMove);
bitset_t consider = (EndgameUtil::IsDeterminedState(brd, colorToMove) ?
brd.GetPosition().GetEmpty() :
EndgameUtil::MovesToConsider(brd, colorToMove));
bitset_t winning;
SgTimer timer;
HexState state(m_game.Board(), colorToMove);
for (BitsetIterator p(consider); p; ++p)
{
state.PlayMove(*p);
HexBoard& brd = m_env.SyncBoard(state.Position());
LogInfo() << "****** Trying " << *p << " ******\n" << brd << '\n';
PointSequence pv;
HexColor winner = m_solver.StartSearch(state, brd, m_positions, pv);
if (winner == colorToMove)
winning.set(*p);
LogInfo() << "****** " << winner << " wins ******\n";
state.UndoMove(*p);
}
LogInfo() << "Total Elapsed Time: " << timer.GetTime() << '\n';
cmd << HexPointUtil::ToString(winning);
}
示例9: CmdCloseDB
/** Closes an open database. */
void DfpnCommands::CmdCloseDB(HtpCommand& cmd)
{
cmd.CheckNuArg(0);
if (m_db.get() == 0)
throw HtpFailure("No open database!\n");
m_db.reset(0);
}
示例10: CmdDBStat
/** Prints database statistics. */
void DfpnCommands::CmdDBStat(HtpCommand& cmd)
{
cmd.CheckNuArg(0);
if (m_db.get() == 0)
throw HtpFailure("No open database!\n");
cmd << m_db->BDBStatistics();
}
示例11: CmdParamSolver
void DfsCommands::CmdParamSolver(HtpCommand& cmd)
{
if (cmd.NuArg() == 0)
{
cmd << '\n'
<< "[bool] backup_ice_info "
<< m_solver.BackupIceInfo() << '\n'
<< "[bool] shrink_proofs "
<< m_solver.ShrinkProofs() << '\n'
<< "[bool] use_decompositions "
<< m_solver.UseDecompositions() << '\n'
<< "[bool] use_guifx "
<< m_solver.UseGuiFx() << '\n'
<< "[string] move_ordering "
<< m_solver.MoveOrdering() << '\n' // FIXME: PRINT NICELY!!
<< "[string] tt_bits "
<< ((m_tt.get() == 0) ? 0 : log2(m_tt->MaxHash())) << '\n'
<< "[string] update_depth "
<< m_solver.UpdateDepth() << '\n';
}
else if (cmd.NuArg() == 2)
{
std::string name = cmd.Arg(0);
if (name == "backup_ice_info")
m_solver.SetBackupIceInfo(cmd.Arg<bool>(1));
else if (name == "shrink_proofs")
m_solver.SetShrinkProofs(cmd.Arg<bool>(1));
else if (name == "use_decompositions")
m_solver.SetUseDecompositions(cmd.Arg<bool>(1));
else if (name == "use_guifx")
m_solver.SetUseGuiFx(cmd.Arg<bool>(1));
else if (name == "move_ordering")
m_solver.SetMoveOrdering(cmd.ArgMinMax<int>(1, 0, 7));
else if (name == "tt_bits")
{
int bits = cmd.ArgMin<int>(1, 0);
if (bits == 0)
m_tt.reset(0);
else
m_tt.reset(new DfsHashTable(1 << bits));
}
else if (name == "update_depth")
m_solver.SetUpdateDepth(cmd.Arg<std::size_t>(1));
else
throw HtpFailure() << "unknown parameter: " << name;
}
}
示例12: CmdParam
void DfpnCommands::CmdParam(HtpCommand& cmd)
{
if (cmd.NuArg() == 0)
{
cmd << '\n'
<< "[bool] use_guifx "
<< m_solver.UseGuiFx() << '\n'
<< "[string] timelimit "
<< m_solver.Timelimit() << '\n'
<< "[string] tt_bits "
<< ((m_tt.get() == 0) ? 0 : log2(m_tt->MaxHash())) << '\n'
<< "[string] widening_base "
<< m_solver.WideningBase() << '\n'
<< "[string] widening_factor "
<< m_solver.WideningFactor() << '\n';
}
else if (cmd.NuArg() == 2)
{
std::string name = cmd.Arg(0);
if (name == "use_guifx")
m_solver.SetUseGuiFx(cmd.Arg<bool>(1));
else if (name == "timelimit")
m_solver.SetTimelimit(cmd.ArgMin<float>(1, 0.0));
else if (name == "tt_bits")
{
int bits = cmd.ArgMin<int>(1, 0);
if (bits == 0)
m_tt.reset(0);
else
m_tt.reset(new DfpnHashTable(1 << bits));
}
else if (name == "widening_base")
m_solver.SetWideningBase(cmd.ArgMin<int>(1, 1));
else if (name == "widening_factor")
{
float value = cmd.Arg<float>(1);
if (0.0f < value && value <= 1.0f)
m_solver.SetWideningFactor(value);
else
throw GtpFailure() << "widening_factor must be in (0, 1]";
}
else
throw GtpFailure() << "Unknown parameter: " << name;
}
else
throw GtpFailure() << "Expected 0 or 2 arguments";
}
示例13: CmdGetState
/** Displays information about the current state from the
hashtable. */
void DfpnCommands::CmdGetState(HtpCommand& cmd)
{
cmd.CheckNuArg(1);
HexColor colorToMove = HtpUtil::ColorArg(cmd, 0);
HexState state(m_game.Board(), colorToMove);
DfpnData data;
if (m_positions.Get(state, data))
cmd << data << '\n';
}
示例14: CmdGetPV
/** Displays PV from current position. */
void DfpnCommands::CmdGetPV(HtpCommand& cmd)
{
cmd.CheckNuArg(1);
HexColor colorToMove = HtpUtil::ColorArg(cmd, 0);
PointSequence pv;
SolverDBUtil::GetVariation(HexState(m_game.Board(), colorToMove),
m_positions, pv);
cmd << HexPointUtil::ToString(pv);
}
示例15: CmdGetState
/** Dumps info from on current state. */
void DfsCommands::CmdGetState(HtpCommand& cmd)
{
cmd.CheckNuArg(0);
HexColor toPlay = m_game.Board().WhoseTurn();
HexState state(m_game.Board(), toPlay);
DfsData data;
if (!m_positions.Get(state, data))
{
cmd << "State not available.";
return;
}
cmd << (data.m_win ? toPlay : !toPlay);
cmd << ' ' << data.m_numMoves;
std::vector<int> nummoves(BITSETSIZE);
std::vector<int> flags(BITSETSIZE);
std::vector<HexPoint> winning, losing;
for (BitsetIterator p(state.Position().GetEmpty()); p; ++p)
{
state.PlayMove(*p);
if (m_positions.Get(state, data))
{
if (data.m_win)
losing.push_back(*p);
else
winning.push_back(*p);
nummoves[*p] = data.m_numMoves;
flags[*p] = data.m_flags;
}
state.UndoMove(*p);
}
cmd << " Winning";
for (unsigned i = 0; i < winning.size(); ++i)
{
cmd << " " << winning[i];
cmd << " " << nummoves[winning[i]];
if (flags[winning[i]] & SolverDataFlags::MIRROR_TRANSPOSITION)
cmd << "m";
else if (flags[winning[i]] & SolverDataFlags::TRANSPOSITION)
cmd << "t";
}
cmd << " Losing";
for (unsigned i = 0; i < losing.size(); ++i)
{
cmd << " " << losing[i];
cmd << " " << nummoves[losing[i]];
if (flags[losing[i]] & SolverDataFlags::MIRROR_TRANSPOSITION)
cmd << "m";
else if (flags[losing[i]] & SolverDataFlags::TRANSPOSITION)
cmd << "t";
}
}