sudoku puzzle generator

I am looking for a puzzle generator and found reference to roamingGamer’s sudokuGen. However, it is not in the marketplace any longer. And I find no way to contact directly to ask. Can someone assist me in finding the plugin?

I’m in the middle of some client business this morning, but I’ll get back to you later today (July 3rd) after 1400 PST with details.

-Ed

@uuela9971,

Bad News - I removed the plugin from the store some time back because I didn’t want to maintain it for future versions of iOS and Android.

Good News:

  1. This site has a great python script for generating puzzles:

(You can run this with an older version of Python 2.7 I think, or you can convert it to Lua)

  1. Here is the C code i used in my now un-supported plugin.  If you’re C and Lua savvy you can convert this to Lua.

    /* Derived from:https://github.com/honzabrecka/sudoku-c The MIT License Copyright © 2014 Jan Břečka <jan.brecka@gmail.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include “CoronaLua.h” #include “CoronaMacros.h” #ifdef _MSC_VER typedef __int32 int32_t; typedef unsigned __int32 uint32_t; typedef unsigned __int64 uint64_t; #else #include <stdint.h> #endif // ****************************** Sudoku Generator Code // ****************************** Sudoku Generator Code int boxWidth = 3; int cellsPerBox = 9; int totalCells = 81; #define EMPTY 0 unsigned int seed = 0; int sudoku_generate(int * grid); #include <stdlib.h> static int getAt(int * grid, int x, int y) { int index = y * cellsPerBox + x; int value = *(grid + index); return value; } static int findEmptyIndex(int * grid) { int length = totalCells; int i; for (i = 0; i < length; i++) { if (*(grid + i) == EMPTY) { return i; } } return -1; } static int isPossible(int * grid, int index, int value) { int boxN = cellsPerBox / boxWidth; int x = index % cellsPerBox; int y = index / cellsPerBox; int boxX = x - (x % boxN); int boxY = y - (y % boxN); int i; for (i = 0; i < cellsPerBox; i++) { if (getAt(grid, i, y) == value || getAt(grid, x, i) == value || getAt(grid, boxX + (int)(i % boxN), boxY + (int)(i / boxN)) == value) { return 0; } } return 1; } static int candidates(int * grid, int index) { int boxN = cellsPerBox / boxWidth; int x = index % cellsPerBox; int y = index / cellsPerBox; int boxX = x - (x % boxN); int boxY = y - (y % boxN); int i; int * counts = (int *) calloc( cellsPerBox + 1, sizeof(int)); int candidate = 0; for (i = 0; i < cellsPerBox; i++) { counts[getAt(grid, i, y)]++; counts[getAt(grid, x, i)]++; counts[getAt(grid, boxX + (int)(i % boxN), boxY + (int)(i / boxN))]++; } for (i = 1; i <= cellsPerBox; i++) { if (*(counts + i) == 0) { if (candidate > 0) { return 0; } candidate = i; } } grid[index] = candidate; free(counts); return candidate > 0; } static void swap(int * a, int * b) { int t = *a; *a = *b; *b = t; } static void shuffle(int * array, int length) { int i, r; //srand((unsigned int)time(NULL)); srand(seed); seed = seed + 1; for (i = length - 1; i > 0; i–) { r = rand() % (i + 1); swap(&array[i], &array[r]); } } static void fill(int * array, int length, int start) { int i; for (i = 0; i < length; i++) { array[i] = start + i; } } int sudoku_generate(int * grid) { int index = findEmptyIndex(grid); int * values = (int *) calloc(cellsPerBox, sizeof(int)); int i, value; if (index == -1) { return 1; } fill(values, cellsPerBox, 1); shuffle(values, cellsPerBox); for (i = 0; i < cellsPerBox; i++) { value = *(values + i); if (isPossible(grid, index, value)) { grid[index] = value; if (sudoku_generate(grid)) { return 1; } grid[index] = EMPTY; } } free(values); return 0; } // dummy int sudoku_internal(lua_State *L) { int * grid; grid = (int *)calloc(totalCells, sizeof(int)); int count = 0; if (lua_type(L, 2) == LUA_TTABLE) { lua_pushnil(L); while (count < totalCells && lua_next(L, 2) != 0) { int value = lua_tointeger(L, -1); lua_pop(L, 1); if (value>0) { grid[count] = value; } count++; } } sudoku_generate(grid); lua_newtable(L); int i; for (i = 0; i < totalCells; i++) { lua_pushnumber(L, i+1); lua_pushinteger(L, (int)grid[i]); lua_settable(L, -3); } free(grid); return 1; } // gen_sudoku( seed, size ) int gen_sudoku(lua_State *L) { seed = (unsigned int)luaL_checknumber(L, 1); boxWidth = (int)luaL_checknumber(L, 1); cellsPerBox = boxWidth * boxWidth; totalCells = cellsPerBox * cellsPerBox; return sudoku_internal(L); } // gen_sudoku_2( seed ) int gen_sudoku_2(lua_State *L) { seed = (unsigned int)luaL_checknumber(L, 1); boxWidth = 2; cellsPerBox = boxWidth * boxWidth; totalCells = cellsPerBox * cellsPerBox; return sudoku_internal(L); } // gen_sudoku_3( seed ) int gen_sudoku_3(lua_State *L) { seed = (unsigned int)luaL_checknumber(L, 1); boxWidth = 3; cellsPerBox = boxWidth * boxWidth; totalCells = cellsPerBox * cellsPerBox; return sudoku_internal(L); } // gen_sudoku_4( seed ) int gen_sudoku_4(lua_State *L) { seed = (unsigned int)luaL_checknumber(L, 1); boxWidth = 4; cellsPerBox = boxWidth * boxWidth; totalCells = cellsPerBox * cellsPerBox; return sudoku_internal(L); } /* // gen_sudoku_5( seed ) int gen_sudoku_5(lua_State *L) { seed = (unsigned int)luaL_checknumber(L, 1); boxWidth = 5; cellsPerBox = boxWidth * boxWidth; totalCells = cellsPerBox * cellsPerBox; return sudoku_internal(L); } */ int dummy(lua_State *L) { seed = (unsigned int)luaL_checknumber(L, 1); lua_pushinteger(L, (int)seed); return 1; } // Export the functions as sudokugen plugin/module // CORONA_EXPORT int luaopen_plugin_sudokugen(lua_State *L) { static const luaL_Reg kVTable[] = { //{ “dummy”, dummy }, //{ “gen_sudoku”, gen_sudoku }, { “gen_sudoku2”, gen_sudoku_2 }, { “gen_sudoku3”, gen_sudoku_3 }, { “gen_sudoku4”, gen_sudoku_4 }, //{ “gen_sudoku5”, gen_sudoku_5 }, { NULL, NULL } }; luaL_openlib(L, “plugin.sudokugen”, kVTable, 0); return 1; }

 Note: If another developer out there wants to turn this into a free plugin go for it.

