Exemple #1
0
            private void InitValidations()
            {
                _validations = new List <FuncEnumPair <Point, Statuses> >
                {
                    new FuncEnumPair <Point, Statuses>((origin, dest) =>
                                                       !(ChessUtils.IsValidPosition(origin) && ChessUtils.IsValidPosition(origin)),
                                                       Statuses.Invalid_Indexes),

                    new FuncEnumPair <Point, Statuses>((origin, dest) =>
                                                       Board.At(origin)?.Player != CurrPlayer,
                                                       Statuses.Invalid_OriginIsNotCurrentPlayerPiece),

                    new FuncEnumPair <Point, Statuses>((origin, dest) =>
                                                       Board.At(dest)?.Player == CurrPlayer,
                                                       Statuses.Invalid_DestIsCurrentPlayerPiece),

                    new FuncEnumPair <Point, Statuses>((origin, dest) =>
                                                       origin.Equals(dest),
                                                       Statuses.Invalid_OriginIsEqualToDest),

                    new FuncEnumPair <Point, Statuses>((origin, dest) =>
                                                       !Board.At(origin).GetPossibleMoves(Board).Contains(dest),
                                                       Statuses.Invalid_PieceMovement),

                    new FuncEnumPair <Point, Statuses>((origin, dest) =>
                                                       Board.At(origin).GetPossibleMoves(Board).Contains(dest),
                                                       Statuses.Valid)
                };
            }
Exemple #2
0
        private static IEnumerable <Point> GetSurroundingPositions(Point point, int xIncrementor, int yIncrementor)
        {
            var points = new Point[]
            {
                new Point(point.X + xIncrementor, point.Y + yIncrementor),
                new Point(point.X - xIncrementor, point.Y - yIncrementor)
            };

            return(points.Where(surroundingPoint => ChessUtils.IsValidPosition(surroundingPoint)));
        }
Exemple #3
0
        private static IEnumerable <Point> GetLinePossibleMoves(Piece piece, Piece[][] board,
                                                                int loopXIncrementor, int loopYIncrementor)
        {
            ICollection <Point> possibleMoves = new List <Point>();

            if (loopXIncrementor == 0 && loopYIncrementor == 0)
            {
                throw new ArgumentException();
            }

            var iterator = 1;

            while (ChessUtils.IsValidPosition(piece.Position.X + loopXIncrementor * iterator,
                                              piece.Position.Y + loopYIncrementor * iterator))
            {
                var xPos = piece.Position.X + loopXIncrementor * iterator;
                var yPos = piece.Position.Y + loopYIncrementor * iterator;

                if (board[yPos][xPos] == null)
                {
                    possibleMoves.Add(new Point(xPos, yPos));
                }
                else
                {
                    if (board[yPos][xPos].Player != piece.Player)
                    {
                        possibleMoves.Add(new Point(xPos, yPos));
                        break;
                    }
                    else
                    {
                        break;
                    }
                }

                iterator++;
            }
            return(possibleMoves);
        }