public override int GetAddMethod(int[] nums) { Console.WriteLine($"Your Num is {nums[0]} {nums[1]}"); Console.WriteLine($"His Num is {nums[2]} {nums[3]}"); Console.WriteLine("Please Input 0 0+=2 1 1+=2 2 0+=3 3 1+=3"); for (int i = 0; i < 4; i++) { if (GCase.IsVaildAddMethod(nums, i)) { GCase gCase = new GCase(); for (int j = 0; j < 4; j++) { gCase.Nums[j] = nums[j]; } gCase.RunMethod(i); Console.WriteLine($"{i} {gCase}"); } } while (true) { string s = Console.ReadLine(); int.TryParse(s, out int method); if (GCase.IsVaildAddMethod(nums, method)) { return(method); } else { Console.WriteLine("You input illegal method, please input mmethod again!"); } } }
public override int GetAddMethod(int[] nums) { if (nums.Length != 4) { throw new Exception("nums长度不为4"); } string gcase = ""; foreach (var num in nums) { gcase += num.ToString(); } int method = -1;//最大胜率对应的方法 foreach (var record in Records.rs) { if (record.GCase == gcase) { GameLog($"case={record}"); double maxWinPercentage = 0;//4种方法中的最大胜率 for (int i = 0; i < 4; i++) { int sum = 0; for (int j = 0; j < 3; j++) { sum += record.Nums[i * 3 + j]; } if (sum != 0) { double winPercentage = (double)record.Nums[i * 3] / sum; GameLog($"method{i} {winPercentage}"); if (winPercentage > maxWinPercentage) { maxWinPercentage = winPercentage; method = i; } } } } } GameLog(method); if (method != -1) { return(method); } else { while (true)//无法确定时,随机选择 { int r = random.Next(0, 4); if (GCase.IsVaildAddMethod(nums, r)) { return(r); } } } }
public override int GetAddMethod(int[] nums) { if (nums.Length != 4) { throw new Exception("nums长度不为4"); } while (true) { int r = random.Next(0, 4); if (GCase.IsVaildAddMethod(nums, r)) { return(r); } } }
public override int GetAddMethod(int[] nums) { if (nums.Length != 4) { throw new ArgumentException(); } Dictionary <int, string> next = new Dictionary <int, string>(); for (int i = 0; i < 4; i++) { GCase current = new GCase(); for (int j = 0; j < 4; j++) { current.Nums[j] = nums[j]; } if (GCase.IsVaildAddMethod(nums, i)) { current.RunMethod(i); current.Reserve(); string s = ""; foreach (var c in current.Nums) { s += c; } next.Add(i, s); } } foreach (var item in next) { GameLog(item); } int result = -1; //如果下一步是对手的必败策略,则这一步是自己的必胜策略 foreach (var item in next) { string value = item.Value; string newValue = $"{value[1]}{value[0]}{value[3]}{value[2]}"; if (fail.Contains(newValue)) { GameLog($"Found {item.Key} {item.Value} SUCCESS"); result = item.Key; break; } } //如果下一步是对手的必胜策略,则这一步是自己的必败策略 //如果没有自己的必胜策略,则选择不是必败的策略 foreach (var item in next) { string value = item.Value; string newValue = $"{value[1]}{value[0]}{value[3]}{value[2]}"; if (success.Contains(newValue)) { GameLog($"Found {item.Key} {item.Value} FAIL"); } else { result = item.Key; break; } } if (result == -1) { GameLog("必败!!!"); result = 0; } return(result); }