public void Player1MoveCausesPlayer2EliminationBeforeFirstTurn() { TestScenerios test = new TestScenerios(); Tile t1 = test.makeTile(0, 2, 1, 5, 3, 4, 6, 7); Board board = new Board(); Admin admin = new Admin(); SPlayer p1 = new SPlayer("blue", new List <Tile>(), new RandomPlayer()); p1.initialize(board); test.setStartPos(board, p1, new Posn(5, 6, 7)); SPlayer p2 = new SPlayer("green", new List <Tile>(), new RandomPlayer()); p2.initialize(board); test.setStartPos(board, p2, new Posn(5, 6, 6)); TurnResult tr = admin.playATurn(board, t1); Posn p1EndPosExpected = new Posn(5, 5, 0); Posn p1EndPosActual = tr.currentPlayers[0].getPlayerPosn(); Assert.IsTrue(p1EndPosExpected.isEqual(p1EndPosActual)); Assert.IsTrue(tr.eliminatedPlayers.Exists(x => x.returnColor() == "green")); Assert.IsTrue(tr.playResult.Exists(x => x.returnColor() == "blue")); }
public void ValidTurnCausePlayerToBeEliminated() { 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> drawpile = test.makeDrawPile(t2, t3); Admin a = test.createAdminWithDrawPile(drawpile); Board b = new Board(); SPlayer p1 = new SPlayer("p1", new List <Tile>()); Posn p1Pos = new Posn(0, 1, 6); test.setStartPos(b, p1, p1Pos); SPlayer p2 = new SPlayer("p2", new List <Tile>()); Posn p2Pos = new Posn(4, 4, 0); test.setStartPos(b, p2, p2Pos); a.addToActivePlayers(p1); a.addToActivePlayers(p2); TurnResult tmpturn = a.playATurn(b, t1); Assert.AreEqual(1, a.numEliminated(), "count of eliminated players has not increased to 1"); Assert.IsTrue(tmpturn.eliminatedPlayers.Count == 1, "count of eliminated players has not increased to 1"); Assert.IsTrue(tmpturn.eliminatedPlayers.Exists(x => x.getColor() == "p1"), "p1 has not been moved to eliminated players"); Assert.IsFalse(tmpturn.currentPlayers.Exists(x => x.getColor() == "p1"), "p1 has not been removed from current players"); Assert.IsTrue(tmpturn.currentPlayers.Count == 1, "count of current players has not decreased to 1"); }
public void boardToXMLWithEliminatedPlayers() { Board board = new Board(); TestScenerios test = new TestScenerios(); // Board set up Tile normalTile = test.makeTile(0, 1, 2, 4, 3, 6, 5, 7); Tile eliminationTile = test.makeTile(0, 1, 2, 3, 4, 5, 6, 7); board.placeTileAt(normalTile, 0, 0); board.placeTileAt(eliminationTile, 3, 0); // Player set up SPlayer activePlayer = new SPlayer("red", new List <Tile>(), new RandomPlayer()); //activePlayer.initialize(board); test.setStartPos(board, activePlayer, new Posn(0, 0, 3)); SPlayer eliminatedPlayer = new SPlayer("blue", new List <Tile>(), new RandomPlayer()); //eliminatedPlayer.initialize(board); test.setStartPos(board, eliminatedPlayer, new Posn(3, 0, 7)); // Test XElement boardToXMLActual = XMLEncoder.boardToXML(board); XElement boardToXMLExpected = XElement.Parse("<board><map><ent><xy><x>0</x><y>0</y></xy><tile><connect><n>0</n><n>1</n></connect><connect><n>2</n><n>4</n></connect><connect><n>3</n><n>6</n></connect><connect><n>5</n><n>7</n></connect></tile></ent><ent><xy><x>0</x><y>3</y></xy><tile><connect><n>0</n><n>1</n></connect><connect><n>2</n><n>3</n></connect><connect><n>4</n><n>5</n></connect><connect><n>6</n><n>7</n></connect></tile></ent></map><map><ent><color>red</color><pawn-loc><v></v><n>1</n><n>1</n></pawn-loc></ent><ent><color>blue</color><pawn-loc><v></v><n>0</n><n>6</n></pawn-loc></ent></map></board>"); Assert.IsTrue(XNode.DeepEquals(boardToXMLActual, boardToXMLExpected)); }
public void boardToXMLPlayerEliminatedCurrentTurn() { Admin a = new Admin(); Board board = new Board(); TestScenerios test = new TestScenerios(); // Board set up Tile normalTile = test.makeTile(0, 1, 2, 4, 3, 6, 5, 7); Tile eliminationTile = test.makeTile(0, 1, 2, 3, 4, 5, 6, 7); Tile drawPileTile = test.makeTile(0, 3, 2, 1, 4, 7, 6, 5); board.grid[0, 0] = normalTile; board.addTileToDrawPile(drawPileTile); // Player set up SPlayer eliminatedPlayer = new SPlayer("blue", new List <Tile>(), new RandomPlayer()); eliminatedPlayer.initialize(board); test.setStartPos(board, eliminatedPlayer, new Posn(3, -1, 3)); SPlayer activePlayer = new SPlayer("red", new List <Tile>(), new RandomPlayer()); activePlayer.initialize(board); test.setStartPos(board, activePlayer, new Posn(0, 0, 3)); TurnResult tmpturn = a.playATurn(board, eliminationTile); // Test XElement boardToXMLActual = XMLEncoder.boardToXML(tmpturn.b); XElement boardToXMLExpected = XElement.Parse("<board><map><ent><xy><x>0</x><y>0</y></xy><tile><connect><n>0</n><n>1</n></connect><connect><n>2</n><n>4</n></connect><connect><n>3</n><n>6</n></connect><connect><n>5</n><n>7</n></connect></tile></ent><ent><xy><x>0</x><y>3</y></xy><tile><connect><n>0</n><n>1</n></connect><connect><n>2</n><n>3</n></connect><connect><n>4</n><n>5</n></connect><connect><n>6</n><n>7</n></connect></tile></ent></map><map><ent><color>red</color><pawn-loc><v></v><n>1</n><n>1</n></pawn-loc></ent><ent><color>blue</color><pawn-loc><v></v><n>0</n><n>6</n></pawn-loc></ent></map></board>"); Assert.IsTrue(XNode.DeepEquals(boardToXMLActual, boardToXMLExpected)); }
public void DragonHolderEliminatedPassestoNextClockwisePlayer() { Admin a = new Admin(); Board board = new Board(); SPlayer p1 = new SPlayer("blue", new List <Tile>(), new RandomPlayer()); SPlayer p2 = new SPlayer("green", new List <Tile>(), new RandomPlayer()); SPlayer p3 = new SPlayer("hotpink", new List <Tile>(), new RandomPlayer()); // Initialize start positions to satisfy contract - can't be // eliminated before placing pawn TestScenerios test = new TestScenerios(); test.setStartPos00(board, p1); test.setStartPos(board, p2, new Posn(3, 3, 3)); test.setStartPos(board, p3, new Posn(4, 3, 3)); a.addToActivePlayers(p1); a.addToActivePlayers(p2); a.addToActivePlayers(p3); a.setDragonTileHolder(p2); a.eliminatePlayer(p2.getColor()); Assert.IsTrue(a.isDragonHolder("hotpink")); Assert.IsTrue(p3.getHand().Count < 3); }
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")); }
public void test() { Board board = new Board(); TestScenerios test = new TestScenerios(); Tile t1 = test.makeTile(0, 1, 2, 4, 3, 6, 5, 7); board.grid[0, 0] = t1; SPlayer p1 = new SPlayer("red", new List <Tile>(), new RandomPlayer()); p1.initialize(board); test.setStartPos(board, p1, new Posn(0, 0, 3)); XElement boardToXML = XMLEncoder.boardToXML(board); XElement boardToXMLExpected = XElement.Parse("<board><map><ent><xy><x>0</x><y>0</y></xy><tile><connect><n>0</n><n>1</n></connect><connect><n>2</n><n>4</n></connect><connect><n>3</n><n>6</n></connect><connect><n>5</n><n>7</n></connect></tile></ent></map><map><ent><color>red</color><pawn-loc><v></v><n>1</n><n>1</n></pawn-loc></ent></map></board>"); Assert.IsTrue(XNode.DeepEquals(boardToXML, boardToXMLExpected)); XElement tilesXML = boardToXMLExpected.Elements("map").ElementAt(0); Console.WriteLine(tilesXML); XElement pawnsXML = boardToXMLExpected.Elements("map").ElementAt(1); Console.WriteLine(pawnsXML); string xval = tilesXML.Descendants("x").ElementAt(0).Value; int x = int.Parse(xval); Console.WriteLine(x); }
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("hotpink", new List <string> { "hotpink" }); test.setStartPos(b, p1, new Posn(-1, 0, 5)); Tile checkTile = p1.playTurn(b, 0); //playturn should return the mid symmetric tile (first valid move) Assert.IsTrue(checkTile.isEqualOrRotation(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))); }
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)); }
public void pawnToXML() { TestScenerios test = new TestScenerios(); Board board = new Board(); SPlayer p1 = new SPlayer("blue", new List <Tile>()); test.setStartPos(board, p1, new Posn(0, 0, 5)); SPlayer p2 = new SPlayer("hotpink", new List <Tile>()); test.setStartPos(board, p2, new Posn(4, 4, 5)); SPlayer p3 = new SPlayer("green", new List <Tile>()); test.setStartPos(board, p3, new Posn(3, 2, 6)); List <SPlayer> players = new List <SPlayer> { p1, p2, p3 }; XElement playersToXML = XMLEncoder.pawnsToXML(new List <string> { "blue", "hotpink", "green" }, board); XElement playersToXMLExpected = new XElement("map", new XElement("ent", new XElement("color", "blue"), new XElement("pawn-loc", new XElement("h", ""), new XElement("n", 1), new XElement("n", 0))), new XElement("ent", new XElement("color", "hotpink"), new XElement("pawn-loc", new XElement("h", ""), new XElement("n", 5), new XElement("n", 8))), new XElement("ent", new XElement("color", "green"), new XElement("pawn-loc", new XElement("v", ""), new XElement("n", 2), new XElement("n", 7)))); Assert.IsTrue(XNode.DeepEquals(playersToXML, playersToXMLExpected)); }
public void XMLToBoardStartGame() { XElement boardXML = XElement.Parse("<board>" + "<map>" + "<ent><xy><x>0</x><y>1</y></xy>" + "<tile>" + "<connect><n>0</n><n>1</n></connect>" + "<connect><n>2</n><n>4</n></connect>" + "<connect><n>3</n><n>6</n></connect>" + "<connect><n>5</n><n>7</n></connect>" + "</tile>" + "</ent>" + "</map>" + "<map>" + "<ent><color>red</color><pawn-loc><h></h><n>0</n><n>0</n></pawn-loc>" + "</ent></map></board>"); Board expected = new Board(); TestScenerios test = new TestScenerios(); Tile t1 = test.makeTile(0, 1, 2, 4, 3, 6, 5, 7); expected.grid[1, 0] = t1; SPlayer p1 = new SPlayer("red", new List <Tile>(), new RandomPlayer()); p1.initialize(expected); test.setStartPos(expected, p1, new Posn(-1, 0, 5)); Board actual = XMLDecoder.xmlToBoard(boardXML); // Check boards are the same for (int i = 0; i < expected.grid.GetLength(0); i++) { for (int j = 0; j < expected.grid.GetLength(0); j++) { if (expected.grid[i, j] == null) { Assert.IsNull(actual.grid[i, j]); } else { Assert.IsTrue(expected.grid[i, j].isEqual(actual.grid[i, j])); } } } // Check players are the same Assert.AreEqual(expected.getNumActive(), actual.getNumActive()); List <string> expectedActivePlayers = expected.getPlayerOrder(); foreach (string color in expectedActivePlayers) { Assert.IsTrue(actual.isOnBoard(color)); } }
public void boardToXMLSimple() { Board board = new Board(); TestScenerios test = new TestScenerios(); Tile t1 = test.makeTile(0, 1, 2, 4, 3, 6, 5, 7); board.grid[0, 0] = t1; SPlayer p1 = new SPlayer("red", new List <Tile>(), new RandomPlayer()); p1.initialize(board); test.setStartPos(board, p1, new Posn(0, 0, 3)); XElement boardToXML = XMLEncoder.boardToXML(board); XElement boardToXMLExpected = XElement.Parse("<board><map><ent><xy><x>0</x><y>0</y></xy><tile><connect><n>0</n><n>1</n></connect><connect><n>2</n><n>4</n></connect><connect><n>3</n><n>6</n></connect><connect><n>5</n><n>7</n></connect></tile></ent></map><map><ent><color>red</color><pawn-loc><v></v><n>1</n><n>1</n></pawn-loc></ent></map></board>"); Assert.IsTrue(XNode.DeepEquals(boardToXML, boardToXMLExpected)); }
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); }
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()); }
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("blue", new List <string> { "blue" }); test.setStartPos(b, p1, new Posn(2, 2, 2)); Tile t = p1.playTurn(b, 0); Assert.AreEqual(2, p1.getHand().Count); Assert.IsFalse(p1.getHand().Exists(x => x.isEqualOrRotation(t))); }
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)); }
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("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(mostSymTile1)); }
public void XMLToBoardBothActiveAndEliminatedPlayers() { XElement boardXML = XElement.Parse("<board>" + "<map>" + "<ent>" + "<xy><x>1</x><y>2</y></xy>" + "<tile>" + "<connect><n>0</n><n>1</n></connect>" + "<connect><n>2</n><n>4</n></connect>" + "<connect><n>3</n><n>6</n></connect>" + "<connect><n>5</n><n>7</n></connect>" + "</tile>" + "</ent>" + "<ent>" + "<xy><x>0</x><y>0</y></xy>" + "<tile>" + "<connect><n>0</n><n>1</n></connect>" + "<connect><n>2</n><n>3</n></connect>" + "<connect><n>4</n><n>5</n></connect>" + "<connect><n>6</n><n>7</n></connect>" + "</tile>" + "</ent>" + "</map>" + "<map>" + "<ent><color>red</color><pawn-loc><h></h><n>0</n><n>0</n></pawn-loc></ent>" + "<ent><color>blue</color><pawn-loc><h></h><n>3</n><n>3</n></pawn-loc></ent>" + "</map>" + "</board>"); Board expected = new Board(); TestScenerios test = new TestScenerios(); Tile t1 = test.makeTile(0, 1, 2, 4, 3, 6, 5, 7); Tile t2 = test.makeTile(0, 1, 2, 3, 4, 5, 6, 7); expected.placeTileAt(t1, 2, 1); expected.placeTileAt(t2, 0, 0); SPlayer p1 = new SPlayer("red", new List <Tile>(), new RandomPlayer()); //p1.initialize(expected); test.setStartPos(expected, p1, new Posn(0, 0, 0)); SPlayer p2 = new SPlayer("blue", new List <Tile>(), new RandomPlayer()); //p2.initialize(expected); test.setStartPos(expected, p2, new Posn(2, 1, 4)); Board actual = XMLDecoder.xmlToBoard(boardXML); // Check boards are the same for (int i = 0; i < expected.getBoardLength(); i++) { for (int j = 0; j < expected.getBoardLength(); j++) { if (expected.getTileAt(i, j) == null) { Assert.IsNull(actual.getTileAt(i, j)); } else { Assert.IsTrue(expected.getTileAt(i, j).isEqualOrRotation(actual.getTileAt(i, j))); } } } // Check players are the same //Assert.IsTrue(actual.isOnBoard("blue")); //Assert.IsFalse(actual.isOnBoard("red")); //Assert.IsTrue(actual.isEliminated("red")); //Assert.IsFalse(actual.isEliminated("blue")); //Assert.AreEqual(1, actual.getNumActive()); //Assert.AreEqual(1, actual.getNumEliminated()); }