Пример #1
0
        public void MostSymPlayerChoosesMidSymTile()
        {
            TestScenerios test         = new TestScenerios();
            Tile          mostSymTile  = test.makeTile(0, 1, 2, 3, 4, 5, 6, 7);
            Tile          medSymTile   = test.makeTile(0, 6, 1, 5, 2, 4, 3, 7);
            Tile          leastSymTile = test.makeTile(0, 5, 1, 3, 2, 6, 4, 7);

            //purposefully unordered
            List <Tile> playerTiles = test.makeHand(medSymTile, mostSymTile, leastSymTile);

            SPlayer p1 = new SPlayer("hotpink", playerTiles, new MostSymmetricPlayer());

            Board b = new Board();

            p1.initialize(b);
            test.setStartPos00(b, p1);
            // Assign start position to top left of board
            p1.setPosn(new Posn(-1, 0, 5));

            Tile checkTile = p1.playTurn(b, 0);

            //playturn should return the mid symmetric tile (first valid move)
            Assert.IsTrue(checkTile.isEqual(medSymTile));

            Assert.IsTrue(checkTile.paths[0].isEqual(new Path(2, 0)));
            Assert.IsTrue(checkTile.paths[1].isEqual(new Path(3, 7)));
            Assert.IsTrue(checkTile.paths[2].isEqual(new Path(4, 6)));
            Assert.IsTrue(checkTile.paths[3].isEqual(new Path(5, 1)));
        }
Пример #2
0
        public void splayerToXMLNotDragonHolder()
        {
            Board         board = new Board();
            TestScenerios test  = new TestScenerios();
            Tile          t1    = test.makeTile(0, 1, 2, 3, 4, 5, 6, 7);
            List <Tile>   hand  = test.makeHand(t1);
            SPlayer       p1    = new SPlayer("red", hand, new RandomPlayer());

            XElement t1XML = new XElement("tile",
                                          new XElement("connect",
                                                       new XElement("n", 0),
                                                       new XElement("n", 1)),
                                          new XElement("connect",
                                                       new XElement("n", 2),
                                                       new XElement("n", 3)),

                                          new XElement("connect",
                                                       new XElement("n", 4),
                                                       new XElement("n", 5)),

                                          new XElement("connect",
                                                       new XElement("n", 6),
                                                       new XElement("n", 7)));

            XElement splayerXMLExpected = new XElement("splayer-nodragon",
                                                       new XElement("color", "red"),
                                                       new XElement("set",
                                                                    t1XML));
            XElement splayerXMLActual = XMLEncoder.splayerToXML(p1, board);

            Console.WriteLine(splayerXMLActual);

            Assert.IsTrue(XNode.DeepEquals(splayerXMLExpected, splayerXMLActual));
        }
Пример #3
0
        public void LeastSymPlayerChoosesLeastSymTileRotated()
        {
            //the least symmetric tile is not valid unless rotated
            //so the player will rotate the least symmetric tile and play that move
            TestScenerios test         = new TestScenerios();
            Tile          mostSymTile  = test.makeTile(0, 1, 2, 3, 4, 5, 6, 7);
            Tile          medSymTile   = test.makeTile(0, 6, 1, 5, 2, 4, 3, 7);
            Tile          leastSymTile = test.makeTile(0, 5, 1, 3, 2, 6, 4, 7);

            //purposefully unordered
            List <Tile> playerTiles = test.makeHand(medSymTile, mostSymTile, leastSymTile);

            SPlayer p1 = new SPlayer("blue", playerTiles, new LeastSymmetricPlayer());

            Board b = new Board();

            p1.initialize("blue", new List <string> {
                "blue"
            });
            test.setStartPos(b, p1, new Posn(0, 1, 7));

            Tile actualTile = p1.playTurn(b, 0);

            //playturn should return the least symmetric tile rotated once
            Assert.IsTrue(actualTile.isEqualOrRotation(leastSymTile));
            Tile leastSymRot3 = test.makeTile(0, 4, 1, 7, 2, 5, 3, 6);

            Assert.IsTrue(leastSymRot3.isEqual(actualTile));
        }
