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 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 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 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 TESTINGERRORCODE() { XElement drawTilesXml = XElement.Parse("<list></list>"); XElement onBoardPlayersXml = XElement.Parse("<list><splayer-nodragon><color>sienna</color><set></set></splayer-nodragon><splayer-dragon><color>red</color><set></set></splayer-dragon></list>"); XElement eliminatedPlayersXml = XElement.Parse("<list><splayer-nodragon><color>blue</color><set></set></splayer-nodragon><splayer-nodragon><color>orange</color><set></set></splayer-nodragon><splayer-nodragon><color>green</color><set></set></splayer-nodragon><splayer-nodragon><color>hotpink</color><set></set></splayer-nodragon></list>"); XElement boardXml = XElement.Parse("<board><map><ent><xy><x>3</x><y>3</y></xy><tile><connect><n>0</n><n>6</n></connect><connect><n>1</n><n>5</n></connect><connect><n>2</n><n>4</n></connect><connect><n>3</n><n>7</n></connect></tile></ent><ent><xy><x>1</x><y>2</y></xy><tile><connect><n>0</n><n>6</n></connect><connect><n>1</n><n>7</n></connect><connect><n>2</n><n>5</n></connect><connect><n>3</n><n>4</n></connect></tile></ent><ent><xy><x>2</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>7</n></connect><connect><n>5</n><n>6</n></connect></tile></ent><ent><xy><x>2</x><y>5</y></xy><tile><connect><n>0</n><n>4</n></connect><connect><n>1</n><n>5</n></connect><connect><n>2</n><n>7</n></connect><connect><n>3</n><n>6</n></connect></tile></ent><ent><xy><x>4</x><y>0</y></xy><tile><connect><n>0</n><n>3</n></connect><connect><n>1</n><n>6</n></connect><connect><n>2</n><n>7</n></connect><connect><n>4</n><n>5</n></connect></tile></ent><ent><xy><x>4</x><y>4</y></xy><tile><connect><n>0</n><n>3</n></connect><connect><n>1</n><n>4</n></connect><connect><n>2</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>6</n></connect><connect><n>1</n><n>7</n></connect><connect><n>2</n><n>4</n></connect><connect><n>3</n><n>5</n></connect></tile></ent><ent><xy><x>5</x><y>1</y></xy><tile><connect><n>0</n><n>6</n></connect><connect><n>1</n><n>3</n></connect><connect><n>2</n><n>4</n></connect><connect><n>5</n><n>7</n></connect></tile></ent><ent><xy><x>5</x><y>5</y></xy><tile><connect><n>0</n><n>1</n></connect><connect><n>2</n><n>6</n></connect><connect><n>3</n><n>7</n></connect><connect><n>4</n><n>5</n></connect></tile></ent><ent><xy><x>3</x><y>1</y></xy><tile><connect><n>0</n><n>6</n></connect><connect><n>1</n><n>4</n></connect><connect><n>2</n><n>3</n></connect><connect><n>5</n><n>7</n></connect></tile></ent><ent><xy><x>3</x><y>5</y></xy><tile><connect><n>0</n><n>6</n></connect><connect><n>1</n><n>4</n></connect><connect><n>2</n><n>5</n></connect><connect><n>3</n><n>7</n></connect></tile></ent><ent><xy><x>1</x><y>4</y></xy><tile><connect><n>0</n><n>3</n></connect><connect><n>1</n><n>7</n></connect><connect><n>2</n><n>4</n></connect><connect><n>5</n><n>6</n></connect></tile></ent><ent><xy><x>2</x><y>3</y></xy><tile><connect><n>0</n><n>3</n></connect><connect><n>1</n><n>5</n></connect><connect><n>2</n><n>6</n></connect><connect><n>4</n><n>7</n></connect></tile></ent><ent><xy><x>4</x><y>2</y></xy><tile><connect><n>0</n><n>4</n></connect><connect><n>1</n><n>6</n></connect><connect><n>2</n><n>3</n></connect><connect><n>5</n><n>7</n></connect></tile></ent><ent><xy><x>0</x><y>5</y></xy><tile><connect><n>0</n><n>1</n></connect><connect><n>2</n><n>7</n></connect><connect><n>3</n><n>6</n></connect><connect><n>4</n><n>5</n></connect></tile></ent><ent><xy><x>5</x><y>3</y></xy><tile><connect><n>0</n><n>6</n></connect><connect><n>1</n><n>2</n></connect><connect><n>3</n><n>4</n></connect><connect><n>5</n><n>7</n></connect></tile></ent><ent><xy><x>2</x><y>0</y></xy><tile><connect><n>0</n><n>4</n></connect><connect><n>1</n><n>2</n></connect><connect><n>3</n><n>6</n></connect><connect><n>5</n><n>7</n></connect></tile></ent><ent><xy><x>1</x><y>5</y></xy><tile><connect><n>0</n><n>6</n></connect><connect><n>1</n><n>3</n></connect><connect><n>2</n><n>7</n></connect><connect><n>4</n><n>5</n></connect></tile></ent><ent><xy><x>2</x><y>4</y></xy><tile><connect><n>0</n><n>1</n></connect><connect><n>2</n><n>3</n></connect><connect><n>4</n><n>6</n></connect><connect><n>5</n><n>7</n></connect></tile></ent><ent><xy><x>1</x><y>1</y></xy><tile><connect><n>0</n><n>3</n></connect><connect><n>1</n><n>5</n></connect><connect><n>2</n><n>4</n></connect><connect><n>6</n><n>7</n></connect></tile></ent><ent><xy><x>4</x><y>3</y></xy><tile><connect><n>0</n><n>7</n></connect><connect><n>1</n><n>2</n></connect><connect><n>3</n><n>4</n></connect><connect><n>5</n><n>6</n></connect></tile></ent><ent><xy><x>0</x><y>2</y></xy><tile><connect><n>0</n><n>4</n></connect><connect><n>1</n><n>5</n></connect><connect><n>2</n><n>6</n></connect><connect><n>3</n><n>7</n></connect></tile></ent><ent><xy><x>5</x><y>0</y></xy><tile><connect><n>0</n><n>4</n></connect><connect><n>1</n><n>2</n></connect><connect><n>3</n><n>7</n></connect><connect><n>5</n><n>6</n></connect></tile></ent><ent><xy><x>5</x><y>4</y></xy><tile><connect><n>0</n><n>1</n></connect><connect><n>2</n><n>5</n></connect><connect><n>3</n><n>4</n></connect><connect><n>6</n><n>7</n></connect></tile></ent><ent><xy><x>3</x><y>0</y></xy><tile><connect><n>0</n><n>3</n></connect><connect><n>1</n><n>6</n></connect><connect><n>2</n><n>5</n></connect><connect><n>4</n><n>7</n></connect></tile></ent><ent><xy><x>3</x><y>4</y></xy><tile><connect><n>0</n><n>5</n></connect><connect><n>1</n><n>3</n></connect><connect><n>2</n><n>7</n></connect><connect><n>4</n><n>6</n></connect></tile></ent><ent><xy><x>1</x><y>3</y></xy><tile><connect><n>0</n><n>3</n></connect><connect><n>1</n><n>6</n></connect><connect><n>2</n><n>4</n></connect><connect><n>5</n><n>7</n></connect></tile></ent><ent><xy><x>2</x><y>2</y></xy><tile><connect><n>0</n><n>5</n></connect><connect><n>1</n><n>4</n></connect><connect><n>2</n><n>7</n></connect><connect><n>3</n><n>6</n></connect></tile></ent><ent><xy><x>4</x><y>5</y></xy><tile><connect><n>0</n><n>4</n></connect><connect><n>1</n><n>7</n></connect><connect><n>2</n><n>3</n></connect><connect><n>5</n><n>6</n></connect></tile></ent><ent><xy><x>0</x><y>4</y></xy><tile><connect><n>0</n><n>4</n></connect><connect><n>1</n><n>3</n></connect><connect><n>2</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>3</n></connect><connect><n>1</n><n>2</n></connect><connect><n>4</n><n>7</n></connect><connect><n>5</n><n>6</n></connect></tile></ent><ent><xy><x>5</x><y>2</y></xy><tile><connect><n>0</n><n>5</n></connect><connect><n>1</n><n>6</n></connect><connect><n>2</n><n>7</n></connect><connect><n>3</n><n>4</n></connect></tile></ent><ent><xy><x>1</x><y>0</y></xy><tile><connect><n>0</n><n>7</n></connect><connect><n>1</n><n>4</n></connect><connect><n>2</n><n>3</n></connect><connect><n>5</n><n>6</n></connect></tile></ent><ent><xy><x>3</x><y>2</y></xy><tile><connect><n>0</n><n>7</n></connect><connect><n>1</n><n>5</n></connect><connect><n>2</n><n>4</n></connect><connect><n>3</n><n>6</n></connect></tile></ent></map><map><ent><color>orange</color><pawn-loc><v></v><n>0</n><n>9</n></pawn-loc></ent><ent><color>red</color><pawn-loc><v></v><n>5</n><n>2</n></pawn-loc></ent><ent><color>sienna</color><pawn-loc><h></h><n>2</n><n>9</n></pawn-loc></ent><ent><color>blue</color><pawn-loc><h></h><n>0</n><n>5</n></pawn-loc></ent><ent><color>hotpink</color><pawn-loc><v></v><n>6</n><n>8</n></pawn-loc></ent><ent><color>green</color><pawn-loc><v></v><n>0</n><n>5</n></pawn-loc></ent></map></board>"); XElement tileToPlayXml = XElement.Parse("<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>"); List <Tile> drawPile = XMLDecoder.xmlToListOfTiles(drawTilesXml); Board b = XMLDecoder.xmlToBoard(boardXml); Tile tileToPlay = XMLDecoder.xmlToTile(tileToPlayXml); SPlayer dragonTileHolder = null; List <SPlayer> activePlayers = new List <SPlayer>(); foreach (XElement splayerXml in onBoardPlayersXml.Elements()) { SPlayer tempPlayer = XMLDecoder.xmlToSplayer(splayerXml); tempPlayer.playerState = SPlayer.State.Playing; if (tempPlayer.isDragonHolder()) { if (dragonTileHolder != null) { throw new TsuroException("Cannot set multiple dragon tile holders."); } dragonTileHolder = tempPlayer; } activePlayers.Add(tempPlayer); } List <SPlayer> eliminatedPlayers = new List <SPlayer>(); foreach (XElement splayerXml in eliminatedPlayersXml.Elements()) { SPlayer tempPlayer = XMLDecoder.xmlToSplayer(splayerXml); eliminatedPlayers.Add(tempPlayer); } // Run our version of play a turn Admin admin = new Admin(activePlayers, eliminatedPlayers, dragonTileHolder, drawPile); TurnResult tr = admin.playATurn(b, tileToPlay); Assert.AreEqual(0, tr.currentPlayers.Count); Assert.AreEqual(6, tr.eliminatedPlayers.Count); Assert.AreEqual(2, tr.playResult.Count); //Convert our turn result into xml strings string outDrawPileXml = XMLEncoder.listOfTilesToXML(tr.drawPile).ToString(); string outActivePlayersXml = XMLEncoder.listOfSPlayerToXML(tr.currentPlayers, admin).ToString(); string outEliminatedPlayersXml = XMLEncoder.listOfSPlayerToXML(tr.eliminatedPlayers, admin).ToString(); string outBoardXml = XMLEncoder.boardToXML(tr.b).ToString(); string outwinnersXML; if (tr.playResult == null) { outwinnersXML = XMLEncoder.encodeFalse().ToString(); } else { outwinnersXML = XMLEncoder.listOfSPlayerToXML(tr.playResult, admin).ToString(); } // Print XML Strings out through stdout Console.WriteLine(XMLEncoder.RemoveWhitespace(outDrawPileXml)); Console.WriteLine(XMLEncoder.RemoveWhitespace(outActivePlayersXml)); Console.WriteLine(XMLEncoder.RemoveWhitespace(outEliminatedPlayersXml)); Console.WriteLine(XMLEncoder.RemoveWhitespace(outBoardXml)); Console.WriteLine(XMLEncoder.RemoveWhitespace(outwinnersXML)); Console.Out.WriteLine(); }