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

How do I switch turns for each move? #32

Closed
kanitabe opened this issue Oct 14, 2022 · 2 comments
Closed

How do I switch turns for each move? #32

kanitabe opened this issue Oct 14, 2022 · 2 comments

Comments

@kanitabe
Copy link

How do I switch turns for each move?
I have written the following code.

GameInfo gi = new GameInfo() { Handicap = 0, StartingPlayer = Content.Black, Komi = 6.5 };
Game game = new Game(gi);

bool legal;
game.MakeMove(3, 3, out legal);
game.MakeMove(16, 16, out legal);

Debug.Log(game.SerializeToSGF(null));

What I get is this kind of SGF. It is a variation move of Black's first move and does not advance the number of moves.

(;SZ[19](;B[dd])(;B[qq]))

What I want is an SGF like this one.

(;SZ[19](;B[dd];W[qq]))
@paviad
Copy link
Owner

paviad commented Oct 14, 2022

Hello, every MakeMove returns a new Game which represents the state after the move, so you need to do this:

GameInfo gi = new GameInfo() { Handicap = 0, StartingPlayer = Content.Black, Komi = 6.5 };
Game gameInitial = new Game(gi);
Game game = gameInitial;

bool legal;
game = game.MakeMove(3, 3, out legal);
game = game.MakeMove(16, 16, out legal);

Debug.Log(game.SerializeToSGF(null));

@paviad paviad closed this as completed Oct 14, 2022
@kanitabe
Copy link
Author

Thank you for reply!
However, no text was output.
It seemed to be caused by GameInfo being null.
So I fixed it as follows.

protected Game(Game fromGame) {
            Board = new Board(fromGame.Board);
            Turn = fromGame.Turn.Opposite();
            GameInfo = fromGame.GameInfo; // I added this line
            _captures[Content.White] = fromGame._captures[Content.White];
            _captures[Content.Black] = fromGame._captures[Content.Black];
            foreach (var p in fromGame._superKoSet) _superKoSet.Add(p);
            Root = fromGame.Root;
        }

With this fix, game properties such as Komi and size are now output, but Moves is stille not.
It seems that Game's _moves is empty when outputting, but I couldn't figure out how to fix it.

        private void SerializeToSGFInternal(TextWriter s) {
            if (_moves.Count == 1) { // I set a breakpoint here, but the Count was 0.
                var pnt = _moves.First().Move;
                SerializeMove(s, pnt);
                _moves.First().Game.SerializeToSGF(s);
            }
}

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

No branches or pull requests

2 participants