private void MakeMove(move_t m) { // start move log output string move = (this.Turn == Player.WHITE) ? "W" : "B"; move += ":\t"; // piece switch (this.Board.Grid[m.from.number][m.from.letter].piece) { case Piece.PAWN: move += "P"; break; case Piece.ROOK: move += "R"; break; case Piece.KNIGHT: move += "k"; break; case Piece.BISHOP: move += "B"; break; case Piece.QUEEN: move += "Q"; break; case Piece.KING: move += "K"; break; } // kill if (this.Board.Grid[m.to.number][m.to.letter].piece != Piece.NONE || LegalMoveSet.isEnPassant(this.Board, m)) { move += "x"; } // letter switch (m.to.letter) { case 0: move += "a"; break; case 1: move += "b"; break; case 2: move += "c"; break; case 3: move += "d"; break; case 4: move += "e"; break; case 5: move += "f"; break; case 6: move += "g"; break; case 7: move += "h"; break; } // number move += (m.to.number + 1).ToString(); // update board / make actual move this.Board = LegalMoveSet.move(this.Board, m); // if that move put someone in check if (LegalMoveSet.isCheck(this.Board, (Turn == Player.WHITE) ? Player.BLACK : Player.WHITE)) { move += "+"; } // show log this.m_UI.LogMove(move + "\n"); }
private void BoardClick(object sender, EventArgs e) { if (chess != null && !m_checkmate) { // clear board for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { Board[i][j].BackColor = ((i + j) % 2 == 0) ? Color.Black : Color.White; } } for (int i = 0; i < 8; i++) { int k = Array.IndexOf(Board[i], sender); if (k > -1) { // draw highlighting if ((!m_manualBoard || m_finalizedBoard) && !m_aigame) { List <position_t> moves = chess.Select(new position_t(k, i)); foreach (position_t move in moves) { if ((chess.Board.Grid[move.number][move.letter].player != chess.Turn && chess.Board.Grid[move.number][move.letter].piece != Piece.NONE) || LegalMoveSet.isEnPassant(chess.Board, new move_t(chess.Selection, move))) { // attack Board[move.number][move.letter].BackColor = Color.Red; } else { // move Board[move.number][move.letter].BackColor = Color.Yellow; } } } // place piece else { chess.Board.SetPiece(m_manualPiece, m_manualPlayer, k, i); SetPiece(m_manualPiece, m_manualPlayer, k, i); if (m_manualPiece == Piece.KING) { if (m_manualPlayer == Player.WHITE) { White_King.Enabled = false; } else { Black_King.Enabled = false; } // both players have kings, we could technically start if (!White_King.Enabled && !Black_King.Enabled) { doneToolStripMenuItem.Enabled = true; } } } } } } }