-Ed

There are hundreds of Sudoku apps on the app stores… try and be original :slight_smile:

Probably more than 100’s :slight_smile:  I’m one of them:

https://play.google.com/store/apps/details?id=com.roaminggamer.sudoku4&hl=en

“There are tons of Sudoku apps out there, but I wanted to make one especially for my Wife (a Sudoku addict).”

Bless ya!

only reason I am doing this is for experience in the overall process of building, submitting the app, etc. Don’t want to work hard on my target game and have to fight through another learning curve. Best to get it out of the way on something simple. 

And there are probably millions of Sudoku apps out there, I agree the last thing we should care about is yet another one.  :smiley:

If you’re looking for a simple game to learn from while making it, I don’t thing Sudoku is a good choice.

Unless of course you choose to NOT implement the tip and note taking features all modern Sudoku games provide.

If you do just a straight up answers only version that would be a good place to start learning Corona.

I’d actually suggest tic-tac-toe as a better grid based, learning Lua, learning Corona game.

thanks a simpler direction certainly.

I’m in the middle of some client business this morning, but I’ll get back to you later today (July 3rd) after 1400 PST with details.

-Ed

@uuela9971,

Bad News - I removed the plugin from the store some time back because I didn’t want to maintain it for future versions of iOS and Android.

Good News:

  1. This site has a great python script for generating puzzles:

