Exemple #1
0
        public Knight(OwnerTypes owner, PiecePosition position) : base(owner, position)
        {
            Type = PieceTypes.Knight;
            name = "Knight";

            if (owner == OwnerTypes.Black)
            {
                Picture = new Bitmap(Properties.Resources.BlackHorse);
            }
            else
            {
                Picture = new Bitmap(Properties.Resources.WhiteHorse);
            }
        }
Exemple #2
0
        public Pawn(OwnerTypes owner, PiecePosition position) : base(owner, position)
        {
            Type = PieceTypes.Pawn;
            name = "Pawn";

            if (owner == OwnerTypes.Black)
            {
                Picture = new Bitmap(Properties.Resources.BlackPawn);
            }
            else
            {
                Picture = new Bitmap(Properties.Resources.WhitePawn);
            }
        }
Exemple #3
0
        public override List <PiecePosition> GetPossibileMoves(ChessTableSquare[,] table)
        {
            List <PiecePosition> moves = new List <PiecePosition>();

            for (int i = (int)Position.Column + 1, j = Position.Row + 1; i <= 8 & j <= 8; i++, j++) //UP-UP
            {
                var newPos = new PiecePosition(i, j);
                if (ValidateMove(newPos, table, 1))
                {
                    moves.Add(newPos);
                }
            }

            for (int i = (int)Position.Column - 1, j = (int)Position.Row + 1; i >= 1 && j <= 8; i--, j++) //DOWN-left
            {
                var newPos = new PiecePosition(i, j);
                if (ValidateMove(newPos, table, 2))
                {
                    moves.Add(newPos);
                }
                else
                {
                    break;
                }
            }

            for (int i = (int)Position.Column + 1, j = (int)Position.Row - 1; i <= 8 & j > 1; i++, j--) //up-down
            {
                var newPos = new PiecePosition(i, j);
                if (ValidateMove(newPos, table, 3))
                {
                    moves.Add(newPos);
                }
            }

            for (int i = (int)Position.Column - 1, j = (int)Position.Row - 1; i >= 1 && j >= 1; i--, j--) //up-left
            {
                var newPos = new PiecePosition(i, j);
                if (ValidateMove(newPos, table, 4))
                {
                    moves.Add(newPos);
                }
                else
                {
                    break;
                }
            }
            return(moves);
        }
