diff options
author | Teruaki Kawashima <teru@rockbox.org> | 2009-12-16 11:53:36 +0000 |
---|---|---|
committer | Teruaki Kawashima <teru@rockbox.org> | 2009-12-16 11:53:36 +0000 |
commit | d9002eb94a2f6dcb07b4869303068416b4e5590a (patch) | |
tree | 8fd87c07786ab78d3212349fa622e442d0722b43 | |
parent | 4e89025935fc155d35d1bffb88c028892181f58c (diff) | |
download | rockbox-d9002eb94a2f6dcb07b4869303068416b4e5590a.tar.gz rockbox-d9002eb94a2f6dcb07b4869303068416b4e5590a.zip |
sudoku: fix FS#7772: Sudoku: "Solve" Crash.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24024 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/plugins/sudoku/generator.c | 31 | ||||
-rw-r--r-- | apps/plugins/sudoku/generator.h | 1 | ||||
-rw-r--r-- | apps/plugins/sudoku/sudoku.c | 19 |
3 files changed, 48 insertions, 3 deletions
diff --git a/apps/plugins/sudoku/generator.c b/apps/plugins/sudoku/generator.c index 59bb9066cc..ba74fa5b08 100644 --- a/apps/plugins/sudoku/generator.c +++ b/apps/plugins/sudoku/generator.c | |||
@@ -1153,3 +1153,34 @@ bool sudoku_generate_board(struct sudoku_state_t* state, char** difficulty) | |||
1153 | *difficulty = classify( ); | 1153 | *difficulty = classify( ); |
1154 | return true; | 1154 | return true; |
1155 | } | 1155 | } |
1156 | |||
1157 | bool sudoku_solve_board(struct sudoku_state_t* state) | ||
1158 | { | ||
1159 | bool ret; | ||
1160 | int r,c,i; | ||
1161 | |||
1162 | reset( ); | ||
1163 | i=0; | ||
1164 | for (r=0;r<9;r++) { | ||
1165 | for (c=0;c<9;c++) { | ||
1166 | if( state->startboard[r][c]!='0' ) | ||
1167 | { | ||
1168 | fill( i, state->startboard[r][c] - '0' ); | ||
1169 | } | ||
1170 | i++; | ||
1171 | } | ||
1172 | } | ||
1173 | |||
1174 | ret = ( 0 == solve( ) && 81 == idx_history ); | ||
1175 | |||
1176 | if (ret) { | ||
1177 | i=0; | ||
1178 | for (r=0;r<9;r++) { | ||
1179 | for (c=0;c<9;c++) { | ||
1180 | state->currentboard[r][c]='0'+GET_DIGIT( board[ i ] ); | ||
1181 | i++; | ||
1182 | } | ||
1183 | } | ||
1184 | } | ||
1185 | return ret; | ||
1186 | } | ||
diff --git a/apps/plugins/sudoku/generator.h b/apps/plugins/sudoku/generator.h index 3caa98ee19..222a9247b2 100644 --- a/apps/plugins/sudoku/generator.h +++ b/apps/plugins/sudoku/generator.h | |||
@@ -1 +1,2 @@ | |||
1 | bool sudoku_generate_board(struct sudoku_state_t* state, char** difficulty); | 1 | bool sudoku_generate_board(struct sudoku_state_t* state, char** difficulty); |
2 | bool sudoku_solve_board(struct sudoku_state_t* state); | ||
diff --git a/apps/plugins/sudoku/sudoku.c b/apps/plugins/sudoku/sudoku.c index 99b08f21a9..9e7e969eee 100644 --- a/apps/plugins/sudoku/sudoku.c +++ b/apps/plugins/sudoku/sudoku.c | |||
@@ -283,6 +283,10 @@ static unsigned int cellypos[9]={ | |||
283 | #define YOFS ((LCD_HEIGHT-BOARD_HEIGHT)/2) | 283 | #define YOFS ((LCD_HEIGHT-BOARD_HEIGHT)/2) |
284 | #endif | 284 | #endif |
285 | 285 | ||
286 | #define BLOCK 3 | ||
287 | #define SIZE (BLOCK*BLOCK) | ||
288 | |||
289 | #if 0 | ||
286 | /****** Solver routine by Tom Shackell <shackell@cs.york.ac.uk> | 290 | /****** Solver routine by Tom Shackell <shackell@cs.york.ac.uk> |
287 | 291 | ||
288 | Downloaded from: | 292 | Downloaded from: |
@@ -295,9 +299,6 @@ Released under GPLv2 | |||
295 | 299 | ||
296 | typedef unsigned int Bitset; | 300 | typedef unsigned int Bitset; |
297 | 301 | ||
298 | #define BLOCK 3 | ||
299 | #define SIZE (BLOCK*BLOCK) | ||
300 | |||
301 | #define true 1 | 302 | #define true 1 |
302 | #define false 0 | 303 | #define false 0 |
303 | 304 | ||
@@ -569,6 +570,18 @@ void sudoku_solve(struct sudoku_state_t* state) | |||
569 | 570 | ||
570 | return; | 571 | return; |
571 | } | 572 | } |
573 | #endif /* 0 */ | ||
574 | |||
575 | void sudoku_solve(struct sudoku_state_t* state) | ||
576 | { | ||
577 | bool ret = sudoku_solve_board(state); | ||
578 | |||
579 | if (!ret) { | ||
580 | rb->splash(HZ*2, "Solve failed"); | ||
581 | } | ||
582 | |||
583 | return; | ||
584 | } | ||
572 | 585 | ||
573 | /* Copies the current to the saved board */ | 586 | /* Copies the current to the saved board */ |
574 | static void save_state(struct sudoku_state_t *state) | 587 | static void save_state(struct sudoku_state_t *state) |