本文整理汇总了C++中Chromosome::set_game_duration方法的典型用法代码示例。如果您正苦于以下问题:C++ Chromosome::set_game_duration方法的具体用法?C++ Chromosome::set_game_duration怎么用?C++ Chromosome::set_game_duration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chromosome
的用法示例。
在下文中一共展示了Chromosome::set_game_duration方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
//.........这里部分代码省略.........
Set up a game between the two and see who wins and by how much...
Use a single engine, just load and unload the factor weights after
every move...
-------------------------------------------------------------------------*/
auto timer = new diagnostics::Timer ();
timer->start ();
this->board->reset ();
// Chromosome A plays white
IEngine::GameResult result;
uint turn = 0;
do
{
this->chess_engine->load_factor_weights (features[turn]);
// TODO: enable again once we implement the assertion below
// bitboard key = this->board->get_hash_key ();
// bitboard lock = this->board->get_hash_lock ();
game_rules::Move move;
result = this->chess_engine->get_best_move (3, this->board, move);
if (result == IEngine::WHITE_MATES ||
result == IEngine::BLACK_MATES ||
result == IEngine::STALEMATE) break;
// TODO: turn into an assertion
// if (key == this->board->get_hash_key () || lock != this->board->get_hash_lock ())
// {
// }
IBoard::Error error = this->board->make_move (move, true);
if (error != IBoard::NO_ERROR && error != IBoard::DRAW_BY_REPETITION)
{
abort ();
}
else if (error == IBoard::DRAW_BY_REPETITION)
{
this->board->undo_move ();
result = IEngine::DRAW_BY_REPETITION;
break;
}
turn = (turn + 1) % 2;
if (this->board->get_move_number() >= MAX_ALLOWED_MOVEMENTS)
{
int r = this->evaluator->evaluate_material(board);
if (r == 0) {
result = IEngine::STALEMATE;
}
else if (board->get_player_in_turn() == Piece::WHITE)
{
if (r > 0)
result = IEngine::WHITE_MATES;
else
result = IEngine::BLACK_MATES;
}
else
{
if (r > 0)
result = IEngine::BLACK_MATES;
else
result = IEngine::WHITE_MATES;
}
break;
}
} while (true);
timer->stop ();
if (result == IEngine::STALEMATE || result == IEngine::DRAW_BY_REPETITION)
{
evaluation = 1.0 / 2.0;
b.set_result (Chromosome::DRAW);
}
else
{
evaluation = 6.0 / 9.0;
if (result == IEngine::WHITE_MATES)
{
evaluation = 1 - evaluation;
b.set_result (Chromosome::LOSS);
}
else
{
b.set_result (Chromosome::WIN);
}
b.set_game_duration (board->get_move_number ());
}
b.set_material_balance (this->evaluator->evaluate_material(board));
b.set_fitness (evaluation);
delete timer;
return evaluation;
}