Beispiel #1
0
    public void SetLackTile(int index, TileDef.Kind k)
    {
        Debug.Log("SetLackTile---->" + index + ":" + k);
        MahjongPlayer player = _playPlayers [index];

        player.Proxy.LackTileKind = k;
    }
Beispiel #2
0
        /// <summary>
        /// Draws a tile from the wall. Automatically replaces bonus tiles.
        /// </summary>
        protected bool DrawFromWall(Player <MahjongMove> player, MahjongPlayer mp, bool from_kong = false)
        {
            if (!from_kong)
            {
                OnReplacement = 0;
            }

            if (Deck.CountDrawPile == 0)
            {
                return(false);
            }

            Card c = Deck.Draw();

            while (c.Suit.Color == SuitColor.BONUS)
            {
                mp.BonusTiles.DrawCard(c);
                OnReplacement++;

                if (Deck.CountDrawPile == 0)
                {
                    return(false);                    // It's okay to draw bonus tiles without ever getting a proper tile
                }
                c = Deck.Draw();
            }

            player.CardsInHand.DrawCard(c);
            return(true);
        }
    public void CloseCombo(TileDef.ComboType type, MahjongPlayer player)
    {
        if (!OpenViewRoot())
        {
            return;
        }

        switch (type)
        {
        case TileDef.ComboType.CHOW:
            if (--_chow <= 0)
            {
                _view._btnChow.gameObject.SetActive(false);
            }
            break;

        case TileDef.ComboType.PONG:
            if (--_pong <= 0)
            {
                _view._btnPong.gameObject.SetActive(false);
            }
            break;

        case TileDef.ComboType.KONG:
        case TileDef.ComboType.KONG_DARK:
        case TileDef.ComboType.KONG_TURN:
            if (--_kong <= 0)
            {
                _view._btnKong.gameObject.SetActive(false);
            }
            break;

        case TileDef.ComboType.WIN:
        case TileDef.ComboType.WIN_SELF:
        case TileDef.ComboType.WIN_AFTER_KONG_TURN:
            if (--_win <= 0)
            {
                _view._btnWin.gameObject.SetActive(false);
            }
            break;

        case TileDef.ComboType.PASS:
        case TileDef.ComboType.PASS_CANCEL:
            if (--_pass <= 0)
            {
                _view._btnPass.gameObject.SetActive(false);
            }
            break;

        case TileDef.ComboType.BAO_TING:
            if (--_baoting <= 0)
            {
                _view._btnBaoTing.gameObject.SetActive(false);
            }
            break;
        }
    }
Beispiel #4
0
    public void AutoPlay(int index, TileDef def, int flag)
    {
        MahjongPlayer player = _playPlayers [index];

        if (player == _self && flag == 0)
        {
            return;
        }
        bool ok = player.Play(def);

        player.SortPocketListAfterPlay();
        Debug.Log("auto play ==================== " + index + "=====================" + player.Proxy.ToString());
    }
Beispiel #5
0
        /// <summary>
        /// Handles all the logic necessary for a declaration of mahjong, including scoring and setting up the next round, and, if necessary, delcaring the game finished.
        /// </summary>
        protected void Mahjong(int player_index, bool stolen_from_kong = false)
        {
            MahjongPlayer[] mp = new MahjongPlayer[4];

            for (int i = 0; i < 4; i++)
            {
                mp[i] = players[i] as MahjongPlayer;
            }

            // Score the hand
            int fan         = MahjongStaticFunctions.HandFan(mp[player_index].Melds, mp[player_index].SeatWind, PrevailingWind, player_moves[player_index].SelfPick, Deck.CountDrawPile == 0, OnReplacement > 0, OnReplacement > 1, stolen_from_kong, Heavenly, Earthly);
            int base_points = MahjongStaticFunctions.FanToBasePoints(fan);

            // Payout the score
            for (int i = 0; i < 4; i++)
            {
                if (i != player_index)
                {
                    int factor = payment_factor(player_index, i);

                    mp[i].Score            -= factor * base_points;
                    mp[player_index].Score += factor * base_points;
                }
            }

            // Go to the next hand
            if (mp[player_index].SeatWind == SuitIdentifier.EAST_WIND)
            {
                // East won, so we have a bonus hand
                BonusHand++;

                if (BonusHand > MaxBonusHand)
                {
                    BonusHand = 0;
                    Hand++;
                }
            }
            else
            {
                // East didn't win, so no bonus hand
                BonusHand = 0;
                Hand++;
            }

            if (!GameFinished)
            {
                InitHand();
            }

            return;
        }
