예제 #1
0
    protected virtual void thinkSutehai(Hai addHai)
    {
        _action.SutehaiIndex = Tehai.getJyunTehaiCount();

        Tehai tehaiCopy = new Tehai(Tehai);

        FormatWorker.setCounterFormat(tehaiCopy, null);
        int maxScore = getCountFormatScore(FormatWorker);

        for (int i = 0; i < tehaiCopy.getJyunTehaiCount(); i++)
        {
            Hai hai = tehaiCopy.removeJyunTehaiAt(i);

            FormatWorker.setCounterFormat(tehaiCopy, addHai);

            int score = getCountFormatScore(FormatWorker);
            if (score > maxScore)
            {
                maxScore             = score;
                _action.SutehaiIndex = i;
            }

            tehaiCopy.insertJyunTehai(i, hai);
        }
    }
예제 #2
0
    protected virtual void thinkSelectSuteHai()
    {
        thinkSutehai(null);

        if (_action.SutehaiIndex == Tehai.getJyunTehaiCount())
        {
            _action.SutehaiIndex = Utils.GetRandomNum(0, Tehai.getJyunTehaiCount());
        }
    }
예제 #3
0
    public bool CheckHaiTypeOver9(Tehai tehai, Hai addHai)
    {
        if (!_game.isChiHou)
        {
            return(false);
        }

        if (tehai.getJyunTehaiCount() < Tehai.JYUN_TEHAI_LENGTH_MAX - 1)
        {
            return(false);
        }


        int[] checkId =
        {
            Hai.ID_WAN_1, Hai.ID_WAN_9, Hai.ID_PIN_1, Hai.ID_PIN_9, Hai.ID_SOU_1, Hai.ID_SOU_9,
            Hai.ID_TON,   Hai.ID_NAN,   Hai.ID_SYA,   Hai.ID_PE,    Hai.ID_HAKU,  Hai.ID_HATSU, Hai.ID_CHUN
        };
        int[] countNumber = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; //length = 13

        //手牌をコピーする
        Hai[] checkHais = tehai.getJyunTehai();

        for (int i = 0; i < checkHais.Length; i++)
        {
            for (int j = 0; j < checkId.Length; j++)
            {
                if (checkHais[i].ID == checkId[j])
                {
                    countNumber[j]++;
                }
            }
        }

        for (int j = 0; j < checkId.Length; j++)
        {
            if (addHai.ID == checkId[j])
            {
                countNumber[j]++;
            }
        }

        int totalHaiType = 0;

        for (int c = 0; c < countNumber.Length; c++)
        {
            if (countNumber[c] > 0)
            {
                totalHaiType++;
            }
        }

        return(totalHaiType >= 9);
    }
예제 #4
0
    protected override EResponse OnHandle_TsumoHai(EKaze fromPlayerKaze, Hai haiToHandle)
    {
        _action.Reset();

        if (inTest)
        {
            _action.SutehaiIndex = Tehai.getJyunTehaiCount();
            return(DoResponse(EResponse.SuteHai));
        }

        Hai tsumoHai = haiToHandle;

        // ツモあがりの場合は、イベント(ツモあがり)を返す。
        int agariScore = MahjongAgent.getAgariScore(Tehai, tsumoHai, JiKaze);

        if (agariScore > 0)
        {
            if (GameSettings.AllowFuriten || !isFuriten())
            {
                return(DoResponse(EResponse.Tsumo_Agari));
            }
            else
            {
                Utils.LogWarningFormat("AI {0} is enable tsumo but furiten...", JiKaze.ToString());
            }
        }

        // 九种九牌check
        if (MahjongAgent.CheckHaiTypeOver9(Tehai, tsumoHai))
        {
            return(DoResponse(EResponse.Nagashi));
        }

        // リーチの場合は、ツモ切りする
        if (MahjongAgent.isReach(JiKaze))
        {
            _action.SutehaiIndex = Tehai.getJyunTehaiCount();

            return(DoResponse(EResponse.SuteHai));
        }

        // check enable Reach
        if (CheckReachPreConditions() == true)
        {
            List <int> reachHaiIndexList;
            if (MahjongAgent.tryGetReachHaiIndex(Tehai, tsumoHai, out reachHaiIndexList))
            {
                _action.IsValidReach      = true;
                _action.ReachHaiIndexList = reachHaiIndexList;

                thinkReach();

                return(DoResponse(EResponse.Reach));
            }
        }

        // 制限事項。リーチ後のカンをさせない
        if (!MahjongAgent.isReach(JiKaze))
        {
            /*
             * if( MahjongAgent.getTotalKanCount() < GameSettings.KanCountMax )
             * {
             *  // TODO: tsumo kans
             *  List<Hai> kanHais = new List<Hai>();
             *  if( Tehai.validAnyTsumoKan(tsumoHai, kanHais) )
             *  {
             *      _action.setValidTsumoKan(true, kanHais);
             *
             *  }
             * }
             */
        }
        else
        {
            if (MahjongAgent.getTotalKanCount() < GameSettings.KanCountMax)
            {
                // if player machi hais won't change after setting AnKan, enable to to it.
                if (Tehai.validAnKan(tsumoHai))
                {
                    List <Hai> machiHais;
                    if (MahjongAgent.tryGetMachiHais(Tehai, out machiHais))
                    {
                        Tehai tehaiCopy = new Tehai(Tehai);
                        tehaiCopy.setAnKan(tsumoHai);
                        tehaiCopy.Sort();

                        List <Hai> newMachiHais;

                        if (MahjongAgent.tryGetMachiHais(tehaiCopy, out newMachiHais))
                        {
                            if (machiHais.Count == newMachiHais.Count)
                            {
                                machiHais.Sort(Tehai.Compare);
                                newMachiHais.Sort(Tehai.Compare);

                                bool enableAnkan = true;

                                for (int i = 0; i < machiHais.Count; i++)
                                {
                                    if (machiHais[i].ID != newMachiHais[i].ID)
                                    {
                                        enableAnkan = false;
                                        break;
                                    }
                                }

                                if (enableAnkan == true)
                                {
                                    _action.setValidTsumoKan(true, new List <Hai>()
                                    {
                                        tsumoHai
                                    });
                                    return(DoResponse(EResponse.Ankan));
                                }
                            }
                        }
                    }
                }
            }

            // can Ron or Ankan, sute hai automatically.
            _action.SutehaiIndex = Tehai.getJyunTehaiCount(); // sute the tsumo hai on Reach

            return(DoResponse(EResponse.SuteHai));
        }


        thinkSutehai(tsumoHai);

        return(DoResponse(EResponse.SuteHai));
    }
