コード例 #1
0
        /// <summary>
        /// Creates a deep copy of this player.
        /// </summary>
        /// <returns>Returns a deep copy of this player.</returns>
        public override Player <MahjongMove> Clone()
        {
            MahjongHumanPlayer ret = new  MahjongHumanPlayer(CardsInHand.Cards);

            ret.CopyData(this);

            return(ret);
        }
コード例 #2
0
        /// <summary>
        /// Called to let a player join the game replacing an AI player.
        /// </summary>
        /// <param name="index">The index of the AI player to replace.</param>
        /// <returns>Returns true if the player joined the game and false otherwise.</returns>
        /// <remarks>Only AI players can be booted for a human player to join. If you want to replace the AI behaviour indirectly, use PlayerLeft instead.</remarks>
        public bool PlayerJoined(int index)
        {
            if (index < 0 || index > 4 || !players[index].IsAI)
            {
                return(false);
            }

            MahjongPlayer old = players[index] as MahjongPlayer;

            players[index] = new MahjongHumanPlayer(players[index].CardsInHand.Cards);
            (players[index] as MahjongPlayer).CopyData(old);

            return(true);
        }
コード例 #3
0
        /// <summary>
        /// Creates a new game state.
        /// All players default to human until replaced by an AI.
        /// </summary>
        public MahjongGameState()
        {
            // Create the deck
            Deck = new MahjongDeck();

            // State variables
            AvailableTile = null;
            OnReplacement = 0;

            Heavenly = true;
            Earthly  = true;

            // Set up hand data
            Hand      = 1;
            BonusHand = 0;

            // Create the players
            ActivePlayer    = 0;
            SubActivePlayer = 0;

            players      = new Player <MahjongMove> [4];
            player_moves = new MahjongMove[4];

            MahjongPlayer[] mp = new MahjongPlayer[4];

            for (int i = 0; i < 4; i++)
            {
                players[i]      = new MahjongHumanPlayer(new List <Card>(Deck.Draw(13)));
                player_moves[i] = null;

                mp[i]       = players[i] as MahjongPlayer;
                mp[i].Score = 0;

                // If a player has bonus tiles, we need to replace them
                RemoveBonusTiles(players[i], mp[i]);
            }

            // Set the initial seat winds (prevailing winds default to east as desired)
            // Note that we don't need to randomise the seat winds; a user can just put the players in a different order if they want something different
            mp[0].SeatWind = SuitIdentifier.EAST_WIND;
            mp[1].SeatWind = SuitIdentifier.SOUTH_WIND;
            mp[2].SeatWind = SuitIdentifier.WEST_WIND;
            mp[3].SeatWind = SuitIdentifier.NORTH_WIND;

            // Give east their first draw, and make sure the draw wasn't a bonus tile
            DrawFromWall(players[0], mp[0]);

            return;
        }