// // Basic check // private bool[] isClear(ChessPiece piece) // Returns [rank, file], [Col, row] { bool colB = true, rowB = true; int col = piece.pos.Column, row = piece.pos.Row; for (int i = 0; i < 8; i++) { PictureBox boxC = (PictureBox)playBoard.GetControlFromPosition(col, i); PictureBox boxR = (PictureBox)playBoard.GetControlFromPosition(i, row); ChessPiece pcC = Calcs.CheckPiece(boxC); ChessPiece pcR = Calcs.CheckPiece(boxR); if (boxC != null && pcC.pieceRank == piece.pieceRank && pcC.isWhite == piece.isWhite && pcC != piece) { colB = false; } if (boxR != null && pcR.pieceRank == piece.pieceRank && pcR.isWhite == piece.isWhite && pcR != piece) { rowB = false; } } return(new bool[2] { colB, rowB }); }
// // Handle piece clicks // internal void PieceClick(object sender, MouseEventArgs e) { // // Discard moves/wrong clicks // if (isOver) { return; } PictureBox box = (PictureBox)sender; ChessPiece selpiece = Calcs.CheckPiece(box); if (isMoving) { AttackMove(sender, e); return; } else if (whiteTurn != selpiece.isWhite) { return; } isMoving = true; // // Get moves + Calculate // Variables selectedPiece = selpiece; List <Point> moves = Calcs.CalcMovesG(selpiece, checkingPieces); List <Point> discard = new List <Point>(); foreach (Point pt in moves) { int col = pt.X; int row = pt.Y; PictureBox cont = (PictureBox)playBoard.GetControlFromPosition(pt.X, pt.Y); ChessPiece contp = Calcs.CheckPiece(cont); // // Discard unusable moves // if (col < 0 || col > 7 || row < 0 || row > 7) { discard.Add(pt); } else if (cont != null && cont.BackColor != Color.DarkGray && contp.isWhite == selpiece.isWhite) { discard.Add(pt); } else { AddTempBox(row, col); } } if (moves.Count == discard.Count) { isMoving = false; return; } }
public Board(Main Mn) { mn = Mn; InitializeComponent(); Calcs.board = playBoard; // Set calc variables for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { PictureBox box = (PictureBox)playBoard.GetControlFromPosition(i, j); if (box != null) { ChessPiece piece = new ChessPiece(box, playBoard); Calcs.pieces.Add(piece); // Set the "pieces" var in Calcs if (piece.isWhite) { Calcs.wP.Add(piece); } else { Calcs.bP.Add(piece); } } } } Calcs.BK = Calcs.CheckPiece(bKe); Calcs.WK = Calcs.CheckPiece(wKe); WPr = new List <Button>() { WbuttonR, WbuttonK, WbuttonB, WbuttonQ }; BPr = new List <Button>() { BbuttonR, BbuttonK, BbuttonB, BbuttonQ }; }