Exemplo n.º 1
0
        private void DrawSquare(System.Windows.Forms.PaintEventArgs e, Graphics surface,
                                BoardLocation boardLocation, int x, int y)
        {
            //draw bounding black square
            surface.DrawRectangle(PenBorder, x, y, 64, 64);

            //draw light or dark square background
            surface.FillRectangle(
                boardLocation.Color() == BoardLocationColor.Light ? LightSquareBrush: DarkSquareBrush,
                x + 1,
                y + 1,
                63, 63);

            //draw square as a valid move square
            if (MovingPiece != ChessPiece.None)
            {
                if (IsValidMove(boardLocation))
                {
                    surface.FillRectangle(LegalMoveBrush, x + 1, y + 1, 63, 63);
                }
            }

            //Draw the legend for squares (a-h and 1-8)
            if (boardLocation.Column() == 0)
            {
                surface.DrawString(Convert.ToString((boardLocation.Row() + 1)), Font,
                                   BlackBoardTextbrush, x + 3, y + 25);
            }
            if (boardLocation.Row() == 0)
            {//ascii A=65
                surface.DrawString(Convert.ToChar(65 + boardLocation.Column()).ToString(), Font,
                                   BlackBoardTextbrush, x + 27, y + 48);
            }

            //dont draw piece if its being moved...
            if ((MovingPiece != ChessPiece.None) &&
                (boardLocation == MovingPieceBoardLocation))
            {
                return;
            }

            //draw the icon on the board..
            if (Game.Board[boardLocation] != ChessPiece.None)
            {
                surface.DrawImage(
                    imageList32.Images[ToImageIndex(boardLocation)],
                    x + 16, y + 16, 32, 32);
            }
        }
Exemplo n.º 2
0
        private bool LastMoveAllowsEnPassantFor(BoardLocation pawnLocation, Direction pawnCaptureDirection)
        {
            var lastMove = _moveHistory.LastOrDefault();

            if (lastMove == null)
            {
                return(false);
            }

            var pawnLocationColumn     = pawnLocation.Column();
            int lastMoveExpectedColumn = 0;

            switch (pawnCaptureDirection)
            {
            case Direction.NorthEast:
            case Direction.SouthEast:
                lastMoveExpectedColumn = pawnLocationColumn + 1;
                break;

            case Direction.NorthWest:
            case Direction.SouthWest:
                lastMoveExpectedColumn = pawnLocationColumn - 1;
                break;
            }

            //If (and ONLY if):
            //-: the last move was a pawn move AND
            //-: the last move was two spaces AND
            //-: we can thus infer it belongs to the opposite player AND
            //-: the last move was right next to the given pawn
            //-: the last move was in the right column (based on capture direction)
            //(Jesus christ almighty this was not easy)
            if ((_board.ContainsPawn(lastMove.Destination)) &&
                (Math.Abs(lastMove.Destination.ToByte() - lastMove.Source.ToByte()) == 2) &&
                (lastMove.Destination.Row() == pawnLocation.Row()) &&
                (lastMove.Destination.Column() == lastMoveExpectedColumn))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 3
0
 public static bool IsOnSameRowAs(this BoardLocation source, BoardLocation target)
 {
     return(source.Row() == target.Row());
 }