Beispiel #6
0
        /// <summary>
        /// Removes all the bonus tiles from the player's hand AND replaces them.
        /// </summary>
        protected void RemoveBonusTiles(Player <MahjongMove> player, MahjongPlayer mp)
        {
            for (int i = 0; i < player.CardsInHand.CardsInHand; i++)
            {
                if (player.CardsInHand.Cards[i].Suit.Color == SuitColor.BONUS)
                {
                    mp.BonusTiles.DrawCard(player.CardsInHand.PlayCard(i));
                    player.CardsInHand.DrawCard(Deck.Draw());
                    i--;
                }
            }

            return;
        }
Beispiel #7
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);
        }
Beispiel #8
0
        /// <summary>
        /// If a player leaves the game then they are replaced with an AI player.
        /// </summary>
        /// <param name="index">The index of the player that left.</param>
        /// <param name="replacement">The replacement AI. If null then a default behavior will be used.</param>
        /// <remarks>An AI player can leave the game to be replaced by a new AI player.</remarks>
        public void PlayerLeft(int index, AIBehavior <MahjongMove> replacement = null)
        {
            if (index < 0 || index > 4)
            {
                return;
            }

            MahjongPlayer old = players[index] as MahjongPlayer;

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

            return;
        }
Beispiel #9
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;
        }
Beispiel #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="resultData"></param>
        /// <param name="huList"></param>
        /// <param name="isBaoExist">是否需要冲宝</param>
        /// <param name="isQingfengExist"></param>
        /// <returns></returns>
        public int SetResultInfo(ResultInfoData resultData, List <int> huList, bool isBaoExist = false, bool isQingfengExist = false)
        {
            #region data
            _resultData = resultData;
            if (_resultData.HuType == 2)//目前自摸情况下,会把胡的那张牌从手牌中带回来,这里删掉。目前只有一个胡牌,所以这么删,待扩展
            {
                resultData.HandList.Remove(huList[0]);
                if (isBaoExist)
                {
                    resultData.HandList.Add(huList[0]);
                }
            }
            #endregion
            #region UI
            MahjongPlayer player = Players[_resultData.UserSeat];
            LabelUserName.text = player.UserInfo.name;
            ZhuangSprite.SetActive(player.IsZhuang);
            LabelFanName.text = _resultData.FanName;
            LabelHuScore.TrySetComponentValue(YxUtiles.GetShowNumber(_resultData.HuNumber).ToString());
            LabelGangNum.TrySetComponentValue(YxUtiles.GetShowNumber(_resultData.GangNum).ToString());
            GuoDanScoreLabel.TrySetComponentValue(YxUtiles.GetShowNumber(_resultData.GuoDanSocre).ToString());
            _qingfengObj.TrySetComponentValue(isQingfengExist);
            _labelQingfeng.TrySetComponentValue(YxUtiles.GetShowNumber(_resultData.QingFengScore).ToString());
            LabelTotalScore.TrySetComponentValue(YxUtiles.GetShowNumber(_resultData.NowRoundScore).ToString());
            if (HeadTexture)
            {
                HeadTexture.mainTexture = player.CurrentInfoPanel.UserIcon.GetTexture();
            }
            player.UserInfo.Gold = _resultData.TotalGold;
            player.CurrentInfoPanel.SetGold(_resultData.TotalGold);
            HuLogo.TrySetComponentValue(IsWiner);
            _infoBg.TrySetComponentValue(IsWiner ? ConstantData.KeyWinerBg : ConstantData.KeyNormalBg);
            if (_scoreGrid)
            {
                _scoreGrid.repositionNow = true;
            }

            #endregion

            if (resultData.FenZhangCard > 0)
            {
                huList.Clear();
                huList.Add(resultData.FenZhangCard);
            }
            _resultCards.Init(_resultData.MahjongGroups, resultData.HandList, huList, _resultData.IsWiner, resultData.FenZhangCard);
            return(_resultData.HuType);
        }
    public void OpenCombo(TileDef.ComboType type, MahjongPlayer player)
    {
        if (!OpenViewRoot())
        {
            return;
        }

        switch (type)
        {
        case TileDef.ComboType.CHOW:
            ++_chow;
            _view._btnChow.gameObject.SetActive(true);
            break;

        case TileDef.ComboType.PONG:
            ++_pong;
            _view._btnPong.gameObject.SetActive(true);
            break;

        case TileDef.ComboType.KONG:
        case TileDef.ComboType.KONG_DARK:
        case TileDef.ComboType.KONG_TURN:
            ++_kong;
            _view._btnKong.gameObject.SetActive(true);
            break;

        case TileDef.ComboType.WIN:
        case TileDef.ComboType.WIN_SELF:
        case TileDef.ComboType.WIN_AFTER_KONG_TURN:
            ++_win;
            _view._btnWin.gameObject.SetActive(true);
            break;

        case TileDef.ComboType.PASS:
        case TileDef.ComboType.PASS_CANCEL:
            ++_pass;
            _view._btnPass.gameObject.SetActive(true);
            break;

        case TileDef.ComboType.BAO_TING:
            ++_baoting;
            _view._btnBaoTing.gameObject.SetActive(true);
            break;
        }
    }
