/// <summary> /// 期待結果と同じか判定 /// </summary> /// <param name="expectedList">期待結果</param> /// <returns>true:同じ, false:違う</returns> public bool EqualsLastSituation(Player[] expectedList) { foreach (Player expected in expectedList) { if (!this.playerSituationList.Exists(x => x.EqualsCard(expected))) return false; } return true; }
/// <summary> /// プレイヤーの状態を追加 /// </summary> /// <param name="player">プレイヤーの状態</param> public void AddPlayerSituation(Player player) { this.playerSituationList.Add(player); }
/// <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); } } }
/// <summary> /// プレイヤー毎の手持ちのカード数の初期値と、 /// 期待結果をCSVファイルから読み込み /// </summary> /// <param name="path">CSVファイルのパス</param> public void ReadInput(string path) { if (!File.Exists(path)) throw new FileNotFoundException(path); this.playerList = new List<Player>(); this.expectedList = new List<Player>(); const string SituationPlayer = "default"; const string SituationExpected = "result"; string[] lines = File.ReadAllLines(path); for (int i = 1; i < lines.Length; ++i) { string[] data = lines[i].Split(','); if (data.Length < 6) continue; // プレイヤー情報を読み込み if (data[5] == SituationPlayer) { Player player = new Player(data[4], data[4].Replace("user_", "")); player.SetCard(int.Parse(data[1]), int.Parse(data[2]), int.Parse(data[3]), int.Parse(data[0])); this.playerList.Add(player); } // 期待結果を読み込み if (data[5] == SituationExpected) { Player player = new Player(data[4], data[4].Replace("user_", "")); player.SetCard(int.Parse(data[1]), int.Parse(data[2]), int.Parse(data[3]), int.Parse(data[0])); this.expectedList.Add(player); } } }
/// <summary> /// 手持ちのカードの枚数が、指定のプレイヤーの状態と同じか判定 /// </summary> /// <param name="player">プレイヤーの状態</param> /// <returns>true:同じ, false:違う</returns> public bool EqualsCard(Player player) { return this.GetCardNum(Master.CardStringGu) == player.GetCardNum(Master.CardStringGu) && this.GetCardNum(Master.CardStringTyoki) == player.GetCardNum(Master.CardStringTyoki) && this.GetCardNum(Master.CardStringPa) == player.GetCardNum(Master.CardStringPa) && this.Star == player.Star; }
/// <summary> /// プレイヤーの情報をディープコピー /// 但し、対戦結果はコピーしない /// </summary> /// <returns>プレイヤー</returns> public Player DeepCopyTo() { Player copy = new Player(this.Id, this.Name); copy.SetCard(this.cardList.Count(x => x == Master.CardStringGu), this.cardList.Count(x => x == Master.CardStringTyoki), this.cardList.Count(x => x == Master.CardStringPa), this.Star); return copy; }