Exemple #4
0
 public override bool Move(PiecePosition newPosition, ChessTableSquare[,] table)
 {
     //Check for for each of the 8 possibile moves by checking some argument first
     //For example the first move is bottom left, condition is row changed by 2, then if column changed by 1
     //Because the first part of an if (_&&_) is executed first, it suits perfectly
     if (ValidateMove(newPosition, table))
     {
         Position = newPosition;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #5
0
        public override void Move(PiecePosition newPosition, ChessTableSquare[,] table)
        {
            //Check for for each of the 8 possibile moves by checking some argument first
            //For example the first move is bottom left, condition is row changed by 2, then if column changed by 1
            //Because the first part of an if (_&&_) is executed first, it suits perfectly
            if (Math.Abs(newPosition.Row - Position.Row) == 2 && Math.Abs(newPosition.Column - Position.Column) == 1)
            {
                Position = newPosition;
                return;
            }
            if (Math.Abs(newPosition.Row - Position.Row) == 1 && Math.Abs(newPosition.Column - Position.Column) == 2)
            {
                Position = newPosition;
                return;
            }

            throw new IllegalMoveException(this, String.Format("Can not move from {0} to {1}", Position.ToString(), newPosition.ToString()));
        }
Exemple #6
0
        public override void Move(PiecePosition newPosition, ChessTableSquare[,] table)
        {
            if ((Math.Abs(newPosition.Column - Position.Column) == Math.Abs(newPosition.Row - Position.Row)) && Math.Abs(newPosition.Row - Position.Row) == 1)
            {
                Position = newPosition;
                return;
            }
            if ((newPosition.Row == Position.Row && newPosition.Column != Position.Column) && Math.Abs(newPosition.Column - Position.Column) == 1)
            {
                Position = newPosition;
                return;
            }

            if ((newPosition.Column == Position.Column && newPosition.Row != Position.Row) && Math.Abs(newPosition.Row - Position.Row) == 1)
            {
                Position = newPosition;
                return;
            }
            throw new IllegalMoveException(this, "Can not move to the new position: " + newPosition.ToString());
        }
 public PiecePosition(PiecePosition position)
 {
     Column = position.Column;
     Row    = position.Row;
 }
Exemple #8
0
 // TODO: add extra rule to check if there is no piece in the way of the piece movement: done for tower
 public abstract bool Move(PiecePosition newPosition, ChessTableSquare[,] table);
Exemple #9
0
 public Piece(PieceTypes type, OwnerTypes owner, PiecePosition position)
 {
     Owner    = owner;
     Type     = type;
     Position = position;
 }
Exemple #10
0
 public Piece(OwnerTypes owner, PiecePosition position)
 {
     Owner    = owner;
     Type     = PieceTypes.Undefined;
     Position = position;
 }
 public PieceLostEventArgs(Piece movedPiece, Piece overlappedPiece, PiecePosition beforePosition, PiecePosition afterPosition, string comment) : base(movedPiece, overlappedPiece, beforePosition, afterPosition, comment)
 {
 }
Exemple #12
0
        public override List <PiecePosition> GetPossibileMoves(ChessTableSquare[,] table)
        {
            List <PiecePosition> moves = new List <PiecePosition>();

            if ((int)Position.Column + 2 < 8 && Position.Row + 1 < 8)
            {
                var newPos = new PiecePosition(Position.Column + 2, Position.Row + 1);
                if (ValidateMove(newPos, table, 1))
                {
                    moves.Add(newPos);
                }
            }

            if ((int)Position.Column + 2 < 8 && Position.Row > 1)
            {
                var newPos = new PiecePosition(Position.Column + 2, Position.Row - 1);
                if (ValidateMove(newPos, table, 2))
                {
                    moves.Add(newPos);
                }
            }

            if ((int)Position.Column - 2 > 1 && Position.Row + 1 < 8)
            {
                var newPos = new PiecePosition(Position.Column - 2, Position.Row + 1);
                if (ValidateMove(newPos, table, 3))
                {
                    moves.Add(newPos);
                }
            }

            if ((int)Position.Column - 2 < 1 && Position.Row - 1 >= 1)
            {
                var newPos = new PiecePosition(Position.Column - 2, Position.Row - 1);
                if (ValidateMove(newPos, table, 4))
                {
                    moves.Add(newPos);
                }
            }

            if ((int)Position.Column + 1 <= 8 && Position.Row + 2 < 8)
            {
                var newPos = new PiecePosition(Position.Column + 1, Position.Row + 2);
                if (ValidateMove(newPos, table, 5))
                {
                    moves.Add(newPos);
                }
            }

            if ((int)Position.Column + 1 <= 8 && Position.Row - 2 >= 1)
            {
                var newPos = new PiecePosition(Position.Column + 1, Position.Row - 2);
                if (ValidateMove(newPos, table, 6))
                {
                    moves.Add(newPos);
                }
            }

            if ((int)Position.Column - 1 >= 1 && Position.Row + 2 < 8)
            {
                var newPos = new PiecePosition(Position.Column - 1, Position.Row + 2);
                if (ValidateMove(newPos, table, 7))
                {
                    moves.Add(newPos);
                }
            }

            if ((int)Position.Column - 1 >= 1 && Position.Row - 2 >= 1)
            {
                var newPos = new PiecePosition(Position.Column - 1, Position.Row - 2);
                if (ValidateMove(newPos, table, 8))
                {
                    moves.Add(newPos);
                }
            }
            return(moves);
        }
Exemple #13
0
        public override bool ValidateMove(PiecePosition newPosition, ChessTableSquare[,] table, int direction = 0)
        {
            if (!base.ValidateMove(newPosition, table, direction))
            {
                return(false);
            }


            if (direction == 0 && Position.Row == newPosition.Row && Position.Column == newPosition.Column)
            {
                return(false);
            }

            if ((direction == 0 || direction == 1) &&
                newPosition.Row == Position.Row + 1 && newPosition.Column == Position.Column + 2)
            {
                return(true);
            }

            if ((direction == 0 || direction == 2) &&
                newPosition.Row == Position.Row - 1 && newPosition.Column == Position.Column + 2)
            {
                return(true);
            }

            if ((direction == 0 || direction == 3) &&
                newPosition.Row == Position.Row + 1 && newPosition.Column == Position.Column - 2)
            {
                return(true);
            }

            if ((direction == 0 || direction == 4) &&
                newPosition.Row == Position.Row - 1 && newPosition.Column == Position.Column - 2)
            {
                return(true);
            }

            if ((direction == 0 || direction == 5) &&
                newPosition.Row == Position.Row + 2 && newPosition.Column == Position.Column + 1)
            {
                return(true);
            }

            if ((direction == 0 || direction == 6) &&
                newPosition.Row == Position.Row - 2 && newPosition.Column == Position.Column + 1)
            {
                return(true);
            }

            if ((direction == 0 || direction == 7) &&
                newPosition.Row == Position.Row + 2 && newPosition.Column == Position.Column - 1)
            {
                return(true);
            }

            if ((direction == 0 || direction == 8) &&
                newPosition.Row == Position.Row - 2 && newPosition.Column == Position.Column - 1)
            {
                return(true);
            }
            return(false);
        }