Beispiel #12
0
        public void SetResultInfo(ISFSObject data, MahjongPlayer player, List <int> handCards, List <int> huList)
        {
            #region data

            int       type;
            long      totalGold;
            ISFSArray Groups;
            GameTools.TryGetValueWitheKey(data, out type, RequestKey.KeyType);
            GameTools.TryGetValueWitheKey(data, out _huNum, RequestKey.KeyHuNum);
            GameTools.TryGetValueWitheKey(data, out _gangNum, RequestKey.KeyGangNum);
            GameTools.TryGetValueWitheKey(data, out _fanName, RequestKey.KeyHuName);
            GameTools.TryGetValueWitheKey(data, out _totalNum, RequestKey.KeyGold);
            GameTools.TryGetValueWitheKey(data, out totalGold, RequestKey.KeyTotalGold);
            GameTools.TryGetValueWitheKey(data, out Groups, RequestKey.KeyGroups);
            var groups = GameTools.GetGroupData(Groups);
            YxDebug.Log("手牌总长度是:" + handCards.Count);
            _isWiner = type > 0;
            if (type == 2) //目前自摸情况下,会把胡的那张牌从手牌中带回来,这里删掉。目前只有一个胡牌,所以这么删,待扩展
            {
                handCards.Remove(huList[0]);
            }
            YxDebug.Log("手牌实际长度是:" + handCards.Count);

            #endregion

            #region UI

            LabelUserName.text = player.UserInfo.name;
            ZhuangSprite.SetActive(player.IsZhuang);
            LabelFanName.text = _fanName;
            YxTools.TrySetComponentValue(LabelHuScore, YxUtiles.GetShowNumber(_huNum).ToString());
            YxTools.TrySetComponentValue(LabelGangNum, YxUtiles.GetShowNumber(_gangNum).ToString());
            YxTools.TrySetComponentValue(LabelTotalScore, YxUtiles.GetShowNumber(_totalNum).ToString());
            HeadTexture.mainTexture = player.CurrentInfoPanel.UserIcon.mainTexture;
            player.UserInfo.Gold    = totalGold;
            player.CurrentInfoPanel.SetGold((int)totalGold);
            HuLogo.SetActive(IsWiner);

            #endregion

            _resultCards.Init(groups, handCards, huList, _isWiner);
            LabelFanName.ProcessText();
            NGUIText.Update();
        }
