Skip to content
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

add chess implementation #240

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

yeekit24
Copy link

Resurrect PR Chess prototype #147 by @namin

  • now it did not stop at self.play stage, as i re-implement the function getGameEnded
def getGameEnded(self, board, player):
        # return 0 if not ended, 1 if player 1 won, -1 if player 1 lost
        outcome = board.outcome()
        if outcome is not None:
            if outcome.winner is None:
                # draw return very little value
                return 1e-4
            else:
                return who(outcome.winner)
        return 0
  • fixed a bug in Arena.py where it showed some weird behaviour.
  • added stockfish player.

Once again, thanks @namin for the code implementation.

@namin
Copy link

namin commented Apr 18, 2021

Glad you're doing this! Have you managed to train a decent chess bot with this?

Comment on lines -93 to +95
if gameResult == -1:
if gameResult == 1:
oneWon += 1
elif gameResult == 1:
elif gameResult == -1:
Copy link

Choose a reason for hiding this comment

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

This seems to precisely invert the logic of which party won; was this done to fix a bug?

Choose a reason for hiding this comment

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

I think the original code is correct, this was not a bug.

Note a few lines up the order of the players was inverted, and also in Arena.py it normalizes for player ID via curPlayer * self.game.getGameEnded(board, curPlayer) here.

Choose a reason for hiding this comment

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

This may be because the getGameEnded(self, board, player) method of ChessGame returns 1 if player 1 won instead of the given player won. Suggest multiplying the return value in ChessGame.getGameEnded by the function parameter player, instead of modifying the code here.

@jamesbraza jamesbraza mentioned this pull request Mar 11, 2023
@@ -58,7 +58,7 @@ 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])
trainExamples.append([self.game.toArray(b), self.curPlayer, p, None])

Choose a reason for hiding this comment

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

I think this would break Coach.py for all other games

Note the same comment holds for the change in MCTS.py

Comment on lines -93 to +95
if gameResult == -1:
if gameResult == 1:
oneWon += 1
elif gameResult == 1:
elif gameResult == -1:

Choose a reason for hiding this comment

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

I think the original code is correct, this was not a bug.

Note a few lines up the order of the players was inverted, and also in Arena.py it normalizes for player ID via curPlayer * self.game.getGameEnded(board, curPlayer) here.

import sys
sys.path.append('../../')
from utils import *
from pytorch_classification.utils import Bar, AverageMeter

Choose a reason for hiding this comment

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

I think we can from utils import AverageMeter, where is pytorch_classification.utils.Bar though?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants