-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrochesterWrappers.py
executable file
·63 lines (54 loc) · 2.16 KB
/
rochesterWrappers.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import Rocgo
import numpy as np
from constants import *
from Rocpreprocessing import Preprocess
def initRocBoard():
# initialize the board state
gs = Rocgo.GameState(BOARD_SZ)
gs.current_player = Rocgo.BLACK
gs.komi = KOMI
return gs
def rocBoard2State(rocEnv):
"""
Returns the state information
@rtype : numpy matrix
@rparam : 48x9x9 state info
"""
nn_input = Preprocess(FEATURE_LIST).state_to_tensor(rocEnv)[0,:,:,:]
return nn_input
def printRocBoard(rocEnv):
one = np.transpose(Preprocess(FEATURE_LIST).state_to_tensor(rocEnv)[0,0,:,:])
two = np.transpose(Preprocess(FEATURE_LIST).state_to_tensor(rocEnv)[0,1,:,:])
print "Rochester Board"
print "0=empty, 1=black, 2=white"
oneModifier = 1 if rocEnv.current_player==Rocgo.BLACK else 2
twoModifier = 2 if rocEnv.current_player==Rocgo.BLACK else 1
print str(one*oneModifier + two*twoModifier).replace('0',' ').replace('.','')
def printNPYstate(state):
one = np.transpose(state[0,:,:])
two = np.transpose(state[1,:,:])
print "Numpy Board"
print "0=empty, 1=you, 2=opponent"
print str(one + 2*two).replace('0',' ').replace('.','')
def returnRocBoard(rocEnv):
one = np.transpose(Preprocess(FEATURE_LIST).state_to_tensor(rocEnv)[0,0,:,:])
two = np.transpose(Preprocess(FEATURE_LIST).state_to_tensor(rocEnv)[0,1,:,:])
oneModifier = 1 if rocEnv.current_player==Rocgo.BLACK else 2
twoModifier = 2 if rocEnv.current_player==Rocgo.BLACK else 1
return one*oneModifier + two*twoModifier
def get_legal_coords(rocEnv):
"""
Returns legal moves
@rtype : int array
@rparam : Zero-indexed, row major coordinates of legal moves
"""
coords = sorted([x+y*BOARD_SZ for (x,y) in rocEnv.get_legal_moves(include_eyes = False)])
coords.append(PASS_ACTION)
coords.append(RESIGN_ACTION)
return coords
def intMove2rocMove(move):
# converts integer move (0-82) to move coordinates used in Rochester board.
if move==PASS_ACTION:
return None
else:
return (move%BOARD_SZ,int(move/BOARD_SZ))