<commit_before>#include "stupid_player.hpp"

#include <ctime>

#include <boost/random/discrete_distribution.hpp>

#include "logger.hpp"
#include "walk_move.hpp"
#include "wall_move.hpp"
#include "exception.hpp"

static boost::log::sources::severity_logger<boost::log::trivial::severity_level> lg;

namespace Quoridor {

StupidPlayer::StupidPlayer(std::shared_ptr<Game> game,
        std::shared_ptr<Pawn> pawn)
    : game_(game), pawn_(pawn), goal_nodes_(), gen_()
{
    lg.add_attribute("Tag", blattrs::constant<std::string>("stupid player"));

    goal_nodes_ = game_->pawn_data(pawn_).goal_nodes;
    gen_.seed(static_cast<unsigned int>(std::time(NULL)));

    BOOST_LOG_DEBUG(lg) << "created new StupidPlayer (" << pawn_->color() << ")";
    for (auto node : goal_nodes_) {
        BOOST_LOG_DEBUG(lg) << "goal node: " << node.row() << ":" << node.col();
    }
}

StupidPlayer::~StupidPlayer()
{
}

IMove *StupidPlayer::get_move()
{
    boost::random::discrete_distribution<> dist{0.6, 0.6};

    if (dist(gen_) == 0) {
        size_t min_path_len = 81;
        std::list<Node> min_path;
        for (auto end_node : goal_nodes_) {
            std::list<Node> path;
            if (game_->get_path(pawn_, end_node, &path)) {
                if (min_path_len > path.size()) {
                    min_path_len = path.size();
                    min_path = path;
                }
            }
        }

        if (min_path.size() == 0) {
            throw Exception("all pathes are blocked");
        }

        auto node_it = min_path.begin();
        Node next_node = *node_it;
        return new WalkMove(next_node);
    }
    else {
        boost::random::discrete_distribution<> dist_2{8, 2};
        boost::random::uniform_int_distribution<> dist_9(0, 8);
        boost::random::discrete_distribution<> dist_8{1, 1, 2, 3, 3, 2, 1, 1};
        Wall::Orientation wall_orient = dist_2(gen_) == 0 ? Wall::kHorizontal : Wall::kVertical;
        return new WallMove(Wall(wall_orient, dist_9(gen_), dist_8(gen_), 2));
    }
}

}  /* namespace Quoridor */
<commit_msg>Use BoardGraph::shortest_path from StupidPlayer<commit_after>#include "stupid_player.hpp"

#include <ctime>

#include <boost/random/discrete_distribution.hpp>

#include "logger.hpp"
#include "walk_move.hpp"
#include "wall_move.hpp"
#include "exception.hpp"

static boost::log::sources::severity_logger<boost::log::trivial::severity_level> lg;

namespace Quoridor {

StupidPlayer::StupidPlayer(std::shared_ptr<Game> game,
        std::shared_ptr<Pawn> pawn)
    : game_(game), pawn_(pawn), goal_nodes_(), gen_()
{
    lg.add_attribute("Tag", blattrs::constant<std::string>("stupid player"));

    goal_nodes_ = game_->pawn_data(pawn_).goal_nodes;
    gen_.seed(static_cast<unsigned int>(std::time(NULL)));

    BOOST_LOG_DEBUG(lg) << "created new StupidPlayer (" << pawn_->color() << ")";
    for (auto node : goal_nodes_) {
        BOOST_LOG_DEBUG(lg) << "goal node: " << node.row() << ":" << node.col();
    }
}

StupidPlayer::~StupidPlayer()
{
}

IMove *StupidPlayer::get_move()
{
    boost::random::discrete_distribution<> dist{0.6, 0.6};

    if (dist(gen_) == 0) {
        size_t path_len = 81;
        std::list<Node> path;
        game_->shortest_path(game_->pawn_data(pawn_).node, goal_nodes_, &path);

        if (path_len == 0) {
            throw Exception("all pathes are blocked");
        }

        auto node_it = path.begin();
        Node next_node = *node_it;
        return new WalkMove(next_node);
    }
    else {
        boost::random::discrete_distribution<> dist_2{8, 2};
        boost::random::uniform_int_distribution<> dist_9(0, 8);
        boost::random::discrete_distribution<> dist_8{1, 1, 2, 3, 3, 2, 1, 1};
        Wall::Orientation wall_orient = dist_2(gen_) == 0 ? Wall::kHorizontal : Wall::kVertical;
        return new WallMove(Wall(wall_orient, dist_9(gen_), dist_8(gen_), 2));
    }
}

}  /* namespace Quoridor */

{'fraction_non_alphanumeric': 0.16161101198062708, 'fraction_numerical': 0.014274789701758857, 'mean_word_length': 3.4239007891770012, 'pattern_counts': {'":': 2, '<': 56, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7459832', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1336, 'n_words': 241}