Ejemplo n.º 1
0
        /// <summary>
        /// Event handler for the work completed event.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">Completed event arguments.</param>
        void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            // Check if this is a previous worker
            if (this.solveGameButton.Content.Equals("Solve Game"))
            {
                return;
            }

            // Update the button text
            this.solveGameButton.Content = "Solve Game";

            // Update the gameboard and the control if the board is solvable
            if (success)
            {
                this.gameBoard = solver.board;
                this.boardControl.updateBoard(this.gameBoard);

                // Update the status label
                this.statusLabel.Content = "Solved!";
            }
            else
            {
                // Update the status label
                this.statusLabel.Content = "Unsolvable!";
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parses the file contents into an object of type SBoard.
        /// </summary>
        /// <param name="fileName">Name and path of the file to be parsed.</param>
        /// <returns>A board object containing the puzzle data.</returns>
        public static SBoard parseFile(string fileName)
        {
            string input = File.ReadAllText(fileName);
            SBoard board = new SBoard();

            int currentCharIndex = 0;

            for (int row = 0; row < SBoard.ROW_SIZE; row++)
            {
                for (int col = 0; col < SBoard.COL_SIZE; col++)
                {
                    int value = -1;
                    while (value == -1)
                    {
                        if (input[currentCharIndex] >= ZERO && input[currentCharIndex] <= NINE)
                        {
                            int.TryParse(input[currentCharIndex].ToString(), out value);
                        }
                        else if (input[currentCharIndex] == DOT)
                        {
                            value = 0;
                        }
                        currentCharIndex++;
                    }
                    board.setCell(value, row, col);
                }
            }

            return(board);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handles solving the gameboard.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">Routed event arguments.</param>
        private void solveGameButton_Click(object sender, RoutedEventArgs e)
        {
            // Change button text
            if (solveGameButton.Content.Equals("Cancel"))
            {
                this.solveGameButton.Content = "Solve Game";
            }
            else
            {
                this.solveGameButton.Content = "Cancel";
            }

            // Get the updated gameboard from the board control
            this.gameBoard = this.boardControl.getUpdatedBoard();

            // Solve the gameboard
            this.solver = new SSolver(this.gameBoard);

            // Update the status label
            this.statusLabel.Content = "Solving...";

            // Check if the background worker is already running. Run
            // the solver on the background worker otherwise
            if (bw.IsBusy)
            {
                // Dispose of the current background worker and stop
                // the thread
                this.disposeBackgroundWorker();
                this.statusLabel.Content = "Canceled!";
            }
            else
            {
                bw.RunWorkerAsync();
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Updates the board cell controls using the model board object.
 /// </summary>
 /// <param name="board">Board model object containing the board data.</param>
 public void updateBoard(SBoard board)
 {
     for (int row = 0; row < SBoard.ROW_SIZE; row++)
     {
         for (int col = 0; col < SBoard.COL_SIZE; col++)
         {
             boardControl[row, col].setValue(board.getCell(row, col).Value);
         }
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns the up-to-date version of the game board.
        /// </summary>
        /// <returns>The up-to-date version of the game board.</returns>
        public SBoard getUpdatedBoard()
        {
            SBoard updatedBoard = new SBoard();

            for (int row = 0; row < SBoard.ROW_SIZE; row++)
            {
                for (int col = 0; col < SBoard.COL_SIZE; col++)
                {
                    updatedBoard.setCell(boardControl[row, col].getValue(), row, col);
                }
            }

            return(updatedBoard);
        }
Ejemplo n.º 6
0
        private IChessEngine CreateTarget()
        {
            var engine = new SBoard();

            return(engine);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Updates the game board from a file.
 /// </summary>
 /// <param name="fileName">Name and path of the file to load the game from.</param>
 private void updateGameBoardFromFile(string fileName)
 {
     this.gameBoard = SParser.parseFile(fileName);
     this.boardControl.updateBoard(this.gameBoard);
 }