Skip to content

Network not punished for illegal moves #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Arena.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def playGame(self, verbose=False):
assert(self.display)
print("Game over: Turn ", str(it), "Result ", str(self.game.getGameEnded(board, 1)))
self.display(board)
return self.game.getGameEnded(board, 1)
return curPlayer*self.game.getGameEnded(board, curPlayer)

def playGames(self, num, verbose=False):
"""
Expand Down
13 changes: 10 additions & 3 deletions Coach.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,23 @@ def executeEpisode(self):

pi = self.mcts.getActionProb(canonicalBoard, temp=temp)
sym = self.game.getSymmetries(canonicalBoard, pi)
for b,p in sym:
trainExamples.append([b, self.curPlayer, p, None])

# ideally these should be combined so that getSymmetries takes valids as well

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the problem of also returning the valids in the "getSymmetry" function?

bs, ps = zip(*self.game.getSymmetries(canonicalBoard, pi))
_, valids_sym = zip(*self.game.getSymmetries(canonicalBoard, valids))
sym = zip(bs,ps,valids_sym)

for b,p,valid in sym:
# previous was: [b, self.curPlayer, p, None], but only 3 values were returned
trainExamples.append([b, self.curPlayer, p, valid])

action = np.random.choice(len(pi), p=pi)
board, self.curPlayer = self.game.getNextState(board, self.curPlayer, action)

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

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

def learn(self):
"""
Expand Down