Пример #1
0
        public void setStartPos00(Board board, SPlayer player)
        {
            //public void setStartPos00(Board board, SPlayer player, string color, List<string> playerOrder) {
            Posn startPos = new Posn(-1, 0, 5);

            player.setPosn(startPos);
            board.registerPlayer(player);
            player.playerState = SPlayer.State.Placed;
        }
Пример #2
0
        public SPlayer createPlayerAtPos(String name, List <Tile> hand,
                                         IPlayer iplayer, Posn posn, Board board)
        {
            SPlayer player = new SPlayer(name, hand, iplayer);

            player.setPosn(posn);
            player.playerState = SPlayer.State.Playing;
            board.registerPlayer(player);
            return(player);
        }
Пример #3
0
        public static Board xmlToBoard(XElement boardXML)
        {
            checkOrderOfTagsFromXML(new List <string> {
                "map", "map"
            },
                                    boardXML.Elements().ToList());

            Board    board    = new Board();
            int      col      = -1;
            int      row      = -1;
            XElement tilesXML = boardXML.Elements("map").ElementAt(0);
            XElement pawnsXML = boardXML.Elements("map").ElementAt(1);

            //create board with tiles placed in correct grid position
            foreach (XElement ent in tilesXML.Elements("ent"))
            {
                try
                {
                    col = Int32.Parse(ent.Descendants("x").ElementAt(0).Value);
                    row = Int32.Parse(ent.Descendants("y").ElementAt(0).Value);
                }
                catch (FormatException e)
                {
                    Console.WriteLine(e.Message);
                }
                Tile tile = xmlToTile(ent.Descendants("tile").ElementAt(0));
                board.grid[row, col] = tile;
            }
            // create pawns (aka onboard players)
            foreach (XElement ent in pawnsXML.Elements("ent"))
            {
                checkOrderOfTagsFromXML(new List <string> {
                    "color", "pawn-loc"
                },
                                        ent.Elements().ToList());

                string      color         = ent.Element("color").Value;
                List <Posn> possiblePosns = xmlToPosn(ent.Element("pawn-loc"));
                Posn        startPos      = pawnLocToPosn(possiblePosns, board);

                SPlayer tempPlayer = new SPlayer();
                tempPlayer.setColor(color);
                tempPlayer.setPosn(startPos);
                board.addPlayerToBoard(tempPlayer);
            }
            return(board);
        }
Пример #4
0
        // Moves all players to the end of their path
        // Returns list of players who end up on the edge
        public void movePlayers()
        {
            List <SPlayer> onEdgePlayers = new List <SPlayer>();

            for (int i = 0; i < getNumActive(); i++)
            {
                SPlayer player = onBoard[i];

                Posn endPos = moveMockPlayer(player.getPlayerPosn());
                player.setPosn(endPos);

                if (onEdge(endPos))
                {
                    onEdgePlayers.Add(player);
                    eliminatePlayer(player);
                    i--;
                }
            }

            if (getNumActive() == 0)
            {
                eliminatedButWinners = onEdgePlayers;
            }
        }
Пример #5
0
        static void Main(string[] args)
        {
            while (true)
            {
                List <XElement> inputXML = new List <XElement>();

                string line;

                for (int i = 0; i < 5; i++)
                {
                    line = Console.ReadLine();

                    // End execution when game is over
                    if (line == null)
                    {
                        return;
                    }
                    inputXML.Add(XElement.Parse(line));
                }
                XElement drawTilesXml         = inputXML[0];
                XElement onBoardPlayersXml    = inputXML[1];
                XElement eliminatedPlayersXml = inputXML[2];
                XElement boardXml             = inputXML[3];
                XElement tileToPlayXml        = inputXML[4];

                List <Tile> drawPile = XMLDecoder.xmlToListOfTiles(drawTilesXml);
                Tile[,] boardGrid = XMLDecoder.xmlBoardToGrid(boardXml);
                Dictionary <string, Posn> colorToPosnMap = XMLDecoder.xmlBoardToPlayerPosns(boardXml);
                Tile    tileToPlay       = XMLDecoder.xmlToTile(tileToPlayXml);
                SPlayer dragonTileHolder = null;

                // Create list of active players from onBoardXml
                List <SPlayer> activePlayers = new List <SPlayer>();
                foreach (XElement splayerXml in onBoardPlayersXml.Elements())
                {
                    string color = XMLDecoder.xmlSPlayerToColor(splayerXml);

                    List <Tile> playerHand = XMLDecoder.xmlSPlayerToHand(splayerXml);
                    SPlayer     tempPlayer = new SPlayer(color, playerHand);
                    tempPlayer.playerState = SPlayer.State.Playing;

                    if (colorToPosnMap[color] == null)
                    {
                        throw new Exception("Active player color was not found on Board player colors");
                    }
                    tempPlayer.setPosn(colorToPosnMap[color]);

                    if (XMLDecoder.SPlayerXmlIsDragonTileHolder(splayerXml))
                    {
                        dragonTileHolder = tempPlayer;
                    }

                    activePlayers.Add(tempPlayer);
                }

                // Create list of eliminated players from onBoardXml
                List <SPlayer> eliminatedPlayers = new List <SPlayer>();
                foreach (XElement splayerXml in eliminatedPlayersXml.Elements())
                {
                    string color = XMLDecoder.xmlSPlayerToColor(splayerXml);

                    List <Tile> playerHand = XMLDecoder.xmlSPlayerToHand(splayerXml);
                    SPlayer     tempPlayer = new SPlayer(color, playerHand);
                    if (colorToPosnMap[color] == null)
                    {
                        throw new Exception("Eliminated player color was not found on Board player colors");
                    }
                    tempPlayer.setPosn(colorToPosnMap[color]);

                    eliminatedPlayers.Add(tempPlayer);
                }

                Board boardWithAllInfo = new Board(drawPile, activePlayers, eliminatedPlayers, dragonTileHolder, boardGrid);

                // Run our version of play a turn
                Admin      admin = new Admin();
                TurnResult tr    = admin.playATurn(boardWithAllInfo, tileToPlay);

                //Convert our turn result into xml strings
                string outDrawPileXml          = XMLEncoder.listOfTilesToXML(tr.drawPile).ToString();
                string outActivePlayersXml     = XMLEncoder.listOfSPlayerToXML(tr.currentPlayers, tr.b).ToString();
                string outEliminatedPlayersXml = XMLEncoder.listOfSPlayerToXML(tr.eliminatedPlayers, tr.b).ToString();
                string outBoardXml             = XMLEncoder.boardToXML(tr.b).ToString();
                string outwinnersXML           = "";

                if (tr.playResult == null)
                {
                    outwinnersXML = XMLEncoder.encodeFalse().ToString();
                }
                else
                {
                    outwinnersXML = XMLEncoder.listOfSPlayerToXML(tr.playResult, tr.b).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();
            }
        }
Пример #6
0
 public void setStartPos(Board board, SPlayer player, Posn pos)
 {
     player.setPosn(pos);
     board.registerPlayer(player);
     player.playerState = SPlayer.State.Placed;
 }