sudoku: fix FS#7772: Sudoku: "Solve" Crash.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24024 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
4e89025935
commit
d9002eb94a
3 changed files with 48 additions and 3 deletions
|
@ -1153,3 +1153,34 @@ bool sudoku_generate_board(struct sudoku_state_t* state, char** difficulty)
|
||||||
*difficulty = classify( );
|
*difficulty = classify( );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool sudoku_solve_board(struct sudoku_state_t* state)
|
||||||
|
{
|
||||||
|
bool ret;
|
||||||
|
int r,c,i;
|
||||||
|
|
||||||
|
reset( );
|
||||||
|
i=0;
|
||||||
|
for (r=0;r<9;r++) {
|
||||||
|
for (c=0;c<9;c++) {
|
||||||
|
if( state->startboard[r][c]!='0' )
|
||||||
|
{
|
||||||
|
fill( i, state->startboard[r][c] - '0' );
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = ( 0 == solve( ) && 81 == idx_history );
|
||||||
|
|
||||||
|
if (ret) {
|
||||||
|
i=0;
|
||||||
|
for (r=0;r<9;r++) {
|
||||||
|
for (c=0;c<9;c++) {
|
||||||
|
state->currentboard[r][c]='0'+GET_DIGIT( board[ i ] );
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
bool sudoku_generate_board(struct sudoku_state_t* state, char** difficulty);
|
bool sudoku_generate_board(struct sudoku_state_t* state, char** difficulty);
|
||||||
|
bool sudoku_solve_board(struct sudoku_state_t* state);
|
||||||
|
|
|
@ -283,6 +283,10 @@ static unsigned int cellypos[9]={
|
||||||
#define YOFS ((LCD_HEIGHT-BOARD_HEIGHT)/2)
|
#define YOFS ((LCD_HEIGHT-BOARD_HEIGHT)/2)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define BLOCK 3
|
||||||
|
#define SIZE (BLOCK*BLOCK)
|
||||||
|
|
||||||
|
#if 0
|
||||||
/****** Solver routine by Tom Shackell <shackell@cs.york.ac.uk>
|
/****** Solver routine by Tom Shackell <shackell@cs.york.ac.uk>
|
||||||
|
|
||||||
Downloaded from:
|
Downloaded from:
|
||||||
|
@ -295,9 +299,6 @@ Released under GPLv2
|
||||||
|
|
||||||
typedef unsigned int Bitset;
|
typedef unsigned int Bitset;
|
||||||
|
|
||||||
#define BLOCK 3
|
|
||||||
#define SIZE (BLOCK*BLOCK)
|
|
||||||
|
|
||||||
#define true 1
|
#define true 1
|
||||||
#define false 0
|
#define false 0
|
||||||
|
|
||||||
|
@ -569,6 +570,18 @@ void sudoku_solve(struct sudoku_state_t* state)
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#endif /* 0 */
|
||||||
|
|
||||||
|
void sudoku_solve(struct sudoku_state_t* state)
|
||||||
|
{
|
||||||
|
bool ret = sudoku_solve_board(state);
|
||||||
|
|
||||||
|
if (!ret) {
|
||||||
|
rb->splash(HZ*2, "Solve failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Copies the current to the saved board */
|
/* Copies the current to the saved board */
|
||||||
static void save_state(struct sudoku_state_t *state)
|
static void save_state(struct sudoku_state_t *state)
|
||||||
|
|
Loading…
Reference in a new issue