2016-04-27 08:00:58 -07:00
|
|
|
#!/usr/bin/env python
|
2016-05-09 19:18:55 -07:00
|
|
|
from six.moves import input as raw_input
|
2016-04-27 08:00:58 -07:00
|
|
|
import argparse
|
|
|
|
import pachi_py
|
|
|
|
import gym
|
|
|
|
from gym import spaces, envs
|
|
|
|
from gym.envs.board_game import go
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('--raw_actions', action='store_true')
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
env = envs.make('Go9x9-v0')
|
|
|
|
env.reset()
|
|
|
|
while True:
|
|
|
|
s = env._state
|
|
|
|
env._render()
|
|
|
|
|
|
|
|
colorstr = pachi_py.color_to_str(s.color)
|
|
|
|
if args.raw_actions:
|
|
|
|
a = int(raw_input('{} (raw)> '.format(colorstr)))
|
|
|
|
else:
|
|
|
|
coordstr = raw_input('{}> '.format(colorstr))
|
|
|
|
a = go.str_to_action(s.board, coordstr)
|
|
|
|
|
|
|
|
_, r, done, _ = env.step(a)
|
|
|
|
if done:
|
|
|
|
break
|
|
|
|
|
|
|
|
print
|
2016-05-09 19:18:55 -07:00
|
|
|
print('You win!' if r > 0 else 'Opponent wins!')
|
|
|
|
print('Final score:', env._state.board.official_score)
|
2016-04-27 08:00:58 -07:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|