Пример #4
0
        public void LeastSymPlayerChoosesLeastSymTileRotated()
        {
            //the least symmetric tile is not valid unless rotated once
            //so the player will rotate the least symmetric tile and play that move
            TestScenerios test         = new TestScenerios();
            Tile          mostSymTile  = test.makeTile(0, 1, 2, 3, 4, 5, 6, 7);
            Tile          medSymTile   = test.makeTile(0, 6, 1, 5, 2, 4, 3, 7);
            Tile          leastSymTile = test.makeTile(0, 5, 1, 3, 2, 6, 4, 7);

            //purposefully unordered
            List <Tile> playerTiles = test.makeHand(medSymTile, mostSymTile, leastSymTile);

            SPlayer p1 = new SPlayer("blue", playerTiles, new LeastSymmetricPlayer());
            //p1.initialize("blue", new List<string> { "hotpink", "green" });

            Board b = new Board();

            p1.initialize(b);
            test.setStartPos00(b, p1);
            p1.setPosn(new Posn(1, 0, 0));

            Tile checkTile = p1.playTurn(b, 0);

            //playturn should return the least symmetric tile rotated once
            Assert.IsTrue(checkTile.isEqual(leastSymTile));

            Assert.IsTrue(checkTile.paths[0].isEqual(new Path(2, 7)));
            Assert.IsTrue(checkTile.paths[1].isEqual(new Path(3, 5)));
            Assert.IsTrue(checkTile.paths[2].isEqual(new Path(4, 0)));
            Assert.IsTrue(checkTile.paths[3].isEqual(new Path(6, 1)));
        }
Пример #5
0
        public void PlayerEliminatedOtherPlayersDrawRefilledDeck()
        {
            TestScenerios test = new TestScenerios();
            Tile          t1   = test.makeTile(0, 1, 2, 3, 4, 5, 6, 7);
            Tile          t2   = test.makeTile(0, 7, 2, 3, 4, 5, 6, 1);
            Tile          t3   = test.makeTile(0, 3, 2, 1, 4, 5, 6, 7);

            List <Tile> hand = test.makeHand(t2, t3);

            Board board = new Board();
            Admin admin = new Admin();

            SPlayer p1 = new SPlayer(null, hand, new RandomPlayer());
            SPlayer p2 = new SPlayer(new RandomPlayer());
            SPlayer p3 = new SPlayer(new RandomPlayer());

            p1.initialize("blue", new List <string> {
                "blue", "green", "hotpink"
            });
            p2.initialize("green", new List <string> {
                "blue", "green", "hotpink"
            });
            p3.initialize("hotpink", new List <string> {
                "blue", "green", "hotpink"
            });
            test.setStartPos00(board, p1);
            test.setStartPos(board, p2, new Posn(3, 3, 3));
            test.setStartPos(board, p3, new Posn(4, 3, 3));

            admin.addToActivePlayers(p1);
            admin.addToActivePlayers(p2);
            admin.addToActivePlayers(p3);

            admin.setDragonTileHolder(p2);

            Assert.AreEqual(0, admin.getDrawPileSize());

            TurnResult tr = admin.playATurn(board, t1);

            // Green and hotpink both drew a tile
            // Green has t2
            // Hot pink has t3
            // No dragon tile holder
            Assert.AreEqual(2, admin.numActive());
            SPlayer greenPlayer = admin.getFirstActivePlayer();

            Assert.AreEqual("green", greenPlayer.getColor());
            Assert.IsTrue(admin.isActivePlayer("hotpink"));

            Assert.AreEqual(1, greenPlayer.getHand().Count);
            Assert.AreEqual(1, p3.getHand().Count);
            Assert.IsTrue(greenPlayer.getHand().Exists(x => x.isEqualOrRotation(t2)));
            Assert.IsTrue(p3.getHand().Exists(x => x.isEqualOrRotation(t3)));
            Assert.IsTrue(admin.isDragonHolder("green"));
        }
Пример #6
0
        public void TileInHandNotRotated()
        {
            TestScenerios test = new TestScenerios();
            Tile          t1   = test.makeTile(0, 1, 2, 4, 3, 6, 5, 7);
            Tile          t2   = test.makeTile(0, 6, 1, 5, 2, 4, 3, 7);
            Tile          t3   = test.makeTile(0, 5, 1, 4, 2, 7, 3, 6);
            List <Tile>   hand = test.makeHand(t1, t2, t3);

            Admin a = new Admin();
            Board b = new Board();

            SPlayer player1 = new SPlayer("blue", hand);

            Assert.IsTrue(player1.tileInHand(t1));
        }
Пример #7
0
        public void SPlayerPlayTurnChoosesValidMoveAndRemovesTileFromHand()
        {
            TestScenerios test = new TestScenerios();
            Tile          t1   = test.makeTile(4, 3, 5, 2, 6, 7, 0, 1);
            Tile          t2   = test.makeTile(4, 3, 5, 7, 6, 1, 0, 2);
            Tile          t3   = test.makeTile(4, 5, 6, 0, 7, 1, 2, 3);
            List <Tile>   hand = test.makeHand(t1, t2, t3);

            Admin a = new Admin();
            Board b = new Board();

            SPlayer player1 = new SPlayer("blue", hand);

            player1.setPosn(new Posn(1, 0, 0));
        }
