Skip to content

Commit

Permalink
cleaning: merged gameUtils.py and game.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sirmammingtonham committed Nov 1, 2018
1 parent 4714d56 commit 06e633b
Show file tree
Hide file tree
Showing 6 changed files with 683 additions and 69 deletions.
4 changes: 2 additions & 2 deletions alphabot/Arena.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ def playGame(self, verbose=False):
action = players[curPlayer + 1](current_game)
next_state, curPlayer = self.game.getNextState(curPlayer, (action), current_game)
else:
pi = players[curPlayer+1](self.game.getState(current_game))
pi = players[curPlayer+1](self.game.getState())
pi_reshape = np.reshape(pi, (21, 18))
action = np.where(pi_reshape==np.max(pi_reshape))
next_state, curPlayer = self.game.getNextState(curPlayer, (action[0][0], action[1][0]), current_game)
# if verbose:
# assert(self.display)
# print("Game over: Turn ", str(it), "Result ", str(self.game.getGameEnded(board, 1)))
# self.display(board)
return self.game.getGameEnded(curPlayer, current_game)
return self.game.getGameEnded(current_game)

def playGames(self, num, verbose=False):
"""
Expand Down
4 changes: 2 additions & 2 deletions alphabot/Coach.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ def executeEpisode(self):
pi = self.mcts.getActionProb(state, temp=temp)
pi_reshape = np.reshape(pi, (21, 18))
# sym = self.game.getSymmetries(state, pi)
s = self.game.getState(self.curPlayer)
s = self.game.getState()
trainExamples.append([s, self.curPlayer, pi, None])
# for b,p in sym:
# trainExamples.append([b, self.curPlayer, p, None])
action = np.random.choice(len(pi), p=pi)
a, b = np.unravel_index(np.ravel(action, np.asarray(pi).shape), pi_reshape.shape)
current_game, self.curPlayer = self.game.getNextState(self.curPlayer, (a[0], b[0]))

r = self.game.getGameEnded(self.curPlayer)
r = self.game.getGameEnded()

if r!=0:
return [(x[0],x[2],r*((-1)**(x[1]!=self.curPlayer))) for x in trainExamples]
Expand Down
Loading

0 comments on commit 06e633b

Please sign in to comment.