sudokuexplainer clone, SINGLESONLY, solver,generator, c src

Programs which generate, solve, and analyze Sudoku puzzles

sudokuexplainer clone, SINGLESONLY, solver,generator, c src

Postby 1to9only » Sun Nov 18, 2018 4:24 pm

[Introduction: A C/C++ SudokuExplainer replacement was discussed many many years ago here: http://forum.enjoysudoku.com/team-project-c-or-c-explainer-like-rating-program-t30083.html.]

This is from one of my attempts to write a SudokuExplainer clone, the project was to explore how to implement a SudokuExplainer clone in C. This was done, and further developement has now stopped. I'm busy with other stuff.

I've added a simple(!) sudoku generator, tidied the code a bit, and released all under version 3 of the GNU General Public License (GPLv3):

"This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version."

"This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details."

If you do not agree with the terms of the GPLv3 license: https://www.gnu.org/licenses/, please do not download this program.

The program (seclone.exe) generates, solves and rates (a single) sudoku that needs singles only to solve. The singles solving code is converted from SudokuExplainer. Sudokus requiring other (not implemented) solving techniques are given a rating of 0.0.

The code has bits I've borrowed from elsewhere, but it's mostly my own. It's coded for speed(!), using global variables (no parameters in function calls) and similar code are repeated (no function calls). There are numerous areas where the code can be improved. As with free software, there is no support!

Some usage information is provided below (this is all the documentation!):

To generate a sudoku [-g generate option]:
Code: Select all
seclone.exe -g

To generate a sudoku, redirecting the output to a file (puzzle.txt):
Code: Select all
seclone.exe -g > puzzle.txt

Example puzzle.txt:
Code: Select all
7..1.2...3..6.74....9.......85........6.1..7........8..5....2...3.5........84.61.
ED=2.3/1.2/1.2


To solve/rate a sudoku [no option specified]:
Code: Select all
seclone.exe 7..1.2...3..6.74....9.......85........6.1..7........8..5....2...3.5........84.61.

Code: Select all
seclone.exe puzzle.txt

Example output:
Code: Select all
748152369312697458569384721285739146496218573173465982851976234634521897927843615
ED=2.3/1.2/1.2


To solve a sudoku (with hints output) [-s solve option]:
Code: Select all
seclone.exe -s 7..1.2...3..6.74....9.......85........6.1..7........8..5....2...3.5........84.61.

Code: Select all
seclone.exe -s puzzle.txt

Example output:
Hidden Text: Show
7..1.2...3..6.74....9.......85........6.1..7........8..5....2...3.5........84.61.
1.2, hidden single: r3c1: 5 in block
1.2, hidden single: r6c3: 3 in block
1.2, hidden single: r6c2: 7 in block
1.2, hidden single: r5c6: 8 in block
1.2, hidden single: r8c5: 2 in block
1.2, hidden single: r9c9: 5 in block
1.5, hidden single: r6c6: 5 in column
1.2, hidden single: r5c7: 5 in block
1.5, hidden single: r9c6: 3 in row
1.5, hidden single: r9c3: 7 in row
1.5, hidden single: r2c3: 2 in column
1.2, hidden single: r1c3: 8 in block
1.5, hidden single: r1c2: 4 in row
1.2, hidden single: r3c2: 6 in block
1.0, hidden single: r2c2: 1 in block
2.3, naked single: r3c6: 4
2.3, naked single: r3c4: 3
1.2, hidden single: r4c5: 3 in block
1.2, hidden single: r4c4: 7 in block
1.2, hidden single: r5c9: 3 in block
1.2, hidden single: r7c5: 7 in block
1.2, hidden single: r7c8: 3 in block
1.2, hidden single: r1c7: 3 in block
1.5, hidden single: r6c5: 6 in column
2.3, naked single: r3c5: 8
1.2, hidden single: r2c9: 8 in block
1.2, hidden single: r8c7: 8 in block
1.2, hidden single: r7c1: 8 in block
1.2, hidden single: r8c1: 6 in block
1.2, hidden single: r7c6: 6 in block
1.2, hidden single: r8c6: 1 in block
1.0, hidden single: r7c4: 9 in block
1.0, hidden single: r4c6: 9 in column
1.2, hidden single: r7c3: 1 in block
1.0, hidden single: r8c3: 4 in column
1.0, hidden single: r7c9: 4 in row
1.2, hidden single: r4c8: 4 in block
1.2, hidden single: r4c9: 6 in block
1.2, hidden single: r1c8: 6 in block
1.2, hidden single: r2c8: 5 in block
1.0, hidden single: r2c5: 9 in row
1.0, hidden single: r1c5: 5 in block
1.0, hidden single: r1c9: 9 in row
1.2, hidden single: r6c9: 2 in block
1.2, hidden single: r3c8: 2 in block
1.0, hidden single: r8c8: 9 in column
1.0, hidden single: r8c9: 7 in block
1.0, hidden single: r3c9: 1 in column
1.0, hidden single: r3c7: 7 in block
1.2, hidden single: r5c4: 2 in block
1.0, hidden single: r6c4: 4 in block
1.2, hidden single: r4c1: 2 in block
1.0, hidden single: r4c7: 1 in row
1.0, hidden single: r6c7: 9 in block
1.0, hidden single: r6c1: 1 in row
1.2, hidden single: r5c1: 4 in block
1.0, hidden single: r5c2: 9 in block
1.0, hidden single: r9c1: 9 in column
1.0, hidden single: r9c2: 2 in block
748152369312697458569384721285739146496218573173465982851976234634521897927843615
ED=2.3/1.2/1.2

The solution is 'exactly' as SudokuExplainer's solution, as verifed using the hints produced by SukakuExplainer from here: http://forum.enjoysudoku.com/help-with-sudoku-explainer-t6677-60.html#p271963.

To solve a sudoku (with pencilmarks output) [-v verbose option]:
Code: Select all
seclone.exe -v 7..1.2...3..6.74....9.......85........6.1..7........8..5....2...3.5........84.61.

Code: Select all
seclone.exe -v puzzle.txt

The output is best redirected to a file for viewing!

The code compiles with TCC (Tiny C Compiler: https://bellard.org/tcc/), using tcc version 0.92.27 downloaded from github: https://github.com/TinyCC/tinycc/releases.

To build seclone.exe:
Code: Select all
tcc seclone.c
Attachments
seclone.zip
unzip for seclone.exe
(7 KiB) Downloaded 30 times
seclone_src.zip
seclone source files
(25.82 KiB) Downloaded 36 times
1to9only
 
Posts: 1005
Joined: 04 April 2018

Re: sudokuexplainer clone, SINGLESONLY, solver,generator, c

Postby 1to9only » Thu Jan 03, 2019 10:44 am

I see the source code has been downloaded a number of times, hope it's been useful. Here are some possible modifications:

To generate symmetric (180 rotational) puzzles, change the '// add a clue' section with the '// add 2 clues' code below:
Hidden Text: Show
Code: Select all
      // add 2 clues

      int addingclue = True;
      while ( addingclue == True )
      {
         int c1 = rand() % 81;               // random cell, 0-80
         int c2 = Sudsize - c1 - 1;          // 180 rotational

         if ( gen_grid[ c1] == 0             // cell is empty?
           && gen_grid[ c2] == 0 )           // cell is empty?
         {
            int n1 = rand() % 9 + 1;         // random number, 1-9
            int n2 = rand() % 9 + 1;         // random number, 1-9

            if ( n1 != n2                       // number not same?
              && gen_clues[ c1] & mbits[ n1]    // number is a candidate?
              && gen_clues[ c2] & mbits[ n2] )  // number is a candidate?
            {
               if ( c1 != c2 )                  // not center cell
               {
                  gen_grid[ c1] = n1;           // set clue
                  gen_clues[ c1] = 0;           // clear clue
                  for (int k=1; k<21; k++ )     // clear peers
                  {
                     gen_clues[ peer[ c1][ k]] &= ~mbits[ n1];
                  }
                  numclues++;
               }

               gen_grid[ c2] = n2;           // set clue
               gen_clues[ c2] = 0;           // clear clue
               for (int k=1; k<21; k++ )     // clear peers
               {
                  gen_clues[ peer[ c2][ k]] &= ~mbits[ n2];
               }
               numclues++;

               addingclue = False;
            }
         }
      }

For puzzles with diagonal symmetry, change the '// 180 rotational' line with the '// diagonal' line below:
Hidden Text: Show
Code: Select all
   int c2 = 81 - (9*(c1%9) + (c1/9)) - 1;    // diagonal

For puzzles with antidiagonal symmetry, change the '// 180 rotational' line with the '// antidiagonal' line below:
Hidden Text: Show
Code: Select all
   int c2 =       9*(c1%9) + (c1/9);         // antidiagonal
1to9only
 
Posts: 1005
Joined: 04 April 2018

6x6 sudoku puzzles, SINGLESONLY, solver,generator, NO src

Postby 1to9only » Fri Jan 11, 2019 10:55 am

It's an interesting exercise to modify the source code from post#1 for 6x6 sudoku puzzles - after having recently modified SudokuExplainer to solve/rate 6x6 sudoku puzzles, see here.

For usage, see post#1 - replacing with s6clone.exe. I've made a few cosmetic changes to this program! In testing, I generated a batch of just under 6000 puzzles producing some (241) 9-clue puzzles, less (23) ED=2.3/1.2/1.2 rated puzzles, and even less (7) 8-clue puzzles. More testing, another batch of just over 5000 puzzles producing a lone (1) 12-clue ED=2.3/1.5/1.5 rated puzzle! All puzzles can be solved with singles only, e.g.

Code: Select all
2...36....2..14...5....4.5...1...65. #12 ED=2.3/1.5/1.5

Hidden Text: Show
Code: Select all
2...36....2..14...5....4.5...1...65.
1.5, hidden single: r4c5: 1 in column
1.2, hidden single: r3c5: 6 in block
1.0, hidden single: r5c5: 4 in column
2.3, naked single: r1c2: 4
1.2, hidden single: r2c4: 4 in block
1.2, hidden single: r1c4: 1 in block
1.0, hidden single: r2c6: 5 in block
1.0, hidden single: r1c3: 5 in row
1.2, hidden single: r3c4: 5 in block
1.2, hidden single: r6c1: 4 in block
1.2, hidden single: r6c3: 1 in block
1.2, hidden single: r2c1: 1 in block
1.5, hidden single: r5c1: 6 in column
1.0, hidden single: r3c1: 3 in column
1.0, hidden single: r3c6: 2 in row
1.0, hidden single: r4c4: 3 in block
1.0, hidden single: r5c4: 2 in column
1.0, hidden single: r6c6: 3 in block
1.0, hidden single: r5c3: 3 in row
1.0, hidden single: r6c2: 2 in block
1.2, hidden single: r2c2: 3 in block
1.0, hidden single: r2c3: 6 in block
1.0, hidden single: r4c2: 6 in column
1.0, hidden single: r4c3: 2 in block
245136136425314562562314653241421653
ED=2.3/1.5/1.5

No source! As mentioned, it's an interesting project...
Attachments
s6clone.zip
for 6x6 sudoku, unzip for s6clone.exe
(5.09 KiB) Downloaded 24 times
1to9only
 
Posts: 1005
Joined: 04 April 2018

Re: sudokuexplainer clone, SINGLESONLY, solver,generator, c

Postby tarek » Thu Jan 17, 2019 3:14 pm

1to9only wrote:It's an interesting exercise to modify the source code from post#1 for 6x6 sudoku puzzles - after having recently modified SudokuExplainer to solve/rate 6x6 sudoku puzzles

Thanks for your effort. You and others have certainly re-energized this forum with very helpful contributions recently

tarek
User avatar
tarek
 
Posts: 2966
Joined: 05 January 2006

Re: sudokuexplainer clone, SINGLESONLY, solver,generator, c

Postby tarek » Sun Jan 20, 2019 12:33 pm

I will try to contribute to your effort here 1to9only & if I have time to others efforts too

1to9only wrote:To generate symmetric (180 rotational) puzzles, change the '// add a clue' section with the '// add 2 clues' code below


I've modified it slightly;
180 symmetry code: Show
Code: Select all
      // add 2 clues

      int addingclue = True;
      while ( addingclue == True )
      {
         int c1 = rand() % 41;               // random cell
         int c2 = Sudsize - c1 - 1;          // 180 rotational symmetry

         if ( gen_grid[ c1] == 0 )            // cell is empty?
         {
            int n1 = rand() % 9 + 1;         // random number, 1-9
            int n2 = rand() % 9 + 1;         // random number, 1-9

            if ( gen_clues[ c1] & mbits[ n1]    // number is a candidate?
              && gen_clues[ c2] & mbits[ n2] )  // number is a candidate?
            {
               if ( c1 != c2 )                  // not symmetrize to same cell
               {
                  gen_grid[ c2] = n2;           // set clue
                  gen_clues[ c2] = 0;           // clear clue
                  for (int k=1; k<21; k++ )     // clear peers
                  {
                     gen_clues[ peer[ c2][ k]] &= ~mbits[ n2];
                  }
                  numclues++;
               }

               gen_grid[ c1] = n1;           // set clue
               gen_clues[ c1] = 0;           // clear clue
               for (int k=1; k<21; k++ )     // clear peers
               {
                  gen_clues[ peer[ c1][ k]] &= ~mbits[ n1];
               }
               numclues++;

               addingclue = False;
            }
         }
      }


Replace \\random cell & \\180 rotational symmetry with the desired symmetry code

main diagonal symmetry: Show
Code: Select all
        int c2 =   rand() % 9;                  // random cell (diagonal pool) 1st step
      int c1 =    9 * c2 + rand() % (9 - c2);     // random cell (diagonal pool) 2nd step   
      c2 = 81 - (9 * (c1 % 9) + (c1 / 9)) - 1;    // diagonal symmetry

anti diagonal symmetry: Show
Code: Select all
        int c2 =   rand() % 9;                  // random cell (anti diagonal pool) 1st step
      int c1 =    9 * c2 + c2 + rand() % (9 - c2);    // random cell (anti diagonal pool) 2nd step   
      c2 = 9*(c1%9) + (c1/9);                  // anti diagonal symmetry

Horizontal symmetry: Show
Code: Select all
        int c1 =   rand() % 45;                  // random cell (Horizontal pool)
      int c2 =   9 * (8 - (c1 / 9)) + c1 % 9;         // Horizontal plane symmetry

Vertical symmetry: Show
Code: Select all
        int c2 =   rand() % 9;            // random cell (vertical pool) 1st step
      int c1 =    9 * c2 + rand() % 5;    // random cell (vertical pool) 2nd step   
      c2 = 9 * (c1 / 9) + (8 - c1 % 9);   // verticl plane symmetry


I removed the need to have different candidates for a symmetrical pairing. This will obviously cause an immediate conflict if they exist in the same Line or Box

I'll add the clunky 4-way symmetries following the same code later today

tarek
User avatar
tarek
 
Posts: 2966
Joined: 05 January 2006

Re: sudokuexplainer clone, SINGLESONLY, solver,generator, c

Postby 1to9only » Sun Jan 20, 2019 3:45 pm

tarek wrote:I removed the need to have different candidates for a symmetrical pairing. This will obviously cause an immediate conflict if they exist in the same Line or Box

A pitfall to be wary of! Ideally, there should be additional code to avoid this conflict. I'll leave this to the person using this code.

Tarek, thanks for your contributions.

[Edit] I admit this is not good code! Looking at past code, I did something like this [pseudocode]:
Code: Select all
select cell1
select cell2
if cell1 and cell2 empty
   select number1 from available cell1 candidates
   apply
if cell1 not cell2 [i.e. not center cell]
   select number2 from avalible cell2 candidates
   apply

The issue highlighted by tarek does not arise!
Last edited by 1to9only on Sun Jan 20, 2019 6:53 pm, edited 1 time in total.
1to9only
 
Posts: 1005
Joined: 04 April 2018

Re: secloneX, SINGLESONLY, solver,generator, NO src

Postby 1to9only » Sun Jan 20, 2019 3:56 pm

It's another interesting exercise to modify the source code from post#1 for sudoku-X puzzles.

For usage, see post#1 - replacing with secloneX.exe. This program solves the very easy sudoku-x puzzle posted by m_b_metcalf in Puzzles related to Patterns Game patterns.
Code: Select all
.....5..3.9.....5...5.2.7......7..4...15..9..8....3..1..9.6.....4.8...7.2....7..6 pg 0130, x-sudoku, v. easy
..1..4..7....7..5.7..2..4....31....5.4.....6.5.....7....9..7..6.1..6....3..8..1.. pg 0133, x-sudoku, v. easy
..1..7.9.....4...13..8..7....86..4...2..1....4....3.....45....31......8..8....9.. pg 0141, x-sudoku, very easy
...2..3.8...1.8.5.....93..442....96...3...4...86....236..51.....3.4.6...2.1..7... pg 0142, x-sudoku, very easy
.....9..6..2.1..9..6.2..4....4....5..9..5...75....81....1..56...8.9...2.7...3.... pg 0146, x-sudoku, very easy
7.....4...2..8......8..1..2.....45...4..9..6...25....75..4.........1..5...7..9..4 pg 0147, x-sudoku, very easy
.....3..1..8....6..3..4.8.....2....6..6.51.3.1...9.2....7..2..9.9..7..4.2..4..1.. pg 0249, x-sudoku, v. easy
.6.3...9.1...7...8..8...3..5..9.4.......6.......7.5..6..2...1..3...4...5.1...3.6. pg 0250, x-sudoku, v. easy

Except that the pg 0250 sudoku-X requires more that singles to solve!!

No source! This is another interesting (and tougher) project...

Undocumented option: This program (and the previous sudoku 6x6 program as well) has a -gg option that (after a new grid is generated) also dumps it in 'nice' format! E.g. secloneX.exe -gg
Code: Select all
6..9...1........24............3.7...2...1..5..4.....671............2....8..7..... #X17 ED=2.3/1.2/1.2
+-------+-------+-------+
| 6 . . | 9 . . | . 1 . |
| . . . | . . . | . 2 4 |
| . . . | . . . | . . . |
+-------+-------+-------+
| . . . | 3 . 7 | . . . |
| 2 . . | . 1 . | . 5 . |
| . 4 . | . . . | . 6 7 |
+-------+-------+-------+
| 1 . . | . . . | . . . |
| . . . | . 2 . | . . . |
| 8 . . | 7 . . | . . . |
+-------+-------+-------+

In the #XNN shown, X denotes a sudoku-X, and NN is the number of givens.

Enjoy!
Attachments
secloneX.zip
for sudoku-X. unzip for secloneX.exe
(8.43 KiB) Downloaded 19 times
1to9only
 
Posts: 1005
Joined: 04 April 2018

Re: sudokuexplainer clone, SINGLESONLY, solver,generator, c

Postby tarek » Sun Jan 20, 2019 9:04 pm

1to9only wrote:[Edit] I admit this is not good code! Looking at past code, I did something like this [pseudocode]:
Code: Select all
select cell1
select cell2
if cell1 and cell2 empty
   select number1 from available cell1 candidates
   apply
if cell1 not cell2 [i.e. not center cell]
   select number2 from avalible cell2 candidates
   apply

The issue highlighted by tarek does not arise!


As I haven't tested nor looked at the full code yet, I played it safe with another replacement code:

Code: Select all
while ( (gen_clues[ c2] & mbits[ n2]) == 0)
when it could be:
while (!(gen_clues[ c2] & mbits[ n2]))


Here is the replacement code again!

180 symmetry code adjusted: Show
Code: Select all
    // add 2 clues
    int addingclue = True;
    while ( addingclue == True )
    {
// to change symmetry type replace the following lines with the desired 2-way symmetry type
        int c1 = rand() % 41;                       // random cell
        int c2 = Sudsize - c1 - 1;                  // 180 rotational symmetry
// to change symmetry type replace the above lines with the desired 2-way symmetry type
        if ( gen_grid[c1] == 0 )                    // cell is empty?
        {
            int n1 = rand() % 9 + 1;
            int n2 = rand() % 9 + 1;                // random number, 1-9
            if ( c1 != c2 )                         // not symmetrize to same cell
            {
                while ( (gen_clues[c2] & mbits[n2]) == 0)
                {
                    n2 = rand() % 9 + 1;            // making sure number is candidate
                }
                gen_grid[c2] = n2;                  // set clue
                gen_clues[c2] = 0;                  // clear clue
                for (int k = 1; k < 21; k++ )       // clear peers
                {
                    gen_clues[peer[c2][k]] &= ~mbits[n2];
                }
                numclues++;
            }
            while ( (gen_clues[c1] & mbits[n1]) == 0)
            {
                n1 = rand() % 9 + 1;                // making sure number is candidate
            }
            gen_grid[c1] = n1;                      // set clue
            gen_clues[c1] = 0;                      // clear clue
            for (int k = 1; k < 21; k++ )           // clear peers
            {
                gen_clues[peer[c1][k]] &= ~mbits[n1];
            }
            numclues++;
            addingclue = False;
        }
    }


And here is a 4-way symmetry (I lost interest after this and didn't continue :D ). Again trying to remain as faithful to the original code

Double orthogonal symmetry: Show
Code: Select all
    // add 4 clues
    int addingclue = True;
    while ( addingclue == True )
    {
// to change symmetry type replace the following lines with the desired 4-way symmetry type
        int c3 = rand() % 5;                        // random cell (double orthogonal pool) 1st step
        int c1 = 9 * c3 + rand() % 5;               // random cell (double orthogonal pool) 2nd step   
        c3 = Sudsize - c1 - 1;                      // double orthogonal plane symmetry
        int c2 = 9 * (8 - (c1 / 9)) + c1 % 9;       // double orthogonal plane symmetry
        int c4 = 9 * (c1 / 9) + (8 - c1 % 9);       // double orthogonal plane symmetry
        c3 = Sudsize - c1 - 1;                      // double orthogonal plane symmetry
// to change symmetry type replace the above lines with the desired 4-way symmetry type
        if ( gen_grid[c1] == 0 )                    // cell is empty?
        {
            int n1 = rand() % 9 + 1;                // random number, 1-9
            int n2 = rand() % 9 + 1;                // random number, 1-9
            int n3 = rand() % 9 + 1;                // random number, 1-9
            int n4 = rand() % 9 + 1;                // random number, 1-9
            if ( c1 != c3 )                         // no 4-way symmetry to same cell
            {
                if ( c1 != c2  &&                   // no 2-way symmetry to same cell
                     c1 != c4 )                     // no 2-way symmetry to same cell
                {
                    while ( (gen_clues[c2] & mbits[n2]) == 0)
                    {
                        n2 = rand() % 9 + 1;        // making sure number is candidate
                    }
                    gen_grid[c2] = n2;              // set clue
                    gen_clues[c2] = 0;              // clear clue
                    for (int k = 1; k < 21; k++ )   // clear peers
                    {
                        gen_clues[peer[c2][k]] &= ~mbits[n2];
                    }
                    numclues++;
                    while ( (gen_clues[c4] & mbits[n4]) == 0)
                    {
                        n4 = rand() % 9 + 1;        // making sure number is candidate
                    }
                    gen_grid[c4] = n4;              // set clue
                    gen_clues[c4] = 0;              // clear clue
                    for (int k = 1; k  <21; k++ )   // clear peers                 
                    {
                        gen_clues[peer[c4][k]] &= ~mbits[n4];
                    }
                    numclues++;
                }
                while ( (gen_clues[c3] & mbits[n3]) == 0)
                {
                    n3 = rand() % 9 + 1;            // making sure number is candidate
                }
                gen_grid[c3] = n3;                  // set clue
                gen_clues[c3] = 0;                  // clear clue
                for (int k = 1; k < 21; k++ )       // clear peers
                {
                    gen_clues[peer[c3][k]] &= ~mbits[n3];
                }
                numclues++;
            }
            while ( (gen_clues[c1] & mbits[n1]) == 0)
            {
                n1 = rand() % 9 + 1;                // making sure number is candidate
            }
            gen_grid[c1] = n1;                      // set clue
            gen_clues[c1] = 0;                      // clear clue
            for (int k = 1; k < 21; k++ )           // clear peers
            {
              gen_clues[peer[c1][k]] &= ~mbits[n1];
            }
            numclues++;
            addingclue = False;
        }
    }
User avatar
tarek
 
Posts: 2966
Joined: 05 January 2006

Re: sudokuexplainer clone, SINGLESONLY, solver,generator, c

Postby 1to9only » Tue Jan 22, 2019 9:45 am

Tarek, thanks for your input. At some point in the future I may want to reissue the code with options to generate symmetric puzzles.

The code to update the grid and clues should be in a separate function, this will help with future code changes!

After the secloneX program, adding other variants is possible, NC would be easiest, the rest will require more coding! I have an s6cloneX program, which I'll post soon!

I've also looked into creating jigsaw puzzles, this requires changes to some of the static tables, here's a jigsaw (singles only) I created earlier:
Code: Select all
........1..7..9..5...........36...48.5....8....1.3....1....7...2..4.3.....8...5.. #JA19 ED=2.3/1.2/1.2
+-----------+---------------+-------+
| .   .   . | .   .   .   . | .   1 |
|           |               |       |
| .   .   7 | .   .   9   . | .   5 |
|       +---+---+---+   +---+       |
| .   . | .   . | . | . | .   .   . |
|   +---+       |   +---+---+       |
| . | .   3   6 | .   . | . | 4   8 |
+---+       +---+       |   +-------+
| .   5   . | .   .   . | 8   .   . |
+-------+   |       +---+       +---+
| .   . | 1 | .   3 | .   .   . | . |
|       +---+---+   |       +---+   |
| 1   .   . | . | . | 7   . | .   . |
|       +---+   +---+---+---+       |
| 2   . | .   4   .   3 | .   .   . |
|       |               |           |
| .   . | 8   .   .   . | 5   .   . |
+-------+---------------+-----------+

Lots of ideas to be kept busy with...
1to9only
 
Posts: 1005
Joined: 04 April 2018

Re: sudokuexplainer clone, SINGLESONLY, solver,generator, c

Postby tarek » Tue Jan 22, 2019 12:36 pm

I only modified the stuff that you clearly shown that can bedowloafef and changed by other people. So it was intended for the audience interested in downloading and possibly modifying it. A bit of fun. Doesn’t matter if clunky as long that it does the job.

From looking at the code I can see how the Jigsaw can easily replace the boxes by changing the definitions (tedious but easy). The NC can be done by doing 4 x 2 extra eliminations when you set a clue. It will be easy to do the cyclic NC and even toroidal eliminations too!

Great work!!

tarek
User avatar
tarek
 
Posts: 2966
Joined: 05 January 2006

Re: sudokuexplainer clone, SINGLESONLY, solver,generator, c

Postby Mathimagics » Tue Jan 22, 2019 2:58 pm

tarek wrote:... bedowloafef and changed by other people.

Someone's getting a little excited! :lol:

Ok looks like you guys are having some fun …

A question for 1to9only. Which do you pick first, the solution grid or the jigsaw pattern?
User avatar
Mathimagics
2017 Supporter
 
Posts: 1263
Joined: 27 May 2015
Location: Canberra

Re: sudokuexplainer clone, SINGLESONLY, solver,generator, c

Postby 1to9only » Tue Jan 22, 2019 5:21 pm

Mathimagics wrote:A question for 1to9only. Which do you pick first, the solution grid or the jigsaw pattern?

I read the jigsaw pattern first - from a Sumocue file (SumoCueV1=0J0...), update some table definitions as Tarek noted, and generate the jigsaw puzzle from an empty grid. The program reuses the code in post #1.

I decided to go with the Sumocue file format as there are a few around, and you can create/export your own in SudokuSolver.
1to9only
 
Posts: 1005
Joined: 04 April 2018

Re: sudokuexplainer clone, SINGLESONLY, solver,generator, c

Postby Mathimagics » Tue Jan 22, 2019 6:33 pm

.
Ok, that's like most generators that I have seen.

But consider the alternative … why not start with a Sudoku grid, and then pick a Jigsaw pattern that matches?

You then have a truly independent generator, no catalog of jigsaw patterns is required. No trust issues (have these patterns been vetted? etc)

Just a thought! 8-)
User avatar
Mathimagics
2017 Supporter
 
Posts: 1263
Joined: 27 May 2015
Location: Canberra


Return to Software