Beispiel #13
0
    public void AutoCombo(int index, TileComboDef def, int flag)
    {
        Debug.Log("auto combo " + index + "     flag:" + flag);
        MahjongPlayer player = _playPlayers [index];

        GameClient.Instance.MG.GetPlayer(def.Index).RemoveLastPlayed();
        if (player == _self)
        {
            player.ResetPocketList();
            player.Combo(def);
            Debug.Log("after combo===========");
            Debug.Log(player.Proxy.ToString());
            return;
        }

        switch (def.Combo)
        {
        case TileDef.ComboType.CHOW:
            break;

        case TileDef.ComboType.PONG:
            player.Proxy.RemovePocketList(2);
            break;

        case TileDef.ComboType.KONG:
            player.Proxy.RemovePocketList(3);
            break;

        case TileDef.ComboType.KONG_DARK:
            player.Proxy.RemovePocketList(4);
            break;

        case TileDef.ComboType.KONG_TURN:
            player.Proxy.RemovePocketList(1);
            break;
        }

        player.ResetPocketList();
        player.Combo(def);
        Debug.Log("after combo===========");
        Debug.Log(player.Proxy.ToString());
    }
Beispiel #14
0
    public void SetPocketCount(int index, int num)
    {
        MahjongPlayer player = _playPlayers [index];

        if (player != _self)
        {
            if (player.Proxy.PocketList.Count > num)
            {
                int count = player.Proxy.PocketList.Count - num;
                player.Proxy.RemovePocketList(count);
            }
            else if (player.Proxy.PocketList.Count < num)
            {
                for (int i = 0; i < (num - player.Proxy.PocketList.Count); ++i)
                {
                    player.Proxy.PocketList.Add(TileDef.Create());
                }
            }
        }
    }
 /// <summary>
 /// 当要显示 combo 的动画效果时调用
 /// </summary>
 public void ShowComboEffect(TileDef.ComboType type, MahjongPlayer player)
 {
     /*
      * if (!OpenViewRoot ())
      *      return;
      *
      * // 如果没有对应的 efffect 忽略
      * UIControllerAnimation.Type animType;
      * if (!_comboAnima.TryGetValue (type, out animType))
      *      return;
      *
      * if (player == null || GameClient.Instance == null || GameClient.Instance.gameMode == null)
      *      return;
      *
      * MahjongGame game = GameClient.Instance.gameMode as MahjongGame;
      * int displayIndex = game.GetPlayerDisplayIndex (player);
      *
      * UIControllerAnimation.Instance.Play (animType, player);
      */
 }
Beispiel #16
0
        /// <summary>
        /// Copies the data in the given player into this one.
        /// </summary>
        /// <param name="mp">The player data to copy.</param>
        public void CopyData(MahjongPlayer mp)
        {
            Score          = mp.Score;
            SeatWind       = mp.SeatWind;
            PrevailingWind = mp.PrevailingWind;

            while (BonusTiles.CardsInHand > 0)
            {
                BonusTiles.PlayCard(0);
            }

            Melds.Clear();

            foreach (MahjongMeld meld in mp.Melds)
            {
                Melds.Add(meld.Clone());
            }

            BonusTiles.DrawCards(mp.BonusTiles.Cards);
            return;
        }
Beispiel #17
0
        /// <summary>
        /// Determines the next move for this AI to make.
        /// </summary>
        /// <param name="state">The state of the game. This will be cloned so that the AI does not affect the actual game state.</param>
        /// <returns>Returns the next move to make based on the current game state.</returns>
        public MahjongMove GetNextMove(GameState <MahjongMove> state)
        {
            MahjongGameState s  = state as MahjongGameState;
            MahjongAIPlayer  ai = state.GetPlayer(Player) as MahjongAIPlayer;
            MahjongPlayer    mp = ai as MahjongPlayer;

            // Pass if it's not this AI's turn
            if (s.ActivePlayer != Player)
            {
                return(new MahjongMove());
            }

            if (MahjongStaticFunctions.HasMahjong(ai.CardsInHand, mp.Melds))
            {
                return(new MahjongMove(true));
            }

            // Pick a random tile to discard
            int r = rand.Next(0, (int)ai.CardsInHand.CardsInHand);

            rc++;

            return(new MahjongMove(ai.CardsInHand.Cards[r]));
        }
