Skip to content

Commit

Permalink
Add blocked pieces penalty
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcticXWolf committed Feb 27, 2021
1 parent 7eec7f5 commit 09e64ff
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions engines/axwchessbot/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def evaluate(self) -> int:
score = int(self.evaluate_material_score())
score += self.evaluate_pair_bonus()
score += self.evaluate_tempo()
score += self.evaluate_blocked_pieces(chess.WHITE)
score += self.evaluate_blocked_pieces(chess.BLACK)

if self.board.turn:
# evals are from whites perspective, convert to current perspective
Expand Down Expand Up @@ -234,6 +236,33 @@ def evaluate_king_shield(self, color: chess.Color):
return -score
return score

def evaluate_blocked_pieces(self, color: chess.Color):
score = 0

# king blocks rook
side_rank = 0 if color == chess.WHITE else 7
if (
self.board.piece_type_at(chess.square(5, side_rank)) == chess.KING
or self.board.piece_type_at(chess.square(6, side_rank)) == chess.KING
) and (
self.board.piece_type_at(chess.square(6, side_rank)) == chess.ROOK
or self.board.piece_type_at(chess.square(7, side_rank)) == chess.ROOK
):
score -= score_tables.additional_modifiers["king_blocks_rook_penalty"]

if (
self.board.piece_type_at(chess.square(1, side_rank)) == chess.KING
or self.board.piece_type_at(chess.square(2, side_rank)) == chess.KING
) and (
self.board.piece_type_at(chess.square(0, side_rank)) == chess.ROOK
or self.board.piece_type_at(chess.square(1, side_rank)) == chess.ROOK
):
score -= score_tables.additional_modifiers["king_blocks_rook_penalty"]

if color == chess.BLACK:
return -score
return score

def attacked_by_inferior_piece(
self, move: chess.Move, evaluate_to_square: bool
) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion engines/axwchessbot/score_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"tempo": 10,
"king_shield_rank_2": 10,
"king_shield_rank_3": 5,
"king_no_shield_penalty": 10,
"king_blocks_rook_penalty": 24
}

additional_settings = {
Expand Down

0 comments on commit 09e64ff

Please sign in to comment.