diff options
author | Peter Elliott <pelliott@ualberta.ca> | 2020-08-19 17:53:50 -0600 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-21 12:26:30 +0200 |
commit | fb62eed05889b1fef9373843ac048e4b05056a4b (patch) | |
tree | e4561b4ce2df96967f06632dadf74af9437dc382 /Libraries/LibChess | |
parent | 7331b2b2f6a122722cb876dc54929bbb7dc5fb50 (diff) | |
download | serenity-fb62eed05889b1fef9373843ac048e4b05056a4b.zip |
Chess: Add support for UCI engines
Diffstat (limited to 'Libraries/LibChess')
-rw-r--r-- | Libraries/LibChess/Chess.cpp | 3 | ||||
-rw-r--r-- | Libraries/LibChess/Chess.h | 5 |
2 files changed, 7 insertions, 1 deletions
diff --git a/Libraries/LibChess/Chess.cpp b/Libraries/LibChess/Chess.cpp index 28249c6956..7495acf0fb 100644 --- a/Libraries/LibChess/Chess.cpp +++ b/Libraries/LibChess/Chess.cpp @@ -385,10 +385,13 @@ bool Board::apply_illegal_move(const Move& move, Colour colour) { Board clone = *this; clone.m_previous_states = {}; + clone.m_moves = {}; auto state_count = 0; if (m_previous_states.contains(clone)) state_count = m_previous_states.get(clone).value(); + m_previous_states.set(clone, state_count + 1); + m_moves.append(move); m_turn = opposing_colour(colour); diff --git a/Libraries/LibChess/Chess.h b/Libraries/LibChess/Chess.h index efb43d3315..2e9c078f78 100644 --- a/Libraries/LibChess/Chess.h +++ b/Libraries/LibChess/Chess.h @@ -31,6 +31,7 @@ #include <AK/Optional.h> #include <AK/StringView.h> #include <AK/Traits.h> +#include <AK/Vector.h> namespace Chess { @@ -136,7 +137,8 @@ public: void generate_moves(Callback callback, Colour colour = Colour::None) const; Result game_result() const; - Colour turn() const { return m_turn; }; + Colour turn() const { return m_turn; } + const Vector<Move>& moves() const { return m_moves; } bool operator==(const Board& other) const; @@ -155,6 +157,7 @@ private: bool m_black_can_castle_queenside { true }; HashMap<Board, int> m_previous_states; + Vector<Move> m_moves; friend struct AK::Traits<Board>; }; |