Fix Python3 compatibility in Go env (#64)

Under Python3, user inputs are in string format and needs be
converted
into bytes before passing to pachi-py. The returned __repr__ from
pachi-py for the boards are bytes and needs be converted into string
for
line breaks to work.

Also fixed raw_input and print functions in play_go under
examples/scripts with six package.
This commit is contained in:
Shu Shen
2016-05-09 19:18:55 -07:00
committed by Greg Brockman
parent a20719c8e3
commit 168f25b976
2 changed files with 5 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
from six.moves import input as raw_input
import argparse import argparse
import pachi_py import pachi_py
import gym import gym
@@ -28,8 +29,8 @@ def main():
break break
print print
print 'You win!' if r > 0 else 'Opponent wins!' print('You win!' if r > 0 else 'Opponent wins!')
print 'Final score:', env._state.board.official_score print('Final score:', env._state.board.official_score)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@@ -38,7 +38,7 @@ def _action_to_coord(board, a):
return board.ij_to_coord(a // board.size, a % board.size) return board.ij_to_coord(a // board.size, a % board.size)
def str_to_action(board, s): def str_to_action(board, s):
return _coord_to_action(board, board.str_to_coord(s)) return _coord_to_action(board, board.str_to_coord(s.encode()))
class GoState(object): class GoState(object):
''' '''
@@ -67,7 +67,7 @@ class GoState(object):
pachi_py.stone_other(self.color)) pachi_py.stone_other(self.color))
def __repr__(self): def __repr__(self):
return 'To play: {}\n{}'.format(six.u(pachi_py.color_to_str(self.color)), six.u(self.board.__repr__())) return 'To play: {}\n{}'.format(six.u(pachi_py.color_to_str(self.color)), self.board.__repr__().decode())
### Adversary policies ### ### Adversary policies ###