This repository has been archived by the owner on Mar 22, 2020. It is now read-only.
forked from maxpumperla/deep_learning_and_the_game_of_go
/
play_hxp.py
53 lines (42 loc) · 1.38 KB
/
play_hxp.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
43
44
45
46
47
48
49
50
51
52
53
from dlgo import minimax
from dlgo import hxp
from six.moves import input
def print_board(board):
print(' C1 C2 C3')
for row in (1, 2, 3):
pieces = []
for col in (1, 2, 3):
minion = board.get(hxp.Point(row, col))
pieces.append(minion or ' ')
print('R%d %s' % (row, ' | '.join(pieces)))
print()
def main():
game = hxp.GameState.new_game()
human_player = hxp.Player.x
# bot_player = hxp.Player.o
bot = minimax.MinimaxAgent()
while not game.is_over():
if game.next_player == human_player:
print("===================")
print_board(game.board)
print("Human player's turn")
print("===================")
moves = game.legal_moves()
print('\n'.join('{} {}'.format(idx, m) for idx, m in enumerate(moves)))
human_select = int(input('-- ').strip())
move = moves[human_select]
else:
print("===================")
print_board(game.board)
print("AI player's turn")
print("===================")
move = bot.select_move(game)
game = game.apply_move(move)
print_board(game.board)
winner = game.winner()
if winner is None:
print("It's a draw.")
else:
print('Winner: ' + str(winner))
if __name__ == '__main__':
main()