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(); Pawn r1 = new Pawn(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); } }