forked from reidlindsay/gostop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgostop.py
41 lines (29 loc) · 1.25 KB
/
gostop.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
import sys
import random
import argparse
from gostop import GameState, HumanAgent, RandomAgent
def main(argv):
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-f', '--fixed-random-seed', dest='fixed_random_seed',
help='Use a fixed random seed to play a predictable game')
args = parser.parse_args()
if args.fixed_random_seed:
random.seed(args.fixed_random_seed)
players = [HumanAgent('Human'), RandomAgent('Deep Pink')]
state = GameState.new_game()
while True:
current_player = players[state.current_player]
print('*** {0}'.format(current_player))
print(state)
possible_actions = state.get_possible_actions()
if len(possible_actions) == 0:
raise Exception('No more actions')
action = current_player.get_action(state, possible_actions)
print('*** {0} takes action {1}'.format(current_player, str(action)))
last_player = state.current_player
state = state.generate_successor(action)
if (state.get_result(last_player) == 1):
print('*** {0} wins!'.format(players[last_player]))
break
if __name__ == '__main__':
main(sys.argv[1:])