Пример #8
0
        public void PlayerHasRotatedVersionOfSameTileInHand()
        {
            TestScenerios test = new TestScenerios();
            Tile          t1   = test.makeTile(0, 1, 2, 4, 3, 6, 5, 7);

            Admin a = new Admin();
            Board b = new Board();

            List <Tile> playerHand = test.makeHand(t1, t1.rotate());

            SPlayer p1 = new SPlayer("blue", playerHand, new MostSymmetricPlayer());

            p1.initialize(b);
            test.setStartPos00(b, p1);
            p1.playTurn(b, b.drawPile.Count);
            Assert.IsInstanceOfType(p1.playerStrategy, typeof(RandomPlayer));
        }
Пример #9
0
        public void LeastSymPlayerChoosesLeastSymTile()
        {
            TestScenerios test         = new TestScenerios();
            Tile          mostSymTile  = test.makeTile(0, 1, 2, 3, 4, 5, 6, 7);
            Tile          medSymTile   = test.makeTile(0, 6, 1, 5, 2, 4, 3, 7);
            Tile          leastSymTile = test.makeTile(0, 5, 1, 3, 2, 6, 4, 7);

            //purposefully unordered
            List <Tile> playerTiles = test.makeHand(medSymTile, mostSymTile, leastSymTile);
            Board       b           = new Board();

            SPlayer lsp1 = new SPlayer("blue", playerTiles, new LeastSymmetricPlayer());

            lsp1.initialize(b);
            test.setStartPos00(b, lsp1);
            //playturn should return the least symmetric tile
            Assert.IsTrue(lsp1.playTurn(b, 0).isEqual(leastSymTile));
        }
Пример #10
0
        public void PlayerHasTooManyTilesInHand()
        {
            TestScenerios test         = new TestScenerios();
            Tile          mostSymTile  = test.makeTile(0, 1, 2, 3, 4, 5, 6, 7);
            Tile          medSymTile   = test.makeTile(0, 6, 1, 5, 2, 4, 3, 7);
            Tile          leastSymTile = test.makeTile(0, 5, 1, 3, 2, 6, 4, 7);
            Tile          extraTile    = test.makeTile(0, 4, 1, 7, 2, 6, 3, 5);

            Admin       a          = new Admin();
            Board       b          = new Board();
            List <Tile> playerHand = test.makeHand(mostSymTile, medSymTile, leastSymTile, extraTile);

            SPlayer p1 = new SPlayer("blue", playerHand, new MostSymmetricPlayer());

            p1.initialize(b);
            test.setStartPos00(b, p1);
            p1.playTurn(b, b.drawPile.Count);
            Assert.IsInstanceOfType(p1.playerStrategy, typeof(RandomPlayer));
        }
Пример #11
0
        public void PlayerHandAlreadyOnBoard()
        {
            TestScenerios test         = new TestScenerios();
            Tile          mostSymTile  = test.makeTile(0, 1, 2, 3, 4, 5, 6, 7);
            Tile          medSymTile   = test.makeTile(0, 6, 1, 5, 2, 4, 3, 7);
            Tile          leastSymTile = test.makeTile(0, 5, 1, 3, 2, 6, 4, 7);

            Admin a = new Admin();
            Board b = new Board();

            b.grid[1, 1] = mostSymTile;

            SPlayer p1 = new SPlayer("blue", test.makeHand(mostSymTile, medSymTile), new MostSymmetricPlayer());

            p1.initialize(b);
            test.setStartPos00(b, p1);
            p1.playTurn(b, b.drawPile.Count);
            Assert.IsInstanceOfType(p1.playerStrategy, typeof(RandomPlayer));
        }
Пример #12
0
        public void EliminatedPlayerReturnsHandToDrawPile()
        {
            TestScenerios test = new TestScenerios();
            Tile          t1   = test.makeTile(0, 1, 2, 3, 4, 5, 6, 7);
            Tile          t2   = test.makeTile(0, 1, 2, 4, 3, 6, 5, 7);
            Tile          t3   = test.makeTile(0, 5, 2, 3, 4, 7, 1, 6);

            List <Tile> hand = test.makeHand(t1, t2);
            SPlayer     p1   = new SPlayer("blue", hand, new LeastSymmetricPlayer());

            Board board = new Board();

            test.setStartPos(board, p1, new Posn(-1, 0, 4));


            Assert.AreEqual(0, board.drawPile.Count);
            board.eliminatePlayer(p1);
            Assert.AreEqual(2, board.drawPile.Count);
        }
