ogarcia / opensudoku

Open Source Sudoku game for Android.
GNU General Public License v3.0
328 stars 144 forks source link

Develop #38

Closed steve3424 closed 4 years ago

steve3424 commented 5 years ago

I made 2 main changes:

  1. I modified the solver so it solves the game from the original state, ignoring user inputs. This allows it to always solve the puzzle and fill in the solution regardless of any mistakes on the board, removing the need for the ambiguous message saying there is a mistake somewhere in the puzzle.

  2. I added the hint feature. I made it slightly different from what we discussed. It simply fills in the correct value of the selected cell no matter what the state of the board is or how many mistakes there are. If the correct value is already in, the user will see nothing happen. I could add a message in this case or in others. Let me know if you'd want me to do that.

The hint feature as it is assumes 2 things to work:

  1. There is always a selected cell (which I think is true)
  2. The puzzle is solvable from its original state. This might not be true for user inputted puzzles, so it would be necessary to use the solver to check the new puzzles before they are saved to make sure they are solvable.
ogarcia commented 5 years ago

I see some improvements:

  1. Leave an error message when the puzzle cannot be solved with the solver. Something like: Puzzle cannot be solved, maybe it is irresoluble
  2. Give an error when ask for a hint in a irresoluble puzzle.
  3. If a read only cell is selected, disable Hint option or give an error message like You cannot get a hint for that cell.
steve3424 commented 5 years ago

Just some clarifications:

  1. Do you want this in there for user inputted puzzles instead of checking before they are saved? As it stands all of the default puzzles are solvable.
  2. Same as 1
  3. I will add this.
ogarcia commented 5 years ago

I think that show an error message is better because the puzzles can be imported from a file and in these cases if the imported file has errors the solver seems do nothing. What do you think?

steve3424 commented 5 years ago

It depends, are the imported files originally created in the app? If not, where do the puzzles from the files come from?

ogarcia commented 5 years ago

Yes, puzzles can be generated in other apps. Is a standard XML format implemented in first instance by GNOME team.

Sample:

<?xml version="1.0" encoding="UTF-8"?>
<opensudoku>
  <name>easy generated at 2019-10-01</name>
  <author>ogarcia</author>
  <description></description>
  <comment></comment>
  <created>2019-10-01</created>
  <source>opensudoku</source>
  <level>easy</level>
  <sourceURL>http://opensudoku.moire.org/</sourceURL>
  <game data="800400692429050070600900040000500060000030500006007000910305726250060801300020450" />
</opensudoku>

Is the puzzle in one line, the zeroes are the empty fields. For the sample of above the board is:

800 400 692
429 050 070
600 900 040

000 500 060
000 030 500
006 007 000

910 305 726
250 060 801
300 020 450
steve3424 commented 5 years ago

Unless there is a convenient way to check if these puzzles are solvable and flag them before they are imported, it would make sense for me to put a dialog in case these puzzles are not solvable. I will put that back in.

I also think it would be useful to check puzzles that are created in this app before they are saved, what do you think?

steve3424 commented 5 years ago

Now it checks whether or not the puzzle is solvable before giving hints and before completely solving the puzzle

ogarcia commented 5 years ago

I also think it would be useful to check puzzles that are created in this app before they are saved, what do you think?

That is a great idea. But I think even if the puzzle has not solution, it should permit to save it but warning to user: This puzzle has no solution. Are you sure you want save it?

steve3424 commented 5 years ago

Yeah that is a good idea. I will work on adding that.

ogarcia commented 4 years ago

I'll merge this PR to upload a new release with the import fix