public bool deathofking(int i1, int j1, int[,] mat2, PictureBox[] picbox2, int[] kings2, int[] rooks2, int k11) { Node <Point> np1 = null; Point pos1 = new Point(i1, j1); List <Point> lst3 = new List <Point>(); king k12 = new king(pos1, mat2, picbox2, k11 * -1, kings2, rooks2); if (k12.toking(i1, j1, mat2, picbox2, k11) == new Point(-1, -1)) { return(false); } try { lst3 = k12.placestomove(); Point pp1 = lst3.GetFirst().GetInfo(); np1 = lst3.GetFirst(); } catch (Exception) { } while (np1 != null) { if (k12.toking(np1.GetInfo().X, np1.GetInfo().Y, mat2, picbox2, k11) != new Point(-1, -1)) { np1 = lst3.Remove(np1); } else { break; } } if (lst3.IsEmpty() == true) { return(true); } else { return(false); } }
//להציג מקומות האפשריות בצבע ירוק 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>(); king k1 = new king(pos, mat, pics, playernum, kings, rooks); try { lst2 = k1.placestomove(); Point pp = lst2.GetFirst().GetInfo(); np = lst2.GetFirst(); } catch (Exception) { } while (np != null) { int x = np.GetInfo().X; int y = np.GetInfo().Y; int n = x * 10 + y - 2 * x; if (k1.toking(x, y, mat, picbox, playernum * -1) == new Point(-1, -1)) { pics[n].BackColor = Color.Green; pics[n].Enabled = true; } else { pics[n].BackColor = Color.Red; } pics[n].Enabled = true; pics[n].Visible = true; 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); } }