public int WinGame(FlagMoveRule a) { int index = -1; index = a.GetIndexByPictureIndex(4); if (index == -1) { return(1); //表示蓝方胜 } index = -1; index = a.GetIndexByPictureIndex(27); if (index == -1) { return(2); //表示红方胜 } if (a.rednum == 0) { this.shanShuo = false; return(1); //蓝方胜 } if (a.bluenum == 0) { this.shanShuo = false; return(2); //红方胜 } return(0); }
public void JiangJun(Point fromPoint, Point toPoint, FlagMoveRule a) { b.Initialize(); this.AcceptValue(a); b.ChangeQiZi(fromPoint, toPoint); this.ChangeParameter(); }
public void SaveNewItem(int fromIndex, int toIndex, Point fromPoint, Point toPoint, string label3_Text, int signRight, bool start, string wrongString, bool whichFangQianZou, FlagMoveRule b) { if (IsReplayAndNoAddItem) { return; } if (this.activeIndex > this.tailIndex) { this.activeIndex = this.tailIndex; } this.activeIndex++; if (this.activeIndex == Length) { MessageBox.Show("悔旗类空间不够,应扩大空间"); return; } this.fromIndex[this.activeIndex] = fromIndex; this.toIndex[this.activeIndex] = toIndex; this.fromPoint[this.activeIndex] = fromPoint; this.toPoint[this.activeIndex] = toPoint; this.label3_Text[this.activeIndex] = label3_Text; this.signRight[this.activeIndex] = signRight; this.start[this.activeIndex] = start; this.wrongString[this.activeIndex] = wrongString; this.whichFangQianZou[this.activeIndex] = whichFangQianZou; FlagMoveRule tempFlagMoveRule = new FlagMoveRule(); tempFlagMoveRule.Initialize(); for (int i = 0; i < 90; i++) { tempFlagMoveRule.have[i] = b.have[i]; tempFlagMoveRule.who[i] = b.who[i]; tempFlagMoveRule.str[i] = b.str[i]; tempFlagMoveRule.allPoint[i] = b.allPoint[i]; if (i < 32) { tempFlagMoveRule.partPoint[i] = b.partPoint[i]; } tempFlagMoveRule.whichPicture[i] = b.whichPicture[i]; } tempFlagMoveRule.rednum = b.rednum; tempFlagMoveRule.bluenum = b.bluenum; tempFlagMoveRule.index = b.index; tempFlagMoveRule.first_X = b.first_X; tempFlagMoveRule.first_Y = b.first_Y; tempFlagMoveRule.height = b.height; tempFlagMoveRule.width = b.width; this.b[this.activeIndex] = tempFlagMoveRule; this.tailIndex = this.activeIndex; }
public Point Find_Down_Point(FlagMoveRule a, Point currentPoint) { Point p1 = a.GetNearPoint(currentPoint.X, currentPoint.Y); Point p2 = a.GetNextPoint(p1, 1, 0); if (p2.X != -1) { return(p2); } return(a.GetNextPoint(p1, -9, 0)); }
public Point Find_Right_Point(FlagMoveRule a, Point currentPoint) { Point p1 = a.GetNearPoint(currentPoint.X, currentPoint.Y); Point p2 = a.GetNextPoint(p1, 0, 1); if (p2.X != -1) { return(p2); } else { return(a.GetNextPoint(p1, 0, -8)); } }
public void ReFresh(FlagMoveRule a) { }
public int GoAhead(ref int fromIndex, ref int toIndex, ref Point fromPoint, ref Point toPoint, ref string label3_Text, ref int signRight, ref bool start, ref string wrongString, ref bool whichFangQianZou, ref FlagMoveRule b) { if (this.activeIndex >= this.tailIndex - 1) { return(0); //只能前进到最后一步旗 } this.activeIndex++; if (this.activeIndex < 0) { this.activeIndex = 0; } fromIndex = this.fromIndex[this.activeIndex]; toIndex = this.toIndex[this.activeIndex]; fromPoint = this.fromPoint[this.activeIndex]; toPoint = this.toPoint[this.activeIndex]; label3_Text = this.label3_Text[this.activeIndex + 1]; signRight = this.signRight[this.activeIndex + 1]; start = this.start[this.activeIndex + 1]; wrongString = this.wrongString[this.activeIndex + 1]; whichFangQianZou = this.whichFangQianZou[this.activeIndex + 1]; b.Initialize(); b.Initialize(this.b[this.activeIndex + 1]); return(1); }
public int FallBack(ref int fromIndex, ref int toIndex, ref Point fromPoint, ref Point toPoint, ref string label3_Text, ref int signRight, ref bool start, ref string wrongString, ref bool whichFangQianZou, ref FlagMoveRule b) { if (this.activeIndex < 0) { return(0); } if (this.activeIndex >= this.tailIndex) { this.activeIndex = this.tailIndex - 1; } if (this.activeIndex <= -1) //*******************防止一开始就点后退 { return(0); } fromIndex = this.fromIndex[this.activeIndex]; toIndex = this.toIndex[this.activeIndex]; fromPoint = this.fromPoint[this.activeIndex]; toPoint = this.toPoint[this.activeIndex]; label3_Text = this.label3_Text[this.activeIndex]; signRight = this.signRight[this.activeIndex]; start = this.start[this.activeIndex]; wrongString = this.wrongString[this.activeIndex]; whichFangQianZou = this.whichFangQianZou[this.activeIndex]; b.Initialize(); b.Initialize(this.b[this.activeIndex]); this.activeIndex--; return(1); }
public void ComputerAuto(FlagMoveRule a, JudgeWhichOneWiner jiangJun, ref Point fromPoint, ref Point toPoint) { b.Initialize(a); this.jiangJun.Inialize(jiangJun); //防守 Point shuaiPoint = new Point(-1, -1); shuaiPoint = b.CountPoint(b.GetIndexByPictureIndex(4)); if (this.jiangJun.ShuaiSymmetryJiang()) //如果将对帅,则直接吃掉将 { Point jiangPoint = new Point(-1, -1); jiangPoint = b.CountPoint(b.GetIndexByPictureIndex(27)); fromPoint = shuaiPoint; toPoint = jiangPoint; return; } //吃将 for (int i = 89; i >= 0; i--) { for (int j = 89; j >= 0; j--) { if (b.who[i] == "red" && b.AcceptJudge(b.allPoint[i], b.allPoint[j], false) && b.whichPicture[b.CountIndex(b.allPoint[j])] == 27) { fromPoint = b.allPoint[i]; toPoint = b.allPoint[j]; this.jiangJun.Inialize(jiangJun); this.jiangJun.JiangJun(b.allPoint[i], b.allPoint[j], b); if (fromPoint != toPoint && this.jiangJun.blueToRed == false) { Console.WriteLine("777777"); return; } } } } b.Initialize(a); this.jiangJun.Inialize(jiangJun); Point[] footShuaiPoint = new Point[5]; int footShuaiIndex = 0; Point[] sideShuaiPoint = new Point[20]; for (int i = 0; i < 90; i++) { if (b.who[i] == "blue" && b.AcceptJudge(b.allPoint[i], shuaiPoint, false)) { footShuaiPoint[footShuaiIndex++] = b.allPoint[i]; } } if (footShuaiIndex == 1) //红帅被将军,寻找有没有直接吃掉将帅的旗子的旗子 { for (int i = 0; i < 90; i++) { if (b.who[i] == "red" && b.AcceptJudge(b.allPoint[i], footShuaiPoint[0], false)) { fromPoint = b.allPoint[i]; toPoint = footShuaiPoint[0]; this.jiangJun.Inialize(jiangJun); this.jiangJun.JiangJun(b.allPoint[i], footShuaiPoint[0], b); if (fromPoint != toPoint && this.jiangJun.blueToRed == false) { Console.WriteLine("111111"); return; } } } } b.Initialize(a); this.jiangJun.Inialize(jiangJun); if (footShuaiIndex >= 1) //走自己非帅旗子,解除将军 { for (int i = 0; i < 90; i++) { for (int j = 0; j < 90; j++) { if (b.who[i] == "red" && b.AcceptJudge(b.allPoint[i], b.allPoint[j], false)) { this.jiangJun.Inialize(jiangJun); this.jiangJun.JiangJun(b.allPoint[i], b.allPoint[j], b); if (this.jiangJun.blueToRed == false) { fromPoint = b.allPoint[i]; toPoint = b.allPoint[j]; if (fromPoint != toPoint) { Console.WriteLine("333333"); return; } } } } } } b.Initialize(a); this.jiangJun.Inialize(jiangJun); Random random = new Random(); int num = random.Next(100); if (num % 2 == 1) { if (footShuaiIndex >= 1) { for (int i = 0; i < 30; i++) { this.jiangJun.Inialize(jiangJun); if (b.str[i] == "红士") { for (int j = 0; j < 30; j++) { if (b.AcceptJudge(b.allPoint[i], b.allPoint[j], false)) { this.jiangJun.JiangJun(b.allPoint[i], b.allPoint[j], b); if (this.jiangJun.blueToRed == false) { fromPoint = b.allPoint[i]; toPoint = b.allPoint[j]; Console.WriteLine("444444"); if (fromPoint != toPoint) { return; } } } } } } } } else { if (footShuaiIndex >= 1) { for (int i = 30; i >= 0; i--) { this.jiangJun.Inialize(jiangJun); if (b.str[i] == "红士") { for (int j = 0; j < 30; j++) { if (b.AcceptJudge(b.allPoint[i], b.allPoint[j], false)) { this.jiangJun.JiangJun(b.allPoint[i], b.allPoint[j], b); if (this.jiangJun.blueToRed == false) { fromPoint = b.allPoint[i]; toPoint = b.allPoint[j]; Console.WriteLine("55555"); if (fromPoint != toPoint) { return; } } } } } } } } b.Initialize(a); this.jiangJun.Inialize(jiangJun); if (footShuaiIndex >= 1) //"帅" 自己解除将军 { for (int i = 0; i < 90; i++) { this.jiangJun.Inialize(jiangJun); this.jiangJun.JiangJun(shuaiPoint, b.allPoint[i], b); if (this.jiangJun.blueToRed == false && b.AcceptJudge(shuaiPoint, b.allPoint[i], false) && b.who[b.CountIndex(b.allPoint[i])] != "red") { fromPoint = shuaiPoint; toPoint = b.allPoint[i]; this.jiangJun.Inialize(jiangJun); this.jiangJun.JiangJun(shuaiPoint, b.allPoint[i], b); if (fromPoint != toPoint && this.jiangJun.blueToRed == false) { Console.WriteLine("666666"); return; } } } } b.Initialize(a); this.jiangJun.Inialize(jiangJun); if (footShuaiIndex >= 1) { for (int i = 0; i < 50; i++) { if (b.AcceptJudge(shuaiPoint, b.allPoint[i], false)) { fromPoint = shuaiPoint; toPoint = b.allPoint[i]; Console.WriteLine("ccccc"); if (fromPoint != toPoint) { return; } } } } //进攻 /*吃将 * for(int i=89;i>=0;i--) * { * for(int j=89;j>=0;j--) * if(b.who[i]=="red"&&b.AcceptJudge(b.allPoint[i],b.allPoint[j],false)&&b.whichPicture[b.CountIndex(b.allPoint[j])]==27) * { * fromPoint=b.allPoint[i]; toPoint=b.allPoint[j]; * this.jiangJun.Inialize(jiangJun); * this.jiangJun.JiangJun(b.allPoint[i],b.allPoint[j],b); * if(fromPoint!=toPoint&&this.jiangJun.blueToRed==false) * { * Console.WriteLine("777777"); * return; * } * } * }*/ b.Initialize(a); this.jiangJun.Inialize(jiangJun); //有没有可吃的旗子 for (int i = 0; i < 90; i++) { for (int j = 0; j < 90; j++) { if (b.who[i] == "red" && b.who[j] == "blue" && b.AcceptJudge(b.allPoint[i], b.allPoint[j], false)) { bool may = true; for (int k = 0; k < 90; k++) { if (b.who[k] == "blue" && b.AcceptJudge(b.allPoint[k], b.allPoint[j], false) && b.CountIndex(b.allPoint[i]) < 60 && b.allPoint[j].X != 308) { may = false; } } // if (may) if (may && b.who[i] != b.who[j]) //避免误杀自己的旗子 { fromPoint = b.allPoint[i]; toPoint = b.allPoint[j]; this.jiangJun.Inialize(jiangJun); this.jiangJun.JiangJun(b.allPoint[i], b.allPoint[j], b); if (this.jiangJun.blueToRed == false) { Console.WriteLine("888888"); if (fromPoint != toPoint) { return; } } } } } } b.Initialize(a); this.jiangJun.Inialize(jiangJun); //避开一方旗子 bool mayGo = true; int index = -1, myIndex = -1; bool run = true; for (int i = 89; i >= 0; i--) { for (int j = 89; j >= 0; j--) { if (b.who[i] == "blue" && b.who[j] == "red" && b.AcceptJudge(b.allPoint[i], b.allPoint[j], false) && run) { index = i; myIndex = j; //i位置的蓝旗子将要吃j位置的红旗子 run = false; } } } b.Initialize(a); this.jiangJun.Inialize(jiangJun); if (index != -1) //杀死正踩红旗头的旗子 { for (int i = 89; i >= 0; i--) { if (b.who[i] == "red" && b.AcceptJudge(b.allPoint[i], b.allPoint[index], false)) { fromPoint = b.allPoint[i]; toPoint = b.allPoint[index]; this.jiangJun.Inialize(jiangJun); this.jiangJun.JiangJun(b.allPoint[i], b.allPoint[index], b); if (fromPoint != toPoint && this.jiangJun.blueToRed == false) { Console.WriteLine("999999"); return; } } } } b.Initialize(a); this.jiangJun.Inialize(jiangJun); if (myIndex != -1) //保护被蓝旗子踩头的旗子 { for (int k = 0; k < 90; k++) { for (int m = 0; m < 90; m++) { if (b.who[k] == "red" && b.AcceptJudge(b.allPoint[k], b.allPoint[m], false) && b.str[k] + string.Empty != string.Empty) { b.Initialize(a); b.ChangeQiZi(b.allPoint[k], b.allPoint[m]); b.str[m] = b.str[k]; try { if ((b.have[m] == false || b.who[m] != "red") && b.AcceptJudge(b.allPoint[m], b.allPoint[myIndex], false)) //防止误杀自己旗子(2006/10) { fromPoint = b.allPoint[k]; toPoint = b.allPoint[m]; b.Initialize(a); this.jiangJun.Inialize(jiangJun); this.jiangJun.JiangJun(b.allPoint[k], b.allPoint[m], b); if (fromPoint != toPoint && this.jiangJun.blueToRed == false) { Console.WriteLine("10 10 10 10"); return; } } } catch { continue; } } } } } b.Initialize(a); this.jiangJun.Inialize(jiangJun); //逃跑 if (myIndex != -1) { for (int i = 0; i < 90; i++) { for (int j = 0; j < 90; j++) { if (b.who[i] == "blue" && b.who[j] == "red" && b.AcceptJudge(b.allPoint[i], b.allPoint[j], false)) { ////自己旗子虽然被对方踩在脚下,但有自己其它的 "战友" "保卫", 则有些时候不必逃跑 //bool blnIsProtected = false; //for (int x = 0; x < 90; x++) //{ // if (b.who[x] == "red" && b.who[j] == "red" && b.AcceptJudge(b.allPoint[x], b.allPoint[j], false)) // { // if (b.allPoint[x] != b.allPoint[j]) // { // blnIsProtected = true; // } // } //} //if (blnIsProtected) //{ // continue; //} for (int k = 0; k < 90; k++) { this.b.Initialize(a); if (b.AcceptJudge(b.allPoint[j], b.allPoint[k], false)) { bool bb = true; for (int x = 0; x < 90; x++) { if (b.who[x] == "red" && b.AcceptJudge(b.allPoint[x], b.allPoint[j], false)) { bb = false; } } b.ChangeQiZi(b.allPoint[j], b.allPoint[k]); for (int m = 0; m < 90; m++) { if (b.who[m] == "blue" && b.AcceptJudge(b.allPoint[m], b.allPoint[k], false)) { bb = false; } } this.b.Initialize(a); this.jiangJun.Inialize(jiangJun); this.jiangJun.JiangJun(b.allPoint[j], b.allPoint[k], b); //this.jiangJun(b); if (bb && this.jiangJun.blueToRed == false) { fromPoint = b.allPoint[j]; toPoint = b.allPoint[k]; if (b.str[b.CountIndex(fromPoint)] == "红卒" && b.CountIndex(fromPoint) == 31) { continue; } Console.WriteLine("11 11 11"); if (fromPoint != toPoint) { return; } } } } } } } } b.Initialize(a); this.jiangJun.Inialize(jiangJun); //招数走旗 for (int i = 89; i >= 0; i--) { for (int j = 89; j >= 0; j--) { b.Initialize(a); if (b.who[i] == "red" && b.AcceptJudge(b.allPoint[i], b.allPoint[j], false)) { Point p = b.CountPoint(27); b.ChangeQiZi(b.allPoint[i], b.allPoint[j]); if (b.who[j] == "red" && b.AcceptJudge(b.allPoint[j], p, false)) { this.jiangJun.Inialize(jiangJun); this.jiangJun.JiangJun(b.allPoint[i], b.allPoint[j], a); if (this.jiangJun.blueToRed == false) { fromPoint = b.allPoint[i]; toPoint = b.allPoint[j]; Console.WriteLine("aaaaaaaa"); if (fromPoint != toPoint) { return; } } } for (int k = 89; k >= 0; k--) { if (b.who[j] == "red" && b.AcceptJudge(b.allPoint[j], b.allPoint[k], false)) { b.ChangeQiZi(b.allPoint[j], b.allPoint[k]); if (b.who[k] == "red" && b.AcceptJudge(b.allPoint[k], p, false)) { this.jiangJun.Inialize(jiangJun); this.jiangJun.JiangJun(b.allPoint[i], b.allPoint[j], a); if (this.jiangJun.blueToRed == false && b.str[i] != b.str[j]) { fromPoint = b.allPoint[i]; toPoint = b.allPoint[j]; Console.WriteLine("bbbbbbbbbb"); if (fromPoint != toPoint) { return; } } } } } } } } b.Initialize(a); b.Initialize(a); this.jiangJun.Inialize(jiangJun); //一般走旗 Random rand = new Random(); int data = rand.Next(100); int data1 = rand.Next(100); int data2 = Math.Abs(data - data1); if (data2 % 2 == 1) { for (int i = 89; i >= 0; i--) { for (int j = 89; j >= 0; j--) { if (b.who[i] == "red" && b.AcceptJudge(b.allPoint[i], b.allPoint[j], false) && b.allPoint[j].Y >= b.allPoint[i].Y - 50) { mayGo = true; for (int k = 0; k < 90; k++) { if (b.who[k] == "blue" && b.AcceptJudge(b.allPoint[k], b.allPoint[j], false)) { mayGo = false; } } if (mayGo) { fromPoint = b.allPoint[i]; toPoint = b.allPoint[j]; this.jiangJun.Inialize(jiangJun); this.jiangJun.JiangJun(b.allPoint[i], b.allPoint[j], b); if (fromPoint != toPoint && this.jiangJun.blueToRed == false) { if (b.str[b.CountIndex(fromPoint)] == "红卒" && b.CountIndex(fromPoint) == 31) { continue; } Console.WriteLine("12 12 12"); return; } } } } } } else { for (int i = 0; i < 90; i++) { for (int j = 89; j >= 0; j--) { if (b.who[i] == "red" && b.AcceptJudge(b.allPoint[i], b.allPoint[j], false) && b.allPoint[j].Y >= b.allPoint[i].Y - 50) { mayGo = true; for (int k = 0; k < 90; k++) { if (b.who[k] == "blue" && b.AcceptJudge(b.allPoint[k], b.allPoint[j], false)) { mayGo = false; } } if (mayGo) { fromPoint = b.allPoint[i]; toPoint = b.allPoint[j]; this.jiangJun.Inialize(jiangJun); this.jiangJun.JiangJun(b.allPoint[i], b.allPoint[j], b); if (fromPoint != toPoint && this.jiangJun.blueToRed == false) { if (b.str[b.CountIndex(fromPoint)] == "红卒" && b.CountIndex(fromPoint) == 31) { continue; } Console.WriteLine("13 13 13"); return; } } } } } } b.Initialize(a); this.jiangJun.Inialize(jiangJun); //随机走一个旗子 for (int i = 0; i < 90; i++) { for (int j = 89; j >= 0; j--) { if (b.who[i] == "red" && b.AcceptJudge(b.allPoint[i], b.allPoint[j], false)) { fromPoint = b.allPoint[i]; toPoint = b.allPoint[j]; Console.WriteLine("14 14 14"); if (fromPoint != toPoint) { return; } } } } }
public ComputerBrainpower() { b = new FlagMoveRule(); c = new FlagMoveRule(); this.jiangJun = new JudgeWhichOneWiner(); }
public void AcceptValue(FlagMoveRule a) { b.Initialize(a); }
public void JiangJun(FlagMoveRule a) { b.Initialize(); this.AcceptValue(a); this.ChangeParameter(); }