forked from pmuens/alphago
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpruned_go.py
42 lines (36 loc) · 1.28 KB
/
pruned_go.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from six.moves import input
from dlgo import goboard_fast as goboard
from dlgo import gotypes
from dlgo import minimax
from dlgo.utils import print_board, print_move, point_from_coords
BOARD_SIZE = 5
def capture_diff(game_state):
black_stones = 0
white_stones = 0
for r in range(1, game_state.board.num_rows + 1):
for c in range(1, game_state.board.num_cols + 1):
p = gotypes.Point(r, c)
color = game_state.board.get(p)
if color == gotypes.Player.black:
black_stones += 1
elif color == gotypes.Player.white:
white_stones += 1
diff = black_stones - white_stones
if game_state.next_player == gotypes.Player.black:
return diff
return -1 * diff
def main():
game = goboard.GameState.new_game(BOARD_SIZE)
bot = minimax.DepthPrunedAgent(3, capture_diff)
while not game.is_over():
print_board(game.board)
if game.next_player == gotypes.Player.black:
human_move = input('-- ')
point = point_from_coords(human_move.strip())
move = goboard.Move.play(point)
else:
move = bot.select_move(game)
print_move(game.next_player, move)
game = game.apply_move(move)
if __name__ == '__main__':
main()