Beispiel #1
0
        public void Allow_BreathPreventsSuicide()
        {
            const short n = 3;
            GoGame game = new GoGame { BoardSize = n };

            game.ProposedPlay(new Loc(0, 0)); // X
            game.ProposedPlay(new Loc(0, 1)); // O
            game.ProposedPlay(new Loc(2, 0)); // X
            game.ProposedPlay(new Loc(2, 1)); // O
            game.ProposedPlay(new Loc(1, 0)); // 1

            Assert.True(game.blackChains.Count == 1);
            Assert.True(game.blackChains.First().Liberties.Count == 1);
            Assert.True(game.blackChains.First().Liberties.First().Equals(new Loc(1, 1)));
        }
Beispiel #2
0
        public void Allow_MergeMakesBreath()
        {
            const short n = 4;
            GoGame game = new GoGame { BoardSize = n };

            game.ProposedPlay(new Loc(0, 0)); // X
            game.ProposedPlay(new Loc(1, 1)); // O
            game.ProposedPlay(new Loc(2, 0)); // X
            game.ProposedPlay(new Loc(2, 1)); // O
            game.ProposedPlay(new Loc(n, n)); // X: PASS
            game.ProposedPlay(new Loc(0, 1)); // O
            game.ProposedPlay(new Loc(1, 0)); // 1

            Assert.True(game.blackChains.Count == 1);
            Assert.True(game.whiteChains.Count == 1);
            Assert.True(game.blackChains.First().Liberties.Count == 1);
            Assert.True(game.blackChains.First().Liberties[0].Equals(new Loc(3, 0)));
        }
Beispiel #3
0
        public void Allow_Kill()
        {
            const short n = 4;
            GoGame game = new GoGame { BoardSize = n };

            game.ProposedPlay(new Loc(1, 0)); // X
            game.ProposedPlay(new Loc(0, 2)); // O
            game.ProposedPlay(new Loc(1, 1)); // X
            game.ProposedPlay(new Loc(1, 2)); // O
            game.ProposedPlay(new Loc(n, n)); // X: PASS
            game.ProposedPlay(new Loc(2, 1)); // O
            game.ProposedPlay(new Loc(n, n)); // X: PASS
            game.ProposedPlay(new Loc(2, 0)); // O
            game.ProposedPlay(new Loc(n, n)); // X: PASS
            game.ProposedPlay(new Loc(0, 0)); // O
            game.ProposedPlay(new Loc(0, 1)); // 1

            Assert.True(game.blackChains.Count == 1);
            Assert.True(game.whiteChains.Count == 2);
            Assert.True(game.PrisonersTakenByBlack == 1);
            Assert.True(game.blackChains.First().Liberties.Count == 1);
            Assert.True(game.blackChains.First().Liberties[0].Equals(new Loc(0, 0)));
        }
Beispiel #4
0
        public void PassPlayPass_SameColor()
        {
            const short n = 3;
            GoGame game = new GoGame { BoardSize = n };

            game.ProposedPlay(new Loc(0, 0)); // 1
            game.ProposedPlay(new Loc(n, n)); // 2: PASS
            RequestResponse response = game.ProposedPlay(new Loc(1, 0)); // 3

            Assert.True(!response.Move.StonePlaced.IsWhite);
        }
Beispiel #5
0
        public void PassPass_EndGame()
        {
            const short n = 2;
            GoGame game = new GoGame { BoardSize = n };

            game.ProposedPlay(new Loc(n, n));
            game.ProposedPlay(new Loc(n, n));

            Assert.True(game.IsOver);
        }
Beispiel #6
0
        public void MakesGroups()
        {
            const short n = 4;
            GoGame game = new GoGame { BoardSize = n };

            game.ProposedPlay(new Loc(0, 0)); // X
            game.ProposedPlay(new Loc(1, 0)); // O
            game.ProposedPlay(new Loc(0, 1)); // X
            game.ProposedPlay(new Loc(1, 1)); // O
            game.ProposedPlay(new Loc(1, 2)); // X
            game.ProposedPlay(new Loc(2, 2)); // O

            // TEST: explicitly check number of groups and each groups stones and breaths.
            Assert.True(game.blackChains.Count == 2);
            Assert.True(game.blackChains.Where(chain => chain.Stones.Count == 1).First().Liberties.Count == 2); // the one with 1 stone has 2 libs
            Assert.True(game.blackChains.Where(chain => chain.Stones.Count == 2).First().Liberties.Count == 1); // the one with 2 stones has 1 lib
            Assert.True(game.whiteChains.Count == 2);
            Assert.True(game.whiteChains.Where(chain => chain.Stones.Count == 1).First().Liberties.Count == 3); // the one with 1 stone has 3 libs
            Assert.True(game.whiteChains.Where(chain => chain.Stones.Count == 2).First().Liberties.Count == 2); // the one with 2 stones has 2 libs
        }
Beispiel #7
0
        public void LiveOtherCorner()
        {
            const short n = 2;
            GoGame game = new GoGame { BoardSize = n };

            game.ProposedPlay(new Loc(1, 1));

            Assert.True(game.blackChains.Count == 1);
            Assert.True(game.blackChains[0].Stones.Count == 1);
            Assert.True(game.blackChains[0].Liberties.Count == 2);
            Assert.True(game.blackChains[0].Liberties.Contains(new Loc(1, 0)));
            Assert.True(game.blackChains[0].Liberties.Contains(new Loc(0, 1)));
        }
