-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhuman_v_bot.py
More file actions
27 lines (23 loc) · 806 Bytes
/
human_v_bot.py
File metadata and controls
27 lines (23 loc) · 806 Bytes
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
from __future__ import print_function
# tag::play_against_your_bot[]
from dlgo.agent.naive import RandomBot
from dlgo import goboard_slow as goboard
from dlgo import gotypes
from dlgo.utils import print_board, print_move, point_from_coords
def main():
board_size = 9
game = goboard.GameState.new_game(board_size)
bot = RandomBot()
while not game.is_over():
print(chr(27) + "[2J")
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()