Skip to content

add chess implementation - #240

Open
yeekit24 wants to merge 5 commits into
suragnair:masterfrom
yeekit24:implement-chess
Open

add chess implementation#240
yeekit24 wants to merge 5 commits into
suragnair:masterfrom
yeekit24:implement-chess

Conversation

@yeekit24

Copy link
Copy Markdown

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

namin commented Apr 18, 2021

Copy link
Copy Markdown

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

Comment thread Arena.py
Comment on lines -93 to +95
if gameResult == -1:
if gameResult == 1:
oneWon += 1
elif gameResult == 1:
elif gameResult == -1:

Copy link
Copy Markdown

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?

Copy link
Copy Markdown

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.

Copy link
Copy Markdown

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
Comment thread Coach.py
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])

Copy link
Copy Markdown

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 thread Arena.py
Comment on lines -93 to +95
if gameResult == -1:
if gameResult == 1:
oneWon += 1
elif gameResult == 1:
elif gameResult == -1:

Copy link
Copy Markdown

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.

Comment thread _chess/pytorch/NNet.py
import sys
sys.path.append('../../')
from utils import *
from pytorch_classification.utils import Bar, AverageMeter

Copy link
Copy Markdown

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.

6 participants