(You can run this with an older version of Python 2.7 I think, or you can convert it to Lua)

  1. Here is the C code i used in my now un-supported plugin.  If you’re C and Lua savvy you can convert this to Lua.

    /* Derived from:https://github.com/honzabrecka/sudoku-c The MIT License Copyright © 2014 Jan Břečka <jan.brecka@gmail.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include “CoronaLua.h” #include “CoronaMacros.h” #ifdef _MSC_VER typedef __int32 int32_t; typedef unsigned __int32 uint32_t; typedef unsigned __int64 uint64_t; #else #include <stdint.h> #endif // ****************************** Sudoku Generator Code // ****************************** Sudoku Generator Code int boxWidth = 3; int cellsPerBox = 9; int totalCells = 81; #define EMPTY 0 unsigned int seed = 0; int sudoku_generate(int * grid); #include <stdlib.h> static int getAt(int * grid, int x, int y) { int index = y * cellsPerBox + x; int value = *(grid + index); return value; } static int findEmptyIndex(int * grid) { int length = totalCells; int i; for (i = 0; i < length; i++) { if (*(grid + i) == EMPTY) { return i; } } return -1; } static int isPossible(int * grid, int index, int value) { int boxN = cellsPerBox / boxWidth; int x = index % cellsPerBox; int y = index / cellsPerBox; int boxX = x - (x % boxN); int boxY = y - (y % boxN); int i; for (i = 0; i < cellsPerBox; i++) { if (getAt(grid, i, y) == value || getAt(grid, x, i) == value || getAt(grid, boxX + (int)(i % boxN), boxY + (int)(i / boxN)) == value) { return 0; } } return 1; } static int candidates(int * grid, int index) { int boxN = cellsPerBox / boxWidth; int x = index % cellsPerBox; int y = index / cellsPerBox; int boxX = x - (x % boxN); int boxY = y - (y % boxN); int i; int * counts = (int *) calloc( cellsPerBox + 1, sizeof(int)); int candidate = 0; for (i = 0; i < cellsPerBox; i++) { counts[getAt(grid, i, y)]++; counts[getAt(grid, x, i)]++; counts[getAt(grid, boxX + (int)(i % boxN), boxY + (int)(i / boxN))]++; } for (i = 1; i <= cellsPerBox; i++) { if (*(counts + i) == 0) { if (candidate > 0) { return 0; } candidate = i; } } grid[index] = candidate; free(counts); return candidate > 0; } static void swap(int * a, int * b) { int t = *a; *a = *b; *b = t; } static void shuffle(int * array, int length) { int i, r; //srand((unsigned int)time(NULL)); srand(seed); seed = seed + 1; for (i = length - 1; i > 0; i–) { r = rand() % (i + 1); swap(&array[i], &array[r]); } } static void fill(int * array, int length, int start) { int i; for (i = 0; i < length; i++) { array[i] = start + i; } } int sudoku_generate(int * grid) { int index = findEmptyIndex(grid); int * values = (int *) calloc(cellsPerBox, sizeof(int)); int i, value; if (index == -1) { return 1; } fill(values, cellsPerBox, 1); shuffle(values, cellsPerBox); for (i = 0; i < cellsPerBox; i++) { value = *(values + i); if (isPossible(grid, index, value)) { grid[index] = value; if (sudoku_generate(grid)) { return 1; } grid[index] = EMPTY; } } free(values); return 0; } // dummy int sudoku_internal(lua_State *L) { int * grid; grid = (int *)calloc(totalCells, sizeof(int)); int count = 0; if (lua_type(L, 2) == LUA_TTABLE) { lua_pushnil(L); while (count < totalCells && lua_next(L, 2) != 0) { int value = lua_tointeger(L, -1); lua_pop(L, 1); if (value>0) { grid[count] = value; } count++; } } sudoku_generate(grid); lua_newtable(L); int i; for (i = 0; i < totalCells; i++) { lua_pushnumber(L, i+1); lua_pushinteger(L, (int)grid[i]); lua_settable(L, -3); } free(grid); return 1; } // gen_sudoku( seed, size ) int gen_sudoku(lua_State *L) { seed = (unsigned int)luaL_checknumber(L, 1); boxWidth = (int)luaL_checknumber(L, 1); cellsPerBox = boxWidth * boxWidth; totalCells = cellsPerBox * cellsPerBox; return sudoku_internal(L); } // gen_sudoku_2( seed ) int gen_sudoku_2(lua_State *L) { seed = (unsigned int)luaL_checknumber(L, 1); boxWidth = 2; cellsPerBox = boxWidth * boxWidth; totalCells = cellsPerBox * cellsPerBox; return sudoku_internal(L); } // gen_sudoku_3( seed ) int gen_sudoku_3(lua_State *L) { seed = (unsigned int)luaL_checknumber(L, 1); boxWidth = 3; cellsPerBox = boxWidth * boxWidth; totalCells = cellsPerBox * cellsPerBox; return sudoku_internal(L); } // gen_sudoku_4( seed ) int gen_sudoku_4(lua_State *L) { seed = (unsigned int)luaL_checknumber(L, 1); boxWidth = 4; cellsPerBox = boxWidth * boxWidth; totalCells = cellsPerBox * cellsPerBox; return sudoku_internal(L); } /* // gen_sudoku_5( seed ) int gen_sudoku_5(lua_State *L) { seed = (unsigned int)luaL_checknumber(L, 1); boxWidth = 5; cellsPerBox = boxWidth * boxWidth; totalCells = cellsPerBox * cellsPerBox; return sudoku_internal(L); } */ int dummy(lua_State *L) { seed = (unsigned int)luaL_checknumber(L, 1); lua_pushinteger(L, (int)seed); return 1; } // Export the functions as sudokugen plugin/module // CORONA_EXPORT int luaopen_plugin_sudokugen(lua_State *L) { static const luaL_Reg kVTable[] = { //{ “dummy”, dummy }, //{ “gen_sudoku”, gen_sudoku }, { “gen_sudoku2”, gen_sudoku_2 }, { “gen_sudoku3”, gen_sudoku_3 }, { “gen_sudoku4”, gen_sudoku_4 }, //{ “gen_sudoku5”, gen_sudoku_5 }, { NULL, NULL } }; luaL_openlib(L, “plugin.sudokugen”, kVTable, 0); return 1; }

 Note: If another developer out there wants to turn this into a free plugin go for it.

-Ed

There are hundreds of Sudoku apps on the app stores… try and be original :slight_smile:

Probably more than 100’s :slight_smile:  I’m one of them:

https://play.google.com/store/apps/details?id=com.roaminggamer.sudoku4&hl=en

“There are tons of Sudoku apps out there, but I wanted to make one especially for my Wife (a Sudoku addict).”

Bless ya!

only reason I am doing this is for experience in the overall process of building, submitting the app, etc. Don’t want to work hard on my target game and have to fight through another learning curve. Best to get it out of the way on something simple. 

And there are probably millions of Sudoku apps out there, I agree the last thing we should care about is yet another one.  :smiley:

If you’re looking for a simple game to learn from while making it, I don’t thing Sudoku is a good choice.

Unless of course you choose to NOT implement the tip and note taking features all modern Sudoku games provide.

If you do just a straight up answers only version that would be a good place to start learning Corona.

I’d actually suggest tic-tac-toe as a better grid based, learning Lua, learning Corona game.

thanks a simpler direction certainly.