Пример #13
0
        public void PlayerHasTooManyTilesInHand()
        {
            TestScenerios test         = new TestScenerios();
            Tile          mostSymTile  = test.makeTile(0, 1, 2, 3, 4, 5, 6, 7);
            Tile          medSymTile   = test.makeTile(0, 6, 1, 5, 2, 4, 3, 7);
            Tile          leastSymTile = test.makeTile(0, 5, 1, 3, 2, 6, 4, 7);
            Tile          extraTile    = test.makeTile(0, 4, 1, 7, 2, 6, 3, 5);

            Admin       a          = new Admin();
            Board       b          = new Board();
            List <Tile> playerHand = test.makeHand(mostSymTile, medSymTile, leastSymTile, extraTile);

            SPlayer p1 = new SPlayer("blue", playerHand, new MostSymmetricPlayer());

            p1.initialize("blue", new List <string> {
                "blue"
            });
            test.setStartPos00(b, p1);
            Assert.IsTrue(a.isCheating(p1, b, mostSymTile));
        }
Пример #14
0
        public void EliminatedPlayerReturnsHandToDrawPile()
        {
            TestScenerios test = new TestScenerios();
            Tile          t1   = test.makeTile(0, 1, 2, 3, 4, 5, 6, 7);
            Tile          t2   = test.makeTile(0, 1, 2, 4, 3, 6, 5, 7);
            Tile          t3   = test.makeTile(0, 5, 2, 3, 4, 7, 1, 6);

            List <Tile> hand = test.makeHand(t1, t2);
            SPlayer     p1   = new SPlayer("blue", hand, new LeastSymmetricPlayer());

            Admin admin = new Admin();
            Board board = new Board();

            test.setStartPos(board, p1, new Posn(-1, 0, 4));

            admin.addToActivePlayers(p1);

            Assert.AreEqual(0, admin.getDrawPileSize());
            admin.eliminatePlayer(p1.getColor());
            Assert.AreEqual(2, admin.getDrawPileSize());
        }
Пример #15
0
        public void RandomPlayerChoosesTileWhenAllMovesAreValidAndRemovesTileFromHand()
        {
            TestScenerios test = new TestScenerios();
            Tile          t1   = test.makeTile(0, 1, 2, 4, 3, 6, 5, 7);
            Tile          t2   = test.makeTile(0, 6, 1, 5, 2, 4, 3, 7);
            Tile          t3   = test.makeTile(0, 5, 1, 4, 2, 7, 3, 6);

            List <Tile> playerHand = test.makeHand(t1, t2, t3);

            Board   b  = new Board();
            SPlayer p1 = new SPlayer("blue", playerHand, new RandomPlayer());

            p1.initialize(b);
            test.setStartPos00(b, p1);
            p1.setPosn(new Posn(2, 2, 2));

            Tile t = p1.playTurn(b, 0);

            Assert.AreEqual(2, p1.returnHand().Count);
            Assert.IsFalse(p1.returnHand().Exists(x => x.isEqual(t)));
        }
Пример #16
0
        public void MostSymPlayerChoosesOneOfMostSymTile()
        {
            TestScenerios test         = new TestScenerios();
            Tile          mostSymTile1 = test.makeTile(0, 1, 2, 3, 4, 5, 6, 7);
            Tile          medSymTile   = test.makeTile(0, 6, 1, 5, 2, 4, 3, 7);
            Tile          mostSymTile2 = test.makeTile(0, 5, 1, 4, 2, 7, 3, 6);

            //purposefully unordered
            List <Tile> playerTiles = test.makeHand(medSymTile, mostSymTile1, mostSymTile2);

            SPlayer p1 = new SPlayer("blue", playerTiles, new MostSymmetricPlayer());

            Board b = new Board();

            p1.initialize(b);
            test.setStartPos00(b, p1);
            p1.setPosn(new Posn(2, 2, 2));
            Tile checkTile = p1.playTurn(b, 0);

            //playturn should return the most symmetric tile
            Assert.IsTrue(checkTile.isEqual(mostSymTile1));
        }