Beispiel #18
0
    public void SetPlayList(int index, List <TileDef> list)
    {
        MahjongPlayer player = _playPlayers [index];

        player.Proxy.PlayList = list;
    }
Beispiel #19
0
        /// <summary>
        /// Initialises a hand but otherwise leaves all data untouched.
        /// Assumes that the hand and bonus hand values are already appropriately assigned.
        /// </summary>
        protected void InitHand()
        {
            // State variables
            AvailableTile = null;
            OnReplacement = 0;

            Heavenly = true;
            Earthly  = true;

            HandFinished = true;

            // Resets
            ResetMoves();
            Deck.Reset();

            // Deal each player a new hand
            MahjongPlayer[] mp = new MahjongPlayer[4];

            for (int i = 0; i < 4; i++)
            {
                mp[i] = players[i] as MahjongPlayer;

                // Discard old cards
                while (players[i].CardsInHand.CardsInHand > 0)
                {
                    players[i].CardsInHand.PlayCard(0);
                }

                while (mp[i].BonusTiles.CardsInHand > 0)
                {
                    mp[i].BonusTiles.PlayCard(0);
                }

                mp[i].Melds.Clear();

                // Draw the initial thireen tiles
                players[i].CardsInHand.DrawCards(Deck.Draw(13));

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

                // Set the new seat winds and prevailing wind
                mp[i].SeatWind       = PlayerToWind(i);           // We do have that rotate wind function, but we don't know if this is a bonus hand or not, so let's not chance it
                mp[i].PrevailingWind = PrevailingWind;
            }

            // Set the active player to be east
            for (int i = 0; i < 4; i++)
            {
                if (mp[i].SeatWind == SuitIdentifier.EAST_WIND)
                {
                    ActivePlayer    = i;
                    SubActivePlayer = i;

                    break;
                }
            }

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

            return;
        }
Beispiel #20
0
        /// <summary>
        ///     其它玩家加入游戏
        /// </summary>
        /// <param name="user"></param>
        public void OnJoinGame(UserData user)
        {
            var           sit      = user.Seat;
            var           ShowSeat = GetShowSeat(sit);
            MahjongPlayer player   = null;

            switch (PlayerNumber)
            {
            case 2:
                player = OppsetPlayer.JoinGame(user);
                break;

            case 3:
                switch (ShowSeat)
                {
                case 1:
                    player = RightPlayer.JoinGame(user);
                    break;

                case 2:
                    player = LeftPlayer.JoinGame(user);
                    break;
                }
                break;

            case 4:
                switch (ShowSeat)
                {
                case 1:
                    player = RightPlayer.JoinGame(user);
                    break;

                case 2:
                    player = OppsetPlayer.JoinGame(user);
                    break;

                case 3:
                    player = LeftPlayer.JoinGame(user);
                    break;
                }
                break;

            default:
                player = null;
                break;
            }
            if (!IsGameing())
            {
                player.Reset();
            }
            var playerNumber = Data.UserDatas.Count;

            if (playerNumber == Data.PlayerNum)
            {
                if (IsInit())
                {
                    GameTotalState = TotalState.Waiting;
                }
            }
            else
            {
                YxDebug.Log(string.Format("人数不满足条件,当前的游戏状态是:{0},人数是{1}", gameState, playerNumber));
            }
        }
