Ejemplo n.º 1
0
        public override bool[,] PossibleMovements()
        {
            bool[,] matrix = new bool[Board.Rows, Board.Cols];

            Position pos = new Position(0, 0);

            // up
            pos.Row = Position.Row - 1;
            pos.Col = Position.Col;
            while (Board.IsValidPosition(pos) && CanMove(pos))
            {
                matrix[pos.Row, pos.Col] = true;
                if (Board.GetPiece(pos) != null && Board.GetPiece(pos).Color != Color)
                {
                    break;
                }
                pos.Row--;
            }

            // up right
            pos.Row = Position.Row - 1;
            pos.Col = Position.Col + 1;
            while (Board.IsValidPosition(pos) && CanMove(pos))
            {
                matrix[pos.Row, pos.Col] = true;
                if (Board.GetPiece(pos) != null && Board.GetPiece(pos).Color != Color)
                {
                    break;
                }
                pos.Row--;
                pos.Col++;
            }

            // right
            pos.Row = Position.Row;
            pos.Col = Position.Col + 1;
            while (Board.IsValidPosition(pos) && CanMove(pos))
            {
                matrix[pos.Row, pos.Col] = true;
                if (Board.GetPiece(pos) != null && Board.GetPiece(pos).Color != Color)
                {
                    break;
                }
                pos.Col++;
            }

            // down right
            pos.Row = Position.Row + 1;
            pos.Col = Position.Col + 1;
            while (Board.IsValidPosition(pos) && CanMove(pos))
            {
                matrix[pos.Row, pos.Col] = true;
                if (Board.GetPiece(pos) != null && Board.GetPiece(pos).Color != Color)
                {
                    break;
                }
                pos.Row++;
                pos.Col++;
            }

            // down
            pos.Row = Position.Row + 1;
            pos.Col = Position.Col;
            while (Board.IsValidPosition(pos) && CanMove(pos))
            {
                matrix[pos.Row, pos.Col] = true;
                if (Board.GetPiece(pos) != null && Board.GetPiece(pos).Color != Color)
                {
                    break;
                }
                pos.Row++;
            }

            // down left
            pos.Row = Position.Row + 1;
            pos.Col = Position.Col - 1;
            while (Board.IsValidPosition(pos) && CanMove(pos))
            {
                matrix[pos.Row, pos.Col] = true;
                if (Board.GetPiece(pos) != null && Board.GetPiece(pos).Color != Color)
                {
                    break;
                }
                pos.Row++;
                pos.Col--;
            }

            // left
            pos.Row = Position.Row;
            pos.Col = Position.Col - 1;
            while (Board.IsValidPosition(pos) && CanMove(pos))
            {
                matrix[pos.Row, pos.Col] = true;
                if (Board.GetPiece(pos) != null && Board.GetPiece(pos).Color != Color)
                {
                    break;
                }
                pos.Col--;
            }

            // up left
            pos.Row = Position.Row - 1;
            pos.Col = Position.Col - 1;
            while (Board.IsValidPosition(pos) && CanMove(pos))
            {
                matrix[pos.Row, pos.Col] = true;
                if (Board.GetPiece(pos) != null && Board.GetPiece(pos).Color != Color)
                {
                    break;
                }
                pos.Row--;
                pos.Col--;
            }

            return(matrix);
        }
Ejemplo n.º 2
0
 public Queen(Board board, Color color) : base(board, color)
 {
 }
Ejemplo n.º 3
0
        private bool CanMove(Position position)
        {
            Piece piece = Board.piece(position);

            return(piece == null || piece.Color != Color);
        }
Ejemplo n.º 4
0
 public Knight(Board board, Color color) : base(board, color)
 {
 }
Ejemplo n.º 5
0
 public Pawn(Board board, Color color, ChessMatch match) : base(board, color)
 {
     Match = match;
 }
Ejemplo n.º 6
0
        public override bool[,] PossiblesMoviments()
        {
            bool[,] mat = new bool[Board.Rows, Board.Columns];

            Position pos = new Position(0, 0);

            if (Color == Color.White)
            {
                pos.SetPosition(Position.Row - 1, Position.Column);
                if (Board.ValidPosition(pos) && FreePosition(pos))
                {
                    mat[pos.Row, pos.Column] = true;
                }
                pos.SetPosition(Position.Row - 2, Position.Column);
                if (Board.ValidPosition(pos) && FreePosition(pos) && AmtMoviments == 0)
                {
                    mat[pos.Row, pos.Column] = true;
                }
                pos.SetPosition(Position.Row - 1, Position.Column - 1);
                if (Board.ValidPosition(pos) && ThereIsAdversary(pos))
                {
                    mat[pos.Row, pos.Column] = true;
                }
                pos.SetPosition(Position.Row - 1, Position.Column + 1);
                if (Board.ValidPosition(pos) && ThereIsAdversary(pos))
                {
                    mat[pos.Row, pos.Column] = true;
                }

                //#special moviment
                if (Position.Row == 3)
                {
                    Position left = new Position(Position.Row, Position.Column - 1);

                    if (Board.ValidPosition(left) && ThereIsAdversary(left) && Board.GetPiece(left) == Match.CanPassant)
                    {
                        mat[left.Row - 1, left.Column] = true;
                    }

                    Position right = new Position(Position.Row, Position.Column + 1);

                    if (Board.ValidPosition(right) && ThereIsAdversary(right) && Board.GetPiece(right) == Match.CanPassant)
                    {
                        mat[right.Row - 1, right.Column] = true;
                    }
                }
            }
            else
            {
                pos.SetPosition(Position.Row + 1, Position.Column);
                if (Board.ValidPosition(pos) && FreePosition(pos))
                {
                    mat[pos.Row, pos.Column] = true;
                }
                pos.SetPosition(Position.Row + 2, Position.Column);
                if (Board.ValidPosition(pos) && FreePosition(pos) && AmtMoviments == 0)
                {
                    mat[pos.Row, pos.Column] = true;
                }
                pos.SetPosition(Position.Row + 1, Position.Column - 1);
                if (Board.ValidPosition(pos) && ThereIsAdversary(pos))
                {
                    mat[pos.Row, pos.Column] = true;
                }
                pos.SetPosition(Position.Row + 1, Position.Column + 1);
                if (Board.ValidPosition(pos) && ThereIsAdversary(pos))
                {
                    mat[pos.Row, pos.Column] = true;
                }

                //#special moviment
                if (Position.Row == 4)
                {
                    Position left = new Position(Position.Row, Position.Column - 1);

                    if (Board.ValidPosition(left) && ThereIsAdversary(left) && Board.GetPiece(left) == Match.CanPassant)
                    {
                        mat[left.Row + 1, left.Column] = true;
                    }

                    Position right = new Position(Position.Row, Position.Column + 1);

                    if (Board.ValidPosition(right) && ThereIsAdversary(right) && Board.GetPiece(right) == Match.CanPassant)
                    {
                        mat[right.Row + 1, right.Column] = true;
                    }
                }
            }


            return(mat);
        }
Ejemplo n.º 7
0
 public bool FreePosition(Position pos)
 {
     return(Board.GetPiece(pos) == null);
 }
Ejemplo n.º 8
0
        public bool ThereIsAdversary(Position pos)
        {
            Piece p = Board.GetPiece(pos);

            return(p != null && p.Color != Color);
        }
Ejemplo n.º 9
0
        private bool CanMove(Position pos)
        {
            Piece p = Board.GetPiece(pos);

            return(p == null || p.Color != this.Color);
        }