From 6badf9ee039541fd62b26465b18d672ac6d49968 Mon Sep 17 00:00:00 2001 From: richelbilderbeek Date: Thu, 25 Aug 2022 18:23:33 +0200 Subject: [PATCH] Use 'collect_all_piece_actions' as a prelude for #34 --- control_actions.cpp | 2 +- game.cpp | 10 +++++----- game.h | 6 +++--- game_view.cpp | 2 +- test_game.cpp | 26 +++++++++++++------------- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/control_actions.cpp b/control_actions.cpp index 44d7452..f9ee65f 100644 --- a/control_actions.cpp +++ b/control_actions.cpp @@ -414,7 +414,7 @@ void start_attack( const chess_color player_color ) { - const auto actions{collect_all_actions(g)}; + const auto actions{collect_all_piece_actions(g)}; if (count_selected_units(g, player_color) == 0) return; diff --git a/game.cpp b/game.cpp index 45d8578..85936cc 100644 --- a/game.cpp +++ b/game.cpp @@ -111,7 +111,7 @@ action_history collect_action_history(const game& g) return collect_action_history(g.get_pieces()); } -std::vector collect_all_actions(const game& g) +std::vector collect_all_piece_actions(const game& g) { // 1. Collect all the simple actions, // such as movement and attacks @@ -119,7 +119,7 @@ std::vector collect_all_actions(const game& g) for (const auto& p: g.get_pieces()) { const auto piece_actions{ - collect_all_actions(g, p) + collect_all_piece_actions(g, p) }; std::copy( std::begin(piece_actions), @@ -183,7 +183,7 @@ std::vector collect_all_actions(const game& g) return actions; } -std::vector collect_all_actions( +std::vector collect_all_piece_actions( const game& g, const chess_color player_color) { @@ -192,7 +192,7 @@ std::vector collect_all_actions( { if (p.get_color() != player_color) continue; const auto piece_actions{ - collect_all_actions(g, p) + collect_all_piece_actions(g, p) }; std::copy( std::begin(piece_actions), @@ -203,7 +203,7 @@ std::vector collect_all_actions( return actions; } -std::vector collect_all_actions( +std::vector collect_all_piece_actions( const game& g, const piece& p ) diff --git a/game.h b/game.h index 6e14431..a9877b5 100644 --- a/game.h +++ b/game.h @@ -114,18 +114,18 @@ action_history collect_action_history(const game& g); /// Collect all valid moves and attackes at a board /// for all pieces -std::vector collect_all_actions(const game& g); +std::vector collect_all_piece_actions(const game& g); /// Collect all valid moves and attackes at a board /// for all pieces of a certain color -std::vector collect_all_actions( +std::vector collect_all_piece_actions( const game& g, const chess_color player_color ); /// Collect all valid moves and attackes at a board /// for a focal piece -std::vector collect_all_actions( +std::vector collect_all_piece_actions( const game& g, const piece& p ); diff --git a/game_view.cpp b/game_view.cpp index d5080d3..255cc1f 100644 --- a/game_view.cpp +++ b/game_view.cpp @@ -601,7 +601,7 @@ void show_possible_moves(game_view& view) { const auto& g{view.get_game()}; const auto& layout{g.get_layout()}; - const auto actions{collect_all_actions(g)}; + const auto actions{collect_all_piece_actions(g)}; for (const auto& action: actions) { if (!get_piece_at(g, action.get_from()).is_selected()) continue; diff --git a/test_game.cpp b/test_game.cpp index aff3e09..c50fb94 100644 --- a/test_game.cpp +++ b/test_game.cpp @@ -189,7 +189,7 @@ void test_game_functions() // default start { const game g; - const auto actions{collect_all_actions(g)}; + const auto actions{collect_all_piece_actions(g)}; assert(!actions.empty()); const piece_action e2e3( chess_color::white, @@ -237,7 +237,7 @@ void test_game_functions() const game g{ get_game_with_starting_position(starting_position_type::pawn_all_out_assault) }; - const auto actions{collect_all_actions(g)}; + const auto actions{collect_all_piece_actions(g)}; assert(!actions.empty()); const piece_action e4xf5( chess_color::white, @@ -261,7 +261,7 @@ void test_game_functions() const game g{ get_game_with_starting_position(starting_position_type::kings_only) }; - const auto actions{collect_all_actions(g)}; + const auto actions{collect_all_piece_actions(g)}; assert(!actions.empty()); const piece_action ke1e2( chess_color::white, @@ -285,7 +285,7 @@ void test_game_functions() const game g{ get_game_with_starting_position(starting_position_type::queen_end_game) }; - const auto actions{collect_all_actions(g)}; + const auto actions{collect_all_piece_actions(g)}; assert(!actions.empty()); const piece_action qd1d5( chess_color::white, @@ -309,7 +309,7 @@ void test_game_functions() const game g{ get_game_with_starting_position(starting_position_type::kasparov_vs_topalov) }; - const auto actions{collect_all_actions(g)}; + const auto actions{collect_all_piece_actions(g)}; assert(!actions.empty()); const piece_action ka4xa3( chess_color::black, @@ -325,7 +325,7 @@ void test_game_functions() const game g{ get_game_with_starting_position(starting_position_type::pawn_all_out_assault) }; - const auto actions{collect_all_actions(g)}; + const auto actions{collect_all_piece_actions(g)}; assert(!actions.empty()); const piece_action ra1a3( chess_color::white, @@ -349,7 +349,7 @@ void test_game_functions() const game g{ get_game_with_starting_position(starting_position_type::pawns_nearly_near_promotion) }; - const auto actions{collect_all_actions(g)}; + const auto actions{collect_all_piece_actions(g)}; assert(!actions.empty()); const piece_action a6a7( chess_color::white, @@ -373,7 +373,7 @@ void test_game_functions() const game g{ get_game_with_starting_position(starting_position_type::pawns_at_promotion) }; - const auto actions{collect_all_actions(g)}; + const auto actions{collect_all_piece_actions(g)}; assert(!actions.empty()); const piece_action a8isq( chess_color::white, @@ -397,7 +397,7 @@ void test_game_functions() const game g{ get_game_with_starting_position(starting_position_type::ready_to_castle) }; - const auto actions{collect_all_actions(g)}; + const auto actions{collect_all_piece_actions(g)}; assert(!actions.empty()); const piece_action wcks( chess_color::white, @@ -437,7 +437,7 @@ void test_game_functions() const game g{ get_game_with_starting_position(starting_position_type::ready_to_not_castle) }; - const auto actions{collect_all_actions(g)}; + const auto actions{collect_all_piece_actions(g)}; assert(!actions.empty()); const piece_action wcks( chess_color::white, @@ -477,7 +477,7 @@ void test_game_functions() const game g{ get_game_with_starting_position(starting_position_type::ready_to_not_castle) }; - const auto actions{collect_all_actions(g)}; + const auto actions{collect_all_piece_actions(g)}; assert(!actions.empty()); const piece_action ke1d1( chess_color::white, @@ -505,7 +505,7 @@ void test_game_functions() // It takes 1 time unit to move, // aim at halfway to window of opportunity for en-passant for (int i{0}; i!=6; ++i) g.tick(delta_t(0.25)); - const auto actions{collect_all_actions(g)}; + const auto actions{collect_all_piece_actions(g)}; assert(!actions.empty()); assert(has_action_of_type(actions, piece_action_type::en_passant)); @@ -529,7 +529,7 @@ void test_game_functions() // After 1 move disappears g.tick(delta_t(1.0)); - const auto actions_again{collect_all_actions(g)}; + const auto actions_again{collect_all_piece_actions(g)}; assert(!is_in(h4xg3ep, actions_again)); assert(!is_in(f4xg3ep, actions_again)); }