Beispiel #21
0
        /// <summary>
        /// Determines the next move for this AI to make.
        /// </summary>
        /// <param name="state">The state of the game. This will be cloned so that the AI does not affect the actual game state.</param>
        /// <returns>Returns the next move to make based on the current game state.</returns>
        public MahjongMove GetNextMove(GameState <MahjongMove> state)
        {
            MahjongGameState s  = state as MahjongGameState;
            MahjongAIPlayer  ai = state.GetPlayer(Player) as MahjongAIPlayer;
            MahjongPlayer    mp = ai as MahjongPlayer;

            // Pass if it's not this AI's turn and it can't meld a pung or kong
            if (s.ActivePlayer != Player)
            {
                if (s.AvailableTile == null)
                {
                    return(new MahjongMove()); // The active player is going out, so there's nothing we can do
                }
                else
                {
                    switch (ai.CardsInHand.CountCard(s.AvailableTile))
                    {
                    case 1:
                        // If this is the last tile we needed to declare mahjong, go for it
                        if (ai.CardsInHand.CardsInHand == 1)
                        {
                            List <Card> eye = new List <Card>();
                            eye.Add(s.AvailableTile.Clone());
                            eye.Add(s.AvailableTile.Clone());

                            return(new MahjongMove(new MahjongMeld(eye, false), s.AvailableTile, true));
                        }

                        // Pass otherwise
                        return(new MahjongMove());

                    case 2:
                        List <Card> p2 = new List <Card>();
                        p2.Add(s.AvailableTile.Clone());
                        p2.Add(s.AvailableTile.Clone());
                        p2.Add(s.AvailableTile.Clone());

                        Hand htemp2 = new StandardHand(ai.CardsInHand.Cards);
                        htemp2.PlayCard(s.AvailableTile);
                        htemp2.PlayCard(s.AvailableTile);

                        MahjongMeld        m2     = new MahjongMeld(p2, false);
                        List <MahjongMeld> melds2 = new List <MahjongMeld>();

                        foreach (MahjongMeld m22 in mp.Melds)
                        {
                            melds2.Add(m22.Clone());
                        }

                        return(new MahjongMove(m2, s.AvailableTile, MahjongStaticFunctions.HasMahjong(htemp2, melds2)));

                    case 3:
                        List <Card> p3 = new List <Card>();
                        p3.Add(s.AvailableTile.Clone());
                        p3.Add(s.AvailableTile.Clone());
                        p3.Add(s.AvailableTile.Clone());
                        p3.Add(s.AvailableTile.Clone());

                        Hand htemp3 = new StandardHand(ai.CardsInHand.Cards);
                        htemp3.PlayCard(s.AvailableTile);
                        htemp3.PlayCard(s.AvailableTile);
                        htemp3.PlayCard(s.AvailableTile);

                        MahjongMeld        m3     = new MahjongMeld(p3, false);
                        List <MahjongMeld> melds3 = new List <MahjongMeld>();

                        foreach (MahjongMeld m33 in mp.Melds)
                        {
                            melds3.Add(m33.Clone());
                        }

                        return(new MahjongMove(m3, s.AvailableTile, MahjongStaticFunctions.HasMahjong(htemp3, melds3)));

                    default:
                        return(new MahjongMove());    // If we naturally drew a kong, it'll stick around until we're forced to discard one of the tiles or just lose
                    }
                }
            }

            // If it's our turn, check if we have mahjong
            if (MahjongStaticFunctions.HasMahjong(ai.CardsInHand, mp.Melds))
            {
                return(new MahjongMove(true));
            }

            // Find all the singletons
            List <int> singletons = new List <int>();

            for (int i = 0; i < ai.CardsInHand.CardsInHand; i++)
            {
                if (ai.CardsInHand.CountCard(ai.CardsInHand.Cards[i]) == 1)
                {
                    singletons.Add(i);
                }
            }

            // If we don't have a singleton tile, we'll have to part with another
            if (singletons.Count == 0)
            {
                singletons.Add(rand.Next(0, (int)ai.CardsInHand.CardsInHand));
                rc++;
            }

            // Pick a random singleton tile to discard
            int r = rand.Next(0, singletons.Count);

            rc++;

            return(new MahjongMove(ai.CardsInHand.Cards[r]));
        }
Beispiel #22
0
    public void ShowPocketList(int index)
    {
        MahjongPlayer player = _playPlayers [index];

        player.ShowPocketList();
    }