Пример #17
0
        public void LeastSymPlayerChoosesFirstTileIfAllTilesAreSameSym()
        {
            TestScenerios test = new TestScenerios();
            //the least symmetric tile is not valid unless rotated once
            //so the player will rotate the least symmetric tile and play that move
            Tile leastSymTile1 = test.makeTile(0, 5, 1, 3, 2, 6, 4, 7);
            Tile leastSymTile2 = test.makeTile(0, 3, 1, 4, 2, 7, 5, 6);
            Tile medSymTile    = test.makeTile(0, 6, 1, 5, 2, 4, 3, 7);

            //purposefully unordered
            List <Tile> playerTiles = test.makeHand(medSymTile, leastSymTile1, leastSymTile2);

            Board b = new Board();

            SPlayer lsp1 = new SPlayer("blue", playerTiles, new LeastSymmetricPlayer());

            lsp1.initialize(b);
            test.setStartPos00(b, lsp1);

            //playturn should return the least symmetric tile
            Assert.IsTrue(lsp1.playTurn(b, 0).isEqual(leastSymTile1));
        }
Пример #18
0
        public void PlayerHasRotatedVersionOfSameTileInHand()
        {
            TestScenerios test = new TestScenerios();
            Tile          t1   = test.makeTile(0, 1, 2, 4, 3, 6, 5, 7);

            Admin a = new Admin();
            Board b = new Board();

            List <Tile> playerHand = test.makeHand(t1, t1.rotate());

            SPlayer p1 = new SPlayer("blue", playerHand, new MostSymmetricPlayer());

            p1.initialize("blue", new List <string> {
                "blue"
            });
            test.setStartPos00(b, p1);
            a.addToActivePlayers(p1);

            Tile t = p1.playTurn(b, a.getDrawPileSize());

            Assert.IsTrue(a.isCheating(p1, b, t));
        }
Пример #19
0
        public void SPlayerPlayTurnChoosesValidMoveAndRemovesTileFromHand()
        {
            TestScenerios test = new TestScenerios();
            Tile          t1   = test.makeTile(4, 3, 5, 2, 6, 7, 0, 1);
            Tile          t2   = test.makeTile(4, 3, 5, 7, 6, 1, 0, 2);
            Tile          t3   = test.makeTile(4, 5, 6, 0, 7, 1, 2, 3);
            List <Tile>   hand = test.makeHand(t1, t2, t3);
            Admin         a    = test.createAdminWithDrawPile(new List <Tile> {
            });

            Board   b       = new Board();
            SPlayer player1 = new SPlayer("blue", hand, new RandomPlayer());

            player1.initialize("blue", new List <string> {
                "blue"
            });
            test.setStartPos(b, player1, new Posn(1, 0, 0));
            a.addToActivePlayers(player1);
            Tile t = player1.playTurn(b, a.getDrawPileSize());

            Assert.IsTrue(!b.isEliminationMove("blue", t));
            Assert.IsFalse(player1.getHand().Contains(t));
        }
Пример #20
0
        public void MostSymPlayerChoosesMostSymTile()
        {
            TestScenerios test         = new TestScenerios();
            Tile          mostSymTile  = test.makeTile(0, 1, 2, 3, 4, 5, 6, 7);
            Tile          medSymTile   = test.makeTile(0, 6, 1, 5, 2, 4, 3, 7);
            Tile          leastSymTile = test.makeTile(0, 5, 1, 3, 2, 6, 4, 7);

            //purposefully unordered
            List <Tile> playerTiles = test.makeHand(medSymTile, mostSymTile, leastSymTile);

            SPlayer p1 = new SPlayer("blue", playerTiles, new MostSymmetricPlayer());

            Board b = new Board();

            p1.initialize("blue", new List <string> {
                "blue"
            });
            test.setStartPos(b, p1, new Posn(2, 2, 2));
            Tile checkTile = p1.playTurn(b, 0);

            //playturn should return the most symmetric tile
            Assert.IsTrue(checkTile.isEqualOrRotation(mostSymTile));
        }
Пример #21
0
        public void PlayerHandAlreadyOnBoard()
        {
            TestScenerios test         = new TestScenerios();
            Tile          mostSymTile  = test.makeTile(0, 1, 2, 3, 4, 5, 6, 7);
            Tile          medSymTile   = test.makeTile(0, 6, 1, 5, 2, 4, 3, 7);
            Tile          leastSymTile = test.makeTile(0, 5, 1, 3, 2, 6, 4, 7);

            Admin a = test.createAdminWithDrawPile(new List <Tile> {
            });
            Board b = new Board();

            b.placeTileAt(mostSymTile, 1, 1);

            SPlayer p1 = new SPlayer("blue", test.makeHand(mostSymTile, medSymTile), new MostSymmetricPlayer());

            p1.initialize("blue", new List <string> {
                "blue"
            });
            test.setStartPos00(b, p1);
            Tile t = p1.playTurn(b, a.getDrawPileSize());

            Assert.IsTrue(a.isCheating(p1, b, t));
        }