//רוזמרין اقليل الجبل public void Filllist(int n, Point[] pt, List <Point>[] lpt) { if (n >= 0) { List <Point> lst = new List <Point>(); Node <Point> np1 = lst.GetFirst(); Point pp = pt[n - 1]; int x = pp.X; int y = pp.Y; if (mat[x, y] * playernum > 0)//> { switch (mat[x, y]) { case 1: case -1: Pawn p2 = new Pawn(new Point(x, y), mat, picbox, playernum, kingsplace, kings, rooks); p2.showGreenplaces(x, y, picbox); break; case 2: case -2: rook r2 = new rook(new Point(x, y), mat, picbox, playernum, kingsplace, kings, rooks); r2.showGreenplaces(x, y, picbox); break; case 3: case -3: knight kn2 = new knight(new Point(x, y), mat, picbox, playernum, kingsplace, kings, rooks); kn2.showGreenplaces(x, y, picbox); break; case 4: case -4: fou f2 = new fou(new Point(x, y), mat, picbox, playernum, kingsplace, kings, rooks); f2.showGreenplaces(x, y, picbox); break; case 5: case -5: queen q2 = new queen(new Point(x, y), mat, picbox, playernum, kingsplace, kings, rooks); q2.showGreenplaces(x, y, picbox); break; case -6: king k2 = new king(new Point(x, y), mat, picbox, playernum, kings, rooks); k2.showGreenplaces(x, y, picbox); break; default: break; } for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (picbox[i * 10 + j - 2 * i].BackColor == Color.Green) { np1 = lst.Insert(np1, new Point(i, j)); } } } game_main gm = new game_main(); gm.refreshcolors(picbox, playernum, mat); } lpt[n - 1] = lst; if (n > 1) { Filllist(n - 1, pt, lpt); } } }
//داله تعيد عدد الاماكن الخضراء public int count_greenplace() //good { int count = 0; int[,] help = new int[8, 8]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { help[i, j] = mat[i, j]; } } help[after.X, after.Y] = help[befor.X, befor.Y]; help[befor.X, befor.Y] = 0; game_main aaa = new game_main(); aaa.refreshcolors(picbox, playernum, mat); switch (help[after.X, after.Y]) { case 1: case -1: Pawn p2 = new Pawn(after, help, picbox, playernum, kingsplace, kings, rooks); p2.showGreenplaces(after.X, after.Y, picbox); break; case 2: case -2: rook r2 = new rook(after, help, picbox, playernum, kingsplace, kings, rooks); r2.showGreenplaces(after.X, after.Y, picbox); break; case 3: case -3: knight kn2 = new knight(after, help, picbox, playernum, kingsplace, kings, rooks); kn2.showGreenplaces(after.X, after.Y, picbox); break; case 4: case -4: fou f2 = new fou(after, help, picbox, playernum, kingsplace, kings, rooks); f2.showGreenplaces(after.X, after.Y, picbox); break; case 5: case -5: queen q2 = new queen(after, help, picbox, playernum, kingsplace, kings, rooks); q2.showGreenplaces(after.X, after.Y, picbox); break; case -6: king k2 = new king(after, help, picbox, playernum, kings, rooks); k2.showGreenplaces(after.X, after.Y, picbox); break; default: break; } for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (picbox[i * 10 + j - 2 * i].BackColor == Color.Green) { count++; } } } return(count); }
// פונקציה הזות מקבלת שני פרמטרים שלמים ובודקת מה סוג של הקטע שקבלנו לפי מערך דומימדי public void Wathitem(int i, int j) { if (playernum == -1) { timer1.Start(); } else { timer2.Start(); } switch (mat[i, j])// pwan + { case 1: Pawn p1 = new Pawn(new Point(i, j), mat, picbox, playernum, kingsplace, kings, rooks); p1.showGreenplaces(i, j, picbox); break; case 2: rook r1 = new rook(new Point(i, j), mat, picbox, playernum, kingsplace, kings, rooks); r1.showGreenplaces(i, j, picbox); break; case 3: knight kn1 = new knight(new Point(i, j), mat, picbox, playernum, kingsplace, kings, rooks); kn1.showGreenplaces(i, j, picbox); break; case 4: fou f1 = new fou(new Point(i, j), mat, picbox, playernum, kingsplace, kings, rooks); f1.showGreenplaces(i, j, picbox); break; case 5: queen q1 = new queen(new Point(i, j), mat, picbox, playernum, kingsplace, kings, rooks); q1.showGreenplaces(i, j, picbox); break; case 6: king k1 = new king(new Point(i, j), mat, picbox, playernum, kings, rooks); k1.showGreenplaces(i, j, picbox); k1.showorangeplace(); break; case -1: Pawn p2 = new Pawn(new Point(i, j), mat, picbox, playernum, kingsplace, kings, rooks); p2.showGreenplaces(i, j, picbox); break; case -2: rook r2 = new rook(new Point(i, j), mat, picbox, playernum, kingsplace, kings, rooks); r2.showGreenplaces(i, j, picbox); break; case -3: knight kn2 = new knight(new Point(i, j), mat, picbox, playernum, kingsplace, kings, rooks); kn2.showGreenplaces(i, j, picbox); break; case -4: fou f2 = new fou(new Point(i, j), mat, picbox, playernum, kingsplace, kings, rooks); f2.showGreenplaces(i, j, picbox); break; case -5: queen q2 = new queen(new Point(i, j), mat, picbox, playernum, kingsplace, kings, rooks); q2.showGreenplaces(i, j, picbox); break; case -6: king k2 = new king(new Point(i, j), mat, picbox, playernum, kings, rooks); k2.showGreenplaces(i, j, picbox); k2.showorangeplace(); break; default: break; } }
//عند انتقال القطعه للمكان الجديد نفحص عدد القطع التي تستطيع القطعه تهديدها ونعيدها واذا ولا قطعه نعيد 0 public int count_piesethreated() //good { game_main aaa = new game_main(); int[,] help = new int[8, 8]; int k = 0, c = 0; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { help[i, j] = mat[i, j]; } } help[after.X, after.Y] = help[befor.X, befor.Y]; help[befor.X, befor.Y] = 0; aaa.refreshcolors(picbox, playernum, help); switch (help[after.X, after.Y]) { case 1: case -1: Pawn p2 = new Pawn(after, help, picbox, playernum, kingsplace, kings, rooks); p2.showGreenplaces(after.X, after.Y, picbox); break; case 2: case -2: rook r2 = new rook(after, help, picbox, playernum, kingsplace, kings, rooks); r2.showGreenplaces(after.X, after.Y, picbox); break; case 3: case -3: knight kn2 = new knight(after, help, picbox, playernum, kingsplace, kings, rooks); kn2.showGreenplaces(after.X, after.Y, picbox); break; case 4: case -4: fou f2 = new fou(after, help, picbox, playernum, kingsplace, kings, rooks); f2.showGreenplaces(after.X, after.Y, picbox); break; case 5: case -5: queen q2 = new queen(after, help, picbox, playernum, kingsplace, kings, rooks); q2.showGreenplaces(after.X, after.Y, picbox); break; case 6: case -6: king k2 = new king(after, help, picbox, playernum, kings, rooks); k2.showGreenplaces(after.X, after.Y, picbox); break; default: break; } for (int d = 0; d < 8; d++) { for (int e = 0; e < 8; e++) { if (picbox[k].BackColor == Color.Green) { if (help[d, e] != 0) { c++; } } k++; } } aaa.refreshcolors(picbox, playernum, help); return(c * 10); }
//اذا كانت القطعه او عند انتقالها للمكان الجديد تستطيع قتل قطع من قطع العو تعيد حسب اهميته جندي 60 وغير ذلك 0 public int killer() // good { game_main aaa = new game_main(); aaa.refreshcolors(picbox, playernum, mat); // no color switch (mat[befor.X, befor.Y]) // show color green before move the item { case -1: case 1: Pawn p2 = new Pawn(befor, mat, picbox, playernum, kingsplace, kings, rooks); p2.showGreenplaces(befor.X, befor.Y, picbox); break; case -2: case 2: rook r2 = new rook(befor, mat, picbox, playernum, kingsplace, kings, rooks); r2.showGreenplaces(befor.X, befor.Y, picbox); break; case -3: case 3: knight kn2 = new knight(befor, mat, picbox, playernum, kingsplace, kings, rooks); kn2.showGreenplaces(befor.X, befor.Y, picbox); break; case -4: case 4: fou f2 = new fou(befor, mat, picbox, playernum, kingsplace, kings, rooks); f2.showGreenplaces(befor.X, befor.Y, picbox); break; case -5: case 5: queen q2 = new queen(befor, mat, picbox, playernum, kingsplace, kings, rooks); q2.showGreenplaces(befor.X, befor.Y, picbox); break; case -6: case 6: king k2 = new king(befor, mat, picbox, playernum, kings, rooks); k2.showGreenplaces(befor.X, befor.Y, picbox); break; default: break; } if (picbox[after.X * 10 + after.Y - 2 * after.X].BackColor == Color.Green) // new point is green? { if (mat[after.X, after.Y] != 0) // new pos in mat(orginal) not 0 { switch (Math.Abs(mat[after.X, after.Y])) { case -1: case 1: aaa.refreshcolors(picbox, playernum, mat); return(60); case -2: case 2: aaa.refreshcolors(picbox, playernum, mat); return(62); case -3: case 3: aaa.refreshcolors(picbox, playernum, mat); return(64); case -4: case 4: aaa.refreshcolors(picbox, playernum, mat); return(66); case -5: case 5: aaa.refreshcolors(picbox, playernum, mat); return(68); default: break; } } } return(0); }
public void showGreenplaces(int i, int j, PictureBox[] pics) { Node <Point> np = null; Point pos = new Point(i, j); List <Point> lst2 = new List <Point>(); Point pt = new Point(); fou r1 = new fou(pos, mat, pics, playernum, kingplaces, kings, rooks); if (playernum == -1) { pt = kingplaces[0]; } else { pt = kingplaces[1]; } king k = new king(pt, mat, picbox, playernum, kings, rooks); bool t = k.deathofking(pt.X, pt.Y, mat, picbox, kings, rooks, playernum * -1); try { lst2 = r1.placestomove(); Point pp = lst2.GetFirst().GetInfo(); np = lst2.GetFirst(); } catch (Exception) { } int[,] help = new int[8, 8]; for (int ii = 0; ii < 8; ii++) { for (int jj = 0; jj < 8; jj++) { help[ii, jj] = mat[ii, jj]; } } while (np != null) { int x = np.GetInfo().X; int y = np.GetInfo().Y; int n = x * 10 + y - 2 * x; int v = help[x, y]; help[x, y] = playernum; if (k.toking(pt.X, pt.Y, help, picbox, playernum * -1) == new Point(-1, -1)) { pics[n].BackColor = Color.Green; pics[n].Enabled = true; pics[n].Visible = true; } else { pics[n].BackColor = Color.Red; pics[n].Enabled = false; pics[n].Visible = true; } help[x, y] = v; np = np.GetNext(); } }
public void computerplayer1(int playernum, int[] kings, int[] rooks, Point[] kingsplace, PictureBox[] picbox, int[,] mat) { Point last = new Point(); Random rd = new Random(); game_main pppp = new game_main(); int i, j, newx, newy, found = 0, c = 0, a, m = 0, p, timer; List <Point> lst = new List <Point>(); List <Point> lst2 = new List <Point>(); Node <Point> np = lst2.GetFirst(); Node <Point> np2; timer = rd.Next(3) + 1; TimeSpan interval = new TimeSpan(0, 0, timer); for (i = 0; i < 8 && found == 0; i++) { c = 0; found = 0; for (j = 0; j < 8 && found == 0; j++) { if (mat[i, j] * playernum > 0) { last = new Point(i, j); switch (mat[i, j]) { case -1: case 1: Pawn p2 = new Pawn(new Point(i, j), mat, picbox, playernum, kingsplace, kings, rooks); p2.showGreenplaces(i, j, picbox); lst = p2.placestomove(); break; case -2: case 2: rook r2 = new rook(new Point(i, j), mat, picbox, playernum, kingsplace, kings, rooks); r2.showGreenplaces(i, j, picbox); lst = r2.placestomove(); break; case -3: case 3: knight kn2 = new knight(new Point(i, j), mat, picbox, playernum, kingsplace, kings, rooks); kn2.showGreenplaces(i, j, picbox); lst = kn2.placestomove(); break; case -4: case 4: fou f2 = new fou(new Point(i, j), mat, picbox, playernum, kingsplace, kings, rooks); f2.showGreenplaces(i, j, picbox); lst = f2.placestomove(); break; case -5: case 5: queen q2 = new queen(new Point(i, j), mat, picbox, playernum, kingsplace, kings, rooks); q2.showGreenplaces(i, j, picbox); lst = q2.placestomove(); break; case -6: case 6: king k2 = new king(new Point(i, j), mat, picbox, playernum, kings, rooks); k2.showGreenplaces(i, j, picbox); lst = k2.placestomove(); break; default: break; } } if (lst.IsEmpty() == false) { for (int k = 0; k < 8; k++) { for (int t = 0; t < 8; t++) { if (picbox[k * 10 + t - 2 * k].BackColor == Color.Green) { np = lst2.Insert(np, new Point(k, t)); c++; } } } if (lst2.IsEmpty() == false) { found = 1; } } } } a = rd.Next(c + 1); m = 0; np2 = lst2.GetFirst(); while (a != m) { np2 = np2.GetNext(); m++; } int b1 = last.X; int b2 = last.Y; lx = new Point(b1, b2); computerplayer.oldstep = new Point(b1, b2); newx = np.GetInfo().X; newy = np.GetInfo().Y; computerplayer.newstep = new Point(newx, newy); nx = new Point(newx, newy); if (mat[newx, newy] != 0) { computerplayer.loscomp = mat[newx, newy]; } if (newx == 7 * playernum && mat[b1, b2] == 1 * playernum) { mat[b1, b2] = 0; mat[newx, newy] = 5; picbox[b1 * 10 + b2 - 2 * b1].ImageLocation = null; Thread.Sleep(interval); Application.DoEvents(); picbox[newx * 10 + newy - 2 * newx].ImageLocation = pppp.chessimage(5); picbox[newx * 10 + newy - 2 * newx].SizeMode = PictureBoxSizeMode.CenterImage; pppp.refreshcolors(picbox, playernum, mat); } else if (newx == 0 && mat[b1, b2] * playernum == -1 * playernum) { mat[b1, b2] = 0; mat[newx, newy] = -5; picbox[b1 * 10 + b2 - 2 * b1].ImageLocation = null; Thread.Sleep(interval); Application.DoEvents(); picbox[newx * 10 + newy - 2 * newx].ImageLocation = pppp.chessimage(-5); picbox[newx * 10 + newy - 2 * newx].SizeMode = PictureBoxSizeMode.CenterImage; pppp.refreshcolors(picbox, playernum, mat); } else { p = mat[b1, b2]; mat[b1, b2] = 0; mat[newx, newy] = p; picbox[b1 * 10 + b2 - 2 * b1].ImageLocation = null; Thread.Sleep(interval); Application.DoEvents(); picbox[newx * 10 + newy - 2 * newx].ImageLocation = pppp.chessimage(p); picbox[newx * 10 + newy - 2 * newx].SizeMode = PictureBoxSizeMode.CenterImage; pppp.refreshcolors(picbox, playernum, mat); } }