Beispiel #23
0
    public override bool Enter()
    {
        _shuffle_initpocket_state = -1;

        poolMahjongRes = PoolManager.Pools ["mahjongres"];

        _pile = gameObject.AddComponent <MahjongPile> ();

        _slot         = GameObject.Find("slot").transform;
        _slotOriginal = _slot.transform.position;

        var go = new GameObject("self");

        _self       = go.AddComponent <MahjongUserPlayer> ();
        _self.Proxy = GameClient.Instance.MahjongGamePlayer;
        go          = new GameObject("left");
        _left       = go.AddComponent <MahjongPlayer> ();
        go          = new GameObject("front");
        _front      = go.AddComponent <MahjongPlayer> ();
        go          = new GameObject("right");
        _right      = go.AddComponent <MahjongPlayer> ();

        //_self.ResPool = poolMahjongRes;
        //_left.ResPool = poolMahjongRes;
        //_front.ResPool = poolMahjongRes;
        //_right.ResPool = poolMahjongRes;

        _players = new List <MahjongPlayer> ();
        _players.Add(_self);
        _players.Add(_right);
        _players.Add(_front);
        _players.Add(_left);

        /*
         * if (GamePlayer._PlayedList != null) {
         *      GamePlayer._PlayedList.Clear ();
         * }
         */
        go = GameObject.Find("MyShowPocketLocator");
        go.GetComponent <MeshRenderer>().enabled = false;
        _self.MyShowPocketLocator = go.transform;
        go = GameObject.Find("MyPocketLocator");
        go.GetComponent <MeshRenderer>().enabled = false;

        string[][] locators = new string[4][] {
            new string[] { "mahjong", "MyPlayLocator", "MyStackLocator", "MyComboLocator", "MyWinLocator", "MyExchangeLocator" },
            new string[] { "RightPocketLocator", "RightPlayLocator", "RightStackLocator", "RightComboLocator", "RightWinLocator", "RightExchangeLocator" },
            new string[] { "FrontPocketLocator", "FrontPlayLocator", "FrontStackLocator", "FrontComboLocator", "FrontWinLocator", "FrontExchangeLocator" },
            new string[] { "LeftPocketLocator", "LeftPlayLocator", "LeftStackLocator", "LeftComboLocator", "LeftWinLocator", "LeftExchangeLocator" },
        };

        Vector3[] direction = new Vector3[] { Vector3.right, Vector3.forward, Vector3.left, -Vector3.forward };
        for (int i = 0; i < 4; ++i)
        {
            _players [i].InitLocator(locators [i]);
            _players [i].InitDirection(direction [i]);
        }

        ArrangePlayer(_self.Proxy.Index, 4);

        // set user pick up pai camera
        //go = GameObject.Find("OCamera169");
        //EasyTouch.AddCamera (go.GetComponent<Camera>());

        //registerOperationTable ();

        //OnRefresh ();

        return(true);
    }
