-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
33 lines (27 loc) · 872 Bytes
/
main.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
from nard_backgammon import (
Nard,
NardState,
Player,
get_random_move,
board_to_str)
# If the first_player is None, then the starting
# player is found on the first roll `first_roll()`
game = Nard.new(first_roll_player=Player.WHITE)
while True:
match game.state:
# If first_roll_player is None then
# NardState is will be FIRST_ROLL at the init
case NardState.FIRST_ROLL:
game.first_roll()
case NardState.PLAYING:
# get valid moves for active player
moves = game.get_valid_moves()
if not moves:
game.skip()
continue
move = get_random_move(moves)
game.play_move(move)
print(board_to_str(game))
case NardState.ENDED:
print(f'Winner: {game.outcome.winner}')
break