예제 #5
0
    protected override EResponse OnHandle_TsumoHai(EKaze fromPlayerKaze, Hai haiToHandle)
    {
        _action.Reset();
        _action.State = EActionState.Select_Sutehai;

        if (inTest)
        {
            //_action.State = EActionState.Select_Sutehai;
            //return DisplayMenuList();
        }

        // 手牌をコピーする。
        Hai tsumoHai = haiToHandle;

        // check enable Tsumo
        int agariScore = MahjongAgent.getAgariScore(Tehai, tsumoHai, JiKaze);

        if (agariScore > 0)
        {
            if (GameSettings.AllowFuriten || !isFuriten())
            {
                _action.IsValidTsumo = true;
                _action.MenuList.Add(EActionType.Tsumo);

                if (MahjongAgent.isReach(JiKaze))
                {
                    return(DisplayMenuList());
                }
            }
            else
            {
                Utils.LogWarningFormat("Player {0} is enable tsumo but furiten...", JiKaze.ToString());
            }
        }

        // 九种九牌check
        if (MahjongAgent.CheckHaiTypeOver9(Tehai, tsumoHai))
        {
            _action.MenuList.Add(EActionType.RyuuKyoku);
        }

        // check enable Reach
        if (CheckReachPreConditions() == true)
        {
            List <int> reachHaiIndexList;
            if (MahjongAgent.tryGetReachHaiIndex(Tehai, tsumoHai, out reachHaiIndexList))
            {
                _action.IsValidReach      = true;
                _action.ReachHaiIndexList = reachHaiIndexList;
                _action.MenuList.Add(EActionType.Reach);
            }
        }

        // 制限事項。リーチ後のカンをさせない
        if (!MahjongAgent.isReach(JiKaze))
        {
            if (MahjongAgent.getTotalKanCount() < GameSettings.KanCountMax)
            {
                // tsumo kans
                List <Hai> kanHais = new List <Hai>();
                if (Tehai.validAnyTsumoKan(tsumoHai, kanHais))
                {
                    _action.setValidTsumoKan(true, kanHais);

                    _action.MenuList.Add(EActionType.Kan);
                }
            }
        }
        else
        {
            if (MahjongAgent.getTotalKanCount() < GameSettings.KanCountMax)
            {
                // if player machi hais won't change after setting AnKan, enable to to it.
                if (Tehai.validAnKan(tsumoHai))
                {
                    List <Hai> machiHais;
                    if (MahjongAgent.tryGetMachiHais(Tehai, out machiHais))
                    {
                        Tehai tehaiCopy = new Tehai(Tehai);
                        tehaiCopy.setAnKan(tsumoHai);
                        tehaiCopy.Sort();

                        List <Hai> newMachiHais;

                        if (MahjongAgent.tryGetMachiHais(tehaiCopy, out newMachiHais))
                        {
                            if (machiHais.Count == newMachiHais.Count)
                            {
                                machiHais.Sort(Tehai.Compare);
                                newMachiHais.Sort(Tehai.Compare);

                                bool enableAnkan = true;

                                for (int i = 0; i < machiHais.Count; i++)
                                {
                                    if (machiHais[i].ID != newMachiHais[i].ID)
                                    {
                                        enableAnkan = false;
                                        break;
                                    }
                                }

                                if (enableAnkan == true)
                                {
                                    _action.setValidTsumoKan(true, new List <Hai>()
                                    {
                                        tsumoHai
                                    });

                                    _action.MenuList.Add(EActionType.Kan);
                                    _action.MenuList.Add(EActionType.Nagashi);

                                    _action.State = EActionState.Select_Kan;
                                }
                            }
                        }
                    }
                } // end if(valid ankan)
            }     // end kan count check

            // can Ron or Ankan, sute hai automatically.
            if (_action.MenuList.Count == 0)
            {
                _action.SutehaiIndex = Tehai.getJyunTehaiCount(); // sute the tsumo hai on Reach

                return(DoResponse(EResponse.SuteHai));
            }
        }

        // always display menu on pick tsumo hai.
        return(DisplayMenuList());
    }