-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgreedy_heuristic.py
26 lines (23 loc) · 952 Bytes
/
greedy_heuristic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import chess
from golf import GolfState, get_neighbour_types
from heuristic import Heuristic
class GreedyHeuristic(Heuristic):
def analyse(self,
state: GolfState,
move_text: str | None,
depth: int) -> float:
captured_count = state.taken.total()
value = captured_count * 100 - depth
if move_text is not None:
move = chess.Move.from_uci(move_text)
moved_piece = state.board.piece_at(move.to_square)
if moved_piece in state.chosen:
value += 20
else:
for neighbour_type in get_neighbour_types(state.board,
move.to_square):
neighbour = chess.Piece(neighbour_type, moved_piece.color)
if neighbour in state.chosen:
value += 10
break
return value