Beispiel #24
0
        /// <summary>
        /// Returns an enumerator of the possible moves at the given state.
        /// </summary>
        /// <param name="state">The state to enumerate the moves of.</param>
        private IEnumerator <MahjongMove> GetMoveEnumerator(MahjongGameState state)
        {
            List <MahjongMove> moves = new List <MahjongMove>();

            // If the hand is done (or the game), then there's nothing left to enumerate.
            if (state.HandFinished || state.GameFinished)
            {
                return(moves.GetEnumerator());
            }

            // Get the player we're considering
            MahjongAIPlayer ai = state.GetPlayer(state.SubActivePlayer) as MahjongAIPlayer;
            MahjongPlayer   mp = ai as MahjongPlayer;

            // The active player has different choices available than the responding players
            if (state.ActivePlayer == state.SubActivePlayer)
            {
                // Add the kongs first
                foreach (Card c in ai.CardsInHand.Cards)
                {
                    if (!ContainsKong(moves, c) && ai.CardsInHand.CountCard(c) == 4)
                    {
                        List <Card> meld = new List <Card>();

                        for (int i = 0; i < 4; i++)
                        {
                            meld.Add(c.Clone());
                        }

                        moves.Add(new MahjongMove(new MahjongMeld(meld, true), c));                       // We're melding a kong, so mahjong is definitely false here
                    }
                }

                // We can also meld a fourth tile into an existing pung
                foreach (MahjongMeld meld in mp.Melds)
                {
                    if (meld.Pung && ai.CardsInHand.Cards.Contains(meld.Cards[0]))
                    {
                        List <Card> n_meld = new List <Card>();

                        for (int i = 0; i < 4; i++)
                        {
                            n_meld.Add(meld.Cards[0].Clone());
                        }

                        moves.Add(new MahjongMove(new MahjongMeld(n_meld, false), meld.Cards[0]));                       // We're melding a kong, so mahjong is definitely false here
                    }
                }

                // Add all of the discards next
                foreach (Card c in ai.CardsInHand.Cards)
                {
                    moves.Add(new MahjongMove(c));
                }

                // Lastly, we'll add the ability to declare mahjong
                if (MahjongStaticFunctions.HasMahjong(ai.CardsInHand, mp.Melds))
                {
                    moves.Add(new MahjongMove(true));
                }
            }
            else
            {
                // We need a tile available to do anything but pass (there are a few cases were this would not be available)
                if (state.AvailableTile != null)
                {
                    // First, add chow moves if we can
                    if (state.SubActivePlayer == state.NextPlayer)
                    {
                        List <MahjongMeld> chows = GetChows(ai.CardsInHand, state.AvailableTile);

                        foreach (MahjongMeld m in chows)
                        {
                            Hand h; List <MahjongMeld> melds;
                            CreateDuplicateMinusMeld(ai.CardsInHand, mp.Melds, m, state.AvailableTile, out h, out melds);

                            moves.Add(new MahjongMove(m, state.AvailableTile, MahjongStaticFunctions.HasMahjong(h, melds)));
                        }
                    }

                    // Add the ability to meld pungs and kongs
                    int count = ai.CardsInHand.CountCard(state.AvailableTile);                     // We'll use this again after pung/kong checks, so this is extra fine to keep around

                    if (count > 1)
                    {
                        // First, pungs are always possible
                        List <Card> cards = new List <Card>();

                        cards.Add(state.AvailableTile.Clone());
                        cards.Add(state.AvailableTile.Clone());
                        cards.Add(state.AvailableTile.Clone());

                        MahjongMeld m = new MahjongMeld(cards);

                        Hand h; List <MahjongMeld> melds;
                        CreateDuplicateMinusMeld(ai.CardsInHand, mp.Melds, m, state.AvailableTile, out h, out melds);

                        moves.Add(new MahjongMove(m, state.AvailableTile, MahjongStaticFunctions.HasMahjong(h, melds)));

                        // Now create a kong move if possible
                        if (count > 2)
                        {
                            cards.Add(state.AvailableTile.Clone());

                            m = new MahjongMeld(cards);
                            CreateDuplicateMinusMeld(ai.CardsInHand, mp.Melds, m, state.AvailableTile, out h, out melds);

                            moves.Add(new MahjongMove(m, state.AvailableTile, MahjongStaticFunctions.HasMahjong(h, melds)));
                        }
                    }

                    // Now add the ability to declare mahjong through non-standard means
                    // Nine gates can only be won on a self pick, so let's deal with thirteen orphans and seven pair first
                    Hand htemp = new StandardHand(ai.CardsInHand.Cards);
                    htemp.DrawCard(state.AvailableTile.Clone());

                    MahjongMeld mtemp = new MahjongMeld(htemp.Cards);

                    if (mtemp.SevenPair || mtemp.ThirteenOrphans)
                    {
                        moves.Add(new MahjongMove(mtemp, state.AvailableTile, true));
                    }

                    // The last mahjong we need to check now is if we can form an eye and win
                    if (count > 0)
                    {
                        List <Card> cards = new List <Card>();

                        cards.Add(state.AvailableTile.Clone());
                        cards.Add(state.AvailableTile.Clone());

                        MahjongMeld m = new MahjongMeld(cards);

                        Hand h; List <MahjongMeld> melds;
                        CreateDuplicateMinusMeld(ai.CardsInHand, mp.Melds, m, state.AvailableTile, out h, out melds);

                        if (MahjongStaticFunctions.HasMahjong(h, melds))
                        {
                            moves.Add(new MahjongMove(m, state.AvailableTile, true));
                        }
                    }
                }

                // Lastly, add the simple pass option
                moves.Add(new MahjongMove());
            }

            return(moves.GetEnumerator());
        }
Beispiel #25
0
    public void UpdatePocketList(int index, bool lastGap = false)
    {
        MahjongPlayer player = _playPlayers [index];

        player.ResetPocketList(lastGap);
    }