Example #1
0
 internal void UpdateLastMove(SquareCoordinates from, Move m, ChessPiece moved, ChessPiece taken)
 {
     moveLabel.Text = MoveRecorder.GetMoveNotation(from, m, moved, taken);
     if (m.Overtaken)
         WaitingPlayer().Material.Pieces.Remove(m.TakenPiece);
 }
Example #2
0
 internal bool WillPlaceKingInCheck(Player p, SquareCoordinates[] fromSquares, SquareCoordinates[] toSquares)
 {
     SquareCoordinates king = p.Material.KingSquare;
     ChessPiece[] overwrittenPieces = new ChessPiece[fromSquares.Length];
     for (int i = 0; i < fromSquares.Length; i++)
     {
         SquareCoordinates from = fromSquares[i];
         SquareCoordinates to = toSquares[i];
         ChessPiece fromPiece = pieces[from.File, from.Rank];
         overwrittenPieces[i] = pieces[to.File, to.Rank];
         pieces[to.File, to.Rank] = fromPiece;
         pieces[from.File, from.Rank] = null;
         if (fromPiece.IsA(PieceType.KING) && fromPiece.IsFriendly(p.White))
             king = to;
     }
     bool inCheck = GameLogic.KingInCheck(this, king, p.White);
     for (int i = 0; i < fromSquares.Length; i++)
     {
         SquareCoordinates from = fromSquares[i];
         SquareCoordinates to = toSquares[i];
         ChessPiece fromPiece = pieces[to.File, to.Rank];
         pieces[from.File, from.Rank] = fromPiece;
         pieces[to.File, to.Rank] = overwrittenPieces[i];
     }
     return inCheck;
 }
Example #3
0
 private void SetPiece(SquareCoordinates coord, ChessPiece piece)
 {
     pieces[coord.File, coord.Rank] = piece;
 }
Example #4
0
 internal void DrawPiece(SquareCoordinates coord, ChessPiece piece)
 {
     SetPiece(coord, piece);
     using (Graphics g = this.CreateGraphics())
     {
         DrawPiece(g, new BoardIndices(coord, whiteOnBottom), piece.White, piece.Type);
     }
 }
Example #5
0
 internal static string GetMoveNotation(SquareCoordinates start, Move m, ChessPiece moved, ChessPiece taken)
 {
     string notation = PieceTypeInitial(moved.Type);
     notation += start.ToString().ToLower();
     //long algebraic notation doesn't actually specify the piece initial of the taken piece, but this is more consistent so just do it
     notation += !m.Overtaken ? "-" : ("x" + PieceTypeInitial(taken.Type));
     notation += m.Coordinates.ToString().ToLower();
     return notation;
 }
Example #6
0
 protected void PromotePiece(ChessBoard board, SquareCoordinates coord, PieceType promotedType, ChessPiece piece)
 {
     piece.Type = promotedType;
     board.ClearSquare(coord);
     board.DrawPiece(coord, piece);
 }
Example #7
0
 protected abstract void MadeMove(ChessBoard board, ChessPiece movedPiece, SquareCoordinates from, SquareCoordinates to, MoveSet moves);
Example #8
0
 protected override void MadeMove(ChessBoard board, ChessPiece movedPiece, SquareCoordinates from, SquareCoordinates to, MoveSet moves)
 {
 }
Example #9
0
 protected override void MadeMove(ChessBoard board, ChessPiece movedPiece, SquareCoordinates from, SquareCoordinates to, MoveSet moves)
 {
     foreach (Move legalMove in moves.LegalMoves)
         board.UnhighlightSquare(legalMove.Coordinates);
     foreach (SquareCoordinates checkedMoves in moves.CheckableMoves)
         board.UnhighlightSquare(checkedMoves);
     foreach (SquareCoordinates checkedMoves in moves.BlockedSquareMoves)
         board.UnhighlightSquare(checkedMoves);
     PieceType promoted = PieceType.UNDEFINED;
     if (movedPiece.IsA(PieceType.PAWN) && (White && to.Rank == 7 || !White && to.Rank == 0))
         PromotePiece(board, to, promoted = new PromotionSelect().Prompt(board));
     if (remoteOpponent != null)
     {
         remoteOpponent.SendMessage(ChessPacketWriter.WriteSelectSquare(to));
         if (promoted != PieceType.UNDEFINED)
             remoteOpponent.SendMessage(ChessPacketWriter.WritePromotion(to, promoted));
     }
 }