Beispiel #8
0
        public void LiveEdge()
        {
            short n = 3;
            GoGame game = new GoGame { BoardSize = n };

            game.ProposedPlay(new Loc(0, 1));

            Assert.True(game.blackChains.Count == 1);
            Assert.True(game.blackChains[0].Stones.Count == 1);
            Assert.True(game.blackChains[0].Liberties.Count == 3);
            Assert.True(game.blackChains[0].Liberties.Contains(new Loc(0, 0)));
            Assert.True(game.blackChains[0].Liberties.Contains(new Loc(1, 1)));
            Assert.True(game.blackChains[0].Liberties.Contains(new Loc(0, 2)));
        }
Beispiel #9
0
        public void LibertyCount()
        {
            const short n = 3;
            GoGame game = new GoGame { BoardSize = n };

            game.ProposedPlay(new Loc(0, 0)); // X
            game.ProposedPlay(new Loc(n, n)); // O: PASS
            game.ProposedPlay(new Loc(0, 1)); // X
            game.ProposedPlay(new Loc(n, n)); // O: PASS
            game.ProposedPlay(new Loc(1, 1)); // X

            // TEST: explicitly check number of groups and each groups stones and breaths.
            Assert.True(game.blackChains.Count == 1);
            Assert.True(game.blackChains.First().Liberties.Count == 4);
        }
Beispiel #10
0
        public void Ko()
        {
            const short n = 4;
            GoGame game = new GoGame { BoardSize = n };

            /* First Step */
            game.ProposedPlay(new Loc(0, 1)); // X
            game.ProposedPlay(new Loc(0, 0)); // O
            game.ProposedPlay(new Loc(n, n)); // X: PASS
            game.ProposedPlay(new Loc(1, 1)); // O
            game.ProposedPlay(new Loc(n, n)); // X: PASS
            game.ProposedPlay(new Loc(2, 0)); // O
            RequestResponse response = game.ProposedPlay(new Loc(1, 0)); // X: 1

            Assert.True(response.Move.ChainsKilled.Count == 1);             // only one group
            Assert.True(response.Move.ChainsKilled[0].Stones.Count == 1);   // of only one stone is killed
            Assert.True(game.PossibleKoLoc.Equals(new Loc(0, 0)));

            /* Second Step */
            response = game.ProposedPlay(new Loc(0, 0)); // O: 2

            Assert.True(game.blackChains.Count == 2);
            Assert.True(game.whiteChains.Count == 2);
            Assert.True(response.Reason == ReasonEnum.Ko);

            /* Play Elsewhere */
            response = game.ProposedPlay(new Loc(2, 2)); // O: 2, again.

            Assert.True(response.Reason == ReasonEnum.Fine);
            Assert.True(response.Move.StonePlaced.IsWhite);
        }
Beispiel #11
0
        public void Kill()
        {
            const short n = 3;
            GoGame game = new GoGame { BoardSize = n };

            game.ProposedPlay(new Loc(0, 1)); // X
            game.ProposedPlay(new Loc(0, 0)); // O
            game.ProposedPlay(new Loc(1, 0)); // 1

            Assert.True(game.blackChains.Count == 2);
            Assert.True(game.blackChains[0].Stones.Count == 1);
            Assert.True(game.blackChains[1].Stones.Count == 1);
            Assert.True(game.whiteChains.Count == 0);
            Assert.True(game.blackChains.First().Liberties.Count == 3);
            Assert.True(game.PrisonersTakenByBlack == 1);
        }
Beispiel #12
0
        public void Disallow_Suicide()
        {
            const short n = 3;
            GoGame game = new GoGame { BoardSize = n };

            game.ProposedPlay(new Loc(n, n)); // X: PASS
            game.ProposedPlay(new Loc(0, 1)); // O
            game.ProposedPlay(new Loc(n, n)); // X: PASS
            game.ProposedPlay(new Loc(1, 0)); // O
            RequestResponse response = game.ProposedPlay(new Loc(0, 0)); // 1

            Assert.True(game.blackChains.Count == 0);
            Assert.True(game.whiteChains.Count == 2);
            Assert.True(response.Reason == ReasonEnum.Suicide);

            // TEST: It's still black's turn
            response = game.ProposedPlay(new Loc(2, 2)); // X
            Assert.True(!response.Move.StonePlaced.IsWhite);

            // TEST: White can still play there.
            response = game.ProposedPlay(new Loc(0, 0)); // O
            Assert.True(response.Reason == ReasonEnum.Fine);
        }
Beispiel #13
0
        public void Disallow_StoneConflict()
        {
            short n = 2;
            GoGame game = new GoGame { BoardSize = n };

            game.ProposedPlay(new Loc(0, 0));

            Assert.True(game.ProposedPlay(new Loc(0, 0)).Reason == ReasonEnum.Conflict);

            // TEST: It's still White's turn.
            Assert.True(game.ProposedPlay(new Loc(1, 1)).Move.StonePlaced.IsWhite);
        }
Beispiel #14
0
        public void Disallow_MergeMakesSuicide()
        {
            const short n = 3;
            GoGame game = new GoGame { BoardSize = n };

            game.ProposedPlay(new Loc(0, 0)); // X
            game.ProposedPlay(new Loc(0, 1)); // O
            game.ProposedPlay(new Loc(2, 0)); // X
            game.ProposedPlay(new Loc(2, 1)); // O
            game.ProposedPlay(new Loc(n, n)); // X: PASS
            game.ProposedPlay(new Loc(1, 1)); // O
            RequestResponse response = game.ProposedPlay(new Loc(1, 0)); // 1

            Assert.True(game.blackChains.Count == 2);
            Assert.True(game.whiteChains.Count == 1);
            Assert.True(game.blackChains.Count(chain => chain.Liberties.First().Equals(new Loc(1, 0))) == 2); // 2 black chains with same Liberty
            Assert.True(response.Reason == ReasonEnum.Suicide);

            // TEST: Still Black's turn.
            Assert.True(!game.ProposedPlay(new Loc(1, 2)).Move.StonePlaced.IsWhite); // X
        }