Esempio n. 1
0
        /// <summary>
        /// プレイヤー2人について、カードを出すパターンを順列で全て列挙して、
        /// 全組み合わせで限定ジャンケンを行い、結果を保存する。
        /// </summary>
        /// <param name="defPlayerA">プレイヤーAの対戦前の情報</param>
        /// <param name="defPlayerB">プレイヤーBの対戦前の情報</param>
        public void BattleAllPattern(Player defPlayerA, Player defPlayerB)
        {
            if (this.playerList.Count < 2) return;

            this.battleScoreList = new List<BattleScore>();

            // 対戦数がプレイヤーのジャンケンカード数より大きい場合は、
            // 対戦数をプレイヤーのジャンケンカード数へ合わせる
            if (defPlayerA.CardList.Length < this.BattleNum ||
                defPlayerB.CardList.Length < this.BattleNum)
            {
                this.BattleNum = defPlayerA.CardList.Length < defPlayerB.CardList.Length
                    ? defPlayerA.CardList.Length : defPlayerB.CardList.Length;
            }

            // カードを出すパターンを順列で生成
            Permutation permA = new Permutation(defPlayerA.CardList);
            permA.GeneratePermutation(this.BattleNum);
            Permutation permB = new Permutation(defPlayerB.CardList);
            permB.GeneratePermutation(this.BattleNum);

            // 順列で生成したカードを出すパターンを全て標準出力
            //permA.PrintPermList();
            //permB.PrintPermList();

            // 生成したパターンについて、全組み合わせで限定ジャンケンを実行
            IEnumerator<List<string>> cardListA = permA.Enumerate();
            while (cardListA.MoveNext())
            {
                List<string> patternA = cardListA.Current;
                IEnumerator<List<string>> cardListB = permB.Enumerate();
                while (cardListB.MoveNext())
                {
                    List<string> patternB = cardListB.Current;

                    BattleScore battleScore = new BattleScore();
                    Player playerA = defPlayerA.DeepCopyTo();
                    Player playerB = defPlayerB.DeepCopyTo();
                    for (int i = 0; i < patternA.Count || i < patternB.Count; ++i)
                    {
                        JankenResult resultA = new JankenResult(patternA[i]);
                        JankenResult resultB = new JankenResult(patternB[i]);
                        resultA.Result = this.Judge(resultA.Card, resultB.Card);    // 勝敗を判定
                        playerA.PopCard(resultA.Card);  // 出したジャンケンカードを削除
                        playerB.PopCard(resultB.Card);  // 出したジャンケンカードを削除
                        // プレイヤーAが勝った時
                        if (resultA.Result == Result.Win)
                        {
                            resultB.Result = Result.Lose;
                            playerA.PushStar();
                            playerB.PopStar();
                        }
                        // プレイヤーAが負けた時(プレイヤーBが勝ち)
                        else if (resultA.Result == Result.Lose)
                        {
                            resultB.Result = Result.Win;
                            playerA.PopStar();
                            playerB.PushStar();
                        }
                        // あいこの時
                        else if (resultA.Result == Result.Even)
                        {
                            resultB.Result = Result.Even;
                        }
                        // 対戦結果を保存
                        playerA.AddJankenResult(resultA);
                        playerB.AddJankenResult(resultB);

                    }
                    // 全対戦結果を保存
                    battleScore.AddPlayerSituation(playerA);
                    battleScore.AddPlayerSituation(playerB);
                    this.battleScoreList.Add(battleScore);
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 対戦時に出したジャンケンカードと結果を保存
 /// </summary>
 /// <param name="result">ジャンケン結果</param>
 public void AddJankenResult(JankenResult result)
 {
     this.resultList.Add(result);
 }