Exemple #1
0
        // Eliminates a player
        //
        // Removes from active player list, adds to eliminated player list,
        // returns  all tiles to the draw pile
        public void eliminatePlayer(string color)
        {
            SPlayer p = activePlayers.Find(x => color == x.getColor());

            if (p == null)
            {
                throw new TsuroException("Cannot find an active player with color " + color + " to eliminate.");
            }
            if ((p.playerState != SPlayer.State.Placed) && (p.playerState != SPlayer.State.Playing))
            {
                throw new TsuroException("Player is being eliminated before having placed a start pawn.");
            }


            // Add eliminated player's tiles to draw pile, and remove from his/her hand
            if (p.getHandSize() != 0)
            {
                List <Tile> hand = p.getHand();
                for (int i = 0; i < hand.Count; i++)
                {
                    Tile tempTile = hand[i];
                    p.removeTileFromHand(tempTile);
                    addTileToDrawPile(tempTile);
                    i--;
                }
            }


            // Eliminated player is dragon tile holder
            if (dragonTileHolder != null && dragonTileHolder.getColor() == p.getColor())
            {
                // Get index of eliminated player in active players list
                int currIndex = activePlayers.FindIndex(x => p.getColor() == x.getColor());;

                // Pass dragon tile to next player with less than 3 tiles in hand
                SPlayer nextPlayer;
                do
                {
                    currIndex += 1;
                    nextPlayer = activePlayers[(currIndex) % activePlayers.Count];
                } while (nextPlayer.getHandSize() >= 3);

                if (nextPlayer.getColor() == p.getColor())
                {
                    // Cannot find player with fewer than 3 tiles in hand
                    dragonTileHolder = null;
                }
                else
                {
                    dragonTileHolder = nextPlayer;
                }
            }

            eliminatedPlayers.Add(p);
            activePlayers.Remove(p);
            p.eliminate();
        }
Exemple #2
0
        /*************** HELPER FUNCTIONS ****************************/

        // Returns whether a player is cheating
        public bool isCheating(SPlayer p, Board b, Tile t)
        {
            // Check legal play - t is in hand, and valid move
            // Valid moves cannot be elimination moves, unless there are no other options
            if (!legalPlay(p, b, t))
            {
                Console.WriteLine("Cheating: non-legal play.");
                return(true);
            }

            // Check that tile to be played is not a rotation of another tile in player's hand
            List <Tile> hand = p.getHand();

            for (int i = 0; i < hand.Count; i++)
            {
                if (hand[i].isEqualOrRotation(t))
                {
                    Console.WriteLine("Cheating: player has duplicate tiles in hand.");
                    return(true);
                }
            }

            //for (int i = 0; i < hand.Count - 1; i++)
            //       {
            //           for (int j = i + 1; j < hand.Count; j++)
            //           {
            //if (hand[i].isEqualOrRotation(hand[j]))
            //              {
            //Console.WriteLine("Cheating: player has duplicate tiles in hand.");
            //return true;
            //        }
            //    }
            //}

            // Check number of tiles in hand
            if (hand.Count > 3)
            {
                Console.WriteLine("Cheating: player has more than 3 tiles in hand.");
                return(true);
            }

            // Check player's tiles are not already on board
            foreach (Tile tile in hand)
            {
                if (b.tileExistsOnBoard(tile))
                {
                    Console.WriteLine("Cheating: player's set of tiles is already on the board.");
                    return(true);
                }
            }

            return(false);
        }
Exemple #3
0
        public static XElement splayerToXML(SPlayer player, Admin a)
        {
            XElement splayerXML;

            if (a.getDragonTileHolder() != null &&
                a.getDragonTileHolder().getColor() == player.getColor())
            {
                splayerXML = new XElement("splayer-dragon");
            }
            else
            {
                splayerXML = new XElement("splayer-nodragon");
            }


            XElement handTileXML = playerHandToXML(player.getHand());

            splayerXML.Add(new XElement("color", player.getColor()),
                           handTileXML);
            return(splayerXML);
        }