Exemplo n.º 1
0
        private ArrayList EnumSingleMovesCore(Point fromLocation, bool optionalJumping, ArrayList jumpMoves)
        {
            // Create resizable list of jumpable moves and their respective jumps
            ArrayList moves = new ArrayList();

            // Check for single moves, if not jumping already took place
            if (path.Count > 0)
            {
                return(moves);
            }

            bool canSingleMove = true;

            if (!optionalJumping)
            {
                // Determine whether or not a single jump can take place
                canSingleMove = (jumpMoves.Count == 0) || (game.OptionalJumping);
                if (canSingleMove)
                {
                    // Further testing for single moves; test all other pieces on the board
                    foreach (CheckersPiece testPiece in game.EnumPlayerPieces(game.Turn))
                    {
                        ArrayList dummy;
                        if (EnumJumpMovesCore(testPiece, testPiece.Location, out dummy).Count == 0)
                        {
                            continue;
                        }
                        canSingleMove = false;
                        break;
                    }
                }
            }

            // Check whether or not a single move can take place
            if (!canSingleMove)
            {
                return(moves);
            }

            // Append single-move moves in the enumeration (if able to)
            if (piece.Location == fromLocation)
            {
                if ((piece.Direction == CheckersDirection.Up) || (piece.Rank == CheckersRank.King))
                {
                    if (InBounds(fromLocation.X - 1, fromLocation.Y - 1) && (board[fromLocation.X - 1, fromLocation.Y - 1] == null))
                    {
                        moves.Add(new Point(fromLocation.X - 1, fromLocation.Y - 1));
                    }
                    if (InBounds(fromLocation.X + 1, fromLocation.Y - 1) && (board[fromLocation.X + 1, fromLocation.Y - 1] == null))
                    {
                        moves.Add(new Point(fromLocation.X + 1, fromLocation.Y - 1));
                    }
                }
                if ((piece.Direction == CheckersDirection.Down) || (piece.Rank == CheckersRank.King))
                {
                    if (InBounds(fromLocation.X - 1, fromLocation.Y + 1) && (board[fromLocation.X - 1, fromLocation.Y + 1] == null))
                    {
                        moves.Add(new Point(fromLocation.X - 1, fromLocation.Y + 1));
                    }
                    if (InBounds(fromLocation.X + 1, fromLocation.Y + 1) && (board[fromLocation.X + 1, fromLocation.Y + 1] == null))
                    {
                        moves.Add(new Point(fromLocation.X + 1, fromLocation.Y + 1));
                    }
                }
            }
            return(moves);
        }