added the opponenent pawn attack map move better ordering

This commit is contained in:
Karma Riuk 2025-02-16 09:28:55 +01:00
parent adf21ee021
commit 959ecdeb7d
5 changed files with 44 additions and 0 deletions

View File

@ -421,3 +421,17 @@ std::vector<Move> Board::all_capturing_moves() const {
return ret;
}
std::vector<int8_t> Board::opponent_pawn_attack_map() const {
std::vector<int8_t> ret;
for (int i = 0; i < 64; i++) {
if (piece_at(i) == Piece::Pawn
&& ((colour_at(i) == White && !white_to_play)
|| (colour_at(i) == Black && white_to_play))) {
std::vector<int8_t> attack_map =
pawn_attack_map(*this, Coords::from_index(i));
ret.insert(ret.end(), attack_map.begin(), attack_map.end());
}
}
return ret;
}

View File

@ -39,6 +39,7 @@ struct Board {
std::vector<Move> all_legal_moves() const;
std::vector<Move> all_capturing_moves() const;
std::vector<int8_t> opponent_pawn_attack_map() const;
bool is_checkmate() const;

View File

@ -79,3 +79,24 @@ std::vector<Move> pawn_moves(const Board& b, const Coords xy) {
return ret;
}
std::vector<int8_t> pawn_attack_map(const Board& b, Coords xy) {
std::vector<int8_t> ret{};
Colour my_colour = b.colour_at(xy);
// -- Capture to the left
if (xy.x > 0) {
int dy = my_colour == Colour::White ? 1 : -1;
Coords left{xy.x - 1, xy.y + dy};
ret.push_back(left.to_index());
}
// -- Capture to the right
if (xy.x < 7) {
int dy = my_colour == Colour::White ? 1 : -1;
Coords right{xy.x + 1, xy.y + dy};
ret.push_back(right.to_index());
}
return ret;
}

View File

@ -69,6 +69,7 @@ std::vector<Move> keep_only_blocking(const std::vector<Move>, const Board&);
std::optional<Move> move_for_position(const Board&, const Coords, const Coords);
std::vector<Move> look_direction(const Board&, const Coords, int, int);
std::vector<int8_t> pawn_attack_map(const Board&, const Coords);
std::vector<Move> pawn_moves(const Board&, const Coords);
std::vector<Move> rook_moves(const Board&, const Coords);
std::vector<Move> knight_moves(const Board&, const Coords);

View File

@ -3,6 +3,8 @@
#include "../board/board.hpp"
#include "utils.hpp"
#include <algorithm>
int Move::score_guess(const Board& b) const {
int ret = 0;
@ -15,5 +17,10 @@ int Move::score_guess(const Board& b) const {
if (promoting_to != Piece::None)
ret += piece_value(promoting_to);
std::vector<int8_t> pawn_attack_map = b.opponent_pawn_attack_map();
if (std::find(pawn_attack_map.begin(), pawn_attack_map.end(), target_square)
!= pawn_attack_map.end())
ret -= me_piece;
return ret;
}