Skip to content

Commit

Permalink
Use 'collect_all_piece_actions' as a prelude for #34
Browse files Browse the repository at this point in the history
  • Loading branch information
richelbilderbeek committed Aug 25, 2022
1 parent e4a6de5 commit 6badf9e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion control_actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 5 additions & 5 deletions game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ action_history collect_action_history(const game& g)
return collect_action_history(g.get_pieces());
}

std::vector<piece_action> collect_all_actions(const game& g)
std::vector<piece_action> collect_all_piece_actions(const game& g)
{
// 1. Collect all the simple actions,
// such as movement and attacks
std::vector<piece_action> actions;
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),
Expand Down Expand Up @@ -183,7 +183,7 @@ std::vector<piece_action> collect_all_actions(const game& g)
return actions;
}

std::vector<piece_action> collect_all_actions(
std::vector<piece_action> collect_all_piece_actions(
const game& g,
const chess_color player_color)
{
Expand All @@ -192,7 +192,7 @@ std::vector<piece_action> 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),
Expand All @@ -203,7 +203,7 @@ std::vector<piece_action> collect_all_actions(
return actions;
}

std::vector<piece_action> collect_all_actions(
std::vector<piece_action> collect_all_piece_actions(
const game& g,
const piece& p
)
Expand Down
6 changes: 3 additions & 3 deletions game.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<piece_action> collect_all_actions(const game& g);
std::vector<piece_action> 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<piece_action> collect_all_actions(
std::vector<piece_action> 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<piece_action> collect_all_actions(
std::vector<piece_action> collect_all_piece_actions(
const game& g,
const piece& p
);
Expand Down
2 changes: 1 addition & 1 deletion game_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 13 additions & 13 deletions test_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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));

Expand All @@ -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));
}
Expand Down

0 comments on commit 6badf9e

Please sign in to comment.