Ejemplo n.º 1
0
        public void MakeRoque(ChessBoard board, ChessFigure king, int moveNumber)
        {
            ChessField kingNewField, rookNewField;

            if (Color == Color.WHITE)
            {
                kingNewField = CurrentField.Column == 'A' ? board.GetField(1, 'C') : board.GetField(1, 'G');
                rookNewField = CurrentField.Column == 'A' ? board.GetField(1, 'D') : board.GetField(1, 'F');
            }
            else
            {
                kingNewField = CurrentField.Column == 'A' ? board.GetField(8, 'C') : board.GetField(8, 'G');
                rookNewField = CurrentField.Column == 'A' ? board.GetField(8, 'D') : board.GetField(8, 'F');
            }

            ChessMove kingMove = new ChessMove(Color, moveNumber, king, null, king.CurrentField, kingNewField, true);

            king.PreviousMoves.Add(kingMove);
            ChessMove move = new ChessMove(Color, moveNumber, this, null, CurrentField, rookNewField, true);

            PreviousMoves.Add(move);

            board.EmptyField(king.CurrentField);
            board.EmptyField(CurrentField);
            board.OccupyField(kingNewField.Row, kingNewField.Column, Color);
            board.OccupyField(rookNewField.Row, rookNewField.Column, Color);
            king.CurrentField = kingNewField;
            CurrentField      = rookNewField;
            king.FindFieldsToMove(board);
            FindFieldsToMove(board);
        }
Ejemplo n.º 2
0
        public virtual void Move(ChessField field, ChessPlayer enemy, ChessBoard board, int moveNumber, ChessFigure[] otherFigures)
        {
            FieldStatus enemyStatus =
                Color == Color.WHITE ? FieldStatus.OCCUPIED_WITH_BLACK : FieldStatus.OCCUPIED_WITH_WHITE;
            ChessFigure killedFigure = null;

            if (field.Status == enemyStatus)
            {
                foreach (ChessFigure enemyFigure in enemy.Figures)
                {
                    if (enemyFigure.CurrentField == field)
                    {
                        enemyFigure.FigureKilled();
                        killedFigure = enemyFigure;
                        break;
                    }

                    if (enemyFigure is ChessPawn && ((ChessPawn)enemyFigure).EnPassant &&
                        enemyFigure.CurrentField.Column == field.Column)
                    {
                        if ((Color == Color.WHITE && field.Row == 6 && ((ChessPawn)enemyFigure).EnPassantMove == moveNumber - 1) ||
                            (Color == Color.BLACK && field.Row == 3 && ((ChessPawn)enemyFigure).EnPassantMove == moveNumber))
                        {
                            enemyFigure.FigureKilled();
                            killedFigure = enemyFigure;
                            break;
                        }
                    }
                }
            }
            ChessMove move = new ChessMove(Color, moveNumber, this, killedFigure, CurrentField, field);

            PreviousMoves.Add(move);
            board.EmptyField(CurrentField);
            board.OccupyField(field.Row, field.Column, Color);
            CurrentField = field;
            FindFieldsToMove(board);
        }