Пример #1
0
Файл: util.hpp Проект: koja/t3
template<typename Tbot_impl, typename Tendgame_checker> static void walk_game_tree(
    const player& _test_player,
    std::vector<board> _board_debug_sequence,
    Tendgame_checker _endgame_checker
) {
    std::shared_ptr<move_coordinates_provider_intf> test_bot = std::shared_ptr<move_coordinates_provider_intf>{new Tbot_impl};

    // generate current move and log it to debug sequence
    board board_for_current_move = _board_debug_sequence.back();

    _test_player.make_move(
        board_for_current_move,
        test_bot->get_next_move(
            game{
                {
                    _test_player,
                    player{ other_symbol( _test_player.get_symbol() ) }
                },
                board_for_current_move
            }
        )
    );

    _board_debug_sequence.push_back(board_for_current_move);

    if( is_end_of_game(board_for_current_move, player{ other_symbol( _test_player.get_symbol() ) }) ) {
        _endgame_checker(_board_debug_sequence, _test_player);
        return;
    }

    // generating all possible opponent moves and log those

    for( const col c : get_ordered_col_values() ) {
        for( const row r : get_ordered_row_values() ) {
            if( !_board_debug_sequence.back().get_symbol(c, r) ) {

                board board_for_opponent_move = _board_debug_sequence.back();
                board_for_opponent_move.add_symbol(c, r, other_symbol( _test_player.get_symbol() ));

                std::vector<board> sequence_including_opponent_move{_board_debug_sequence};
                sequence_including_opponent_move.push_back(board_for_opponent_move);

                if( is_end_of_game(board_for_opponent_move, _test_player) ) {
                    _endgame_checker(
                        sequence_including_opponent_move,
                        player{
                            other_symbol( _test_player.get_symbol() )
                        }
                    );
                    continue;
                }

                walk_game_tree<Tbot_impl>(_test_player, sequence_including_opponent_move, _endgame_checker);
            }
        }
    }
}
Пример #2
0
Файл: util.hpp Проект: koja/t3
inline bool is_end_of_game(const board& _board, const player& _current_player) {
    game check_game{
        { _current_player, player{other_symbol(_current_player.get_symbol())} },
        _board
    };

    if( check_game.get_winner() ) {
        return true;
    }

    if( check_game.is_tie() ){
        return true;
    }

    return false;
}