summaryrefslogtreecommitdiff
path: root/apps/plugins/sudoku
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2008-10-30 21:00:17 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2008-10-30 21:00:17 +0000
commit324816f0190dec308f3496a288820a47926b1c17 (patch)
treeb0d44a84e24f3942aebbdc9c21a4e34d046355c1 /apps/plugins/sudoku
parentd19534977902945738523872a78adc26b3147088 (diff)
Factor out save / restore sudoku board (FS#9516 by Alexander Levin)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18939 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/sudoku')
-rw-r--r--apps/plugins/sudoku/sudoku.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/apps/plugins/sudoku/sudoku.c b/apps/plugins/sudoku/sudoku.c
index db375d4588..150edaba54 100644
--- a/apps/plugins/sudoku/sudoku.c
+++ b/apps/plugins/sudoku/sudoku.c
@@ -584,6 +584,20 @@ void sudoku_solve(struct sudoku_state_t* state)
return;
}
+/* Copies the current to the saved board */
+static void save_state(struct sudoku_state_t *state)
+{
+ rb->memcpy(state->savedboard, state->currentboard,
+ sizeof(state->savedboard));
+}
+
+/* Copies the saved to the current board */
+static void restore_state(struct sudoku_state_t *state)
+{
+ rb->memcpy(state->currentboard, state->savedboard,
+ sizeof(state->savedboard));
+}
+
void default_state(struct sudoku_state_t* state)
{
int r,c;
@@ -600,7 +614,7 @@ void default_state(struct sudoku_state_t* state)
}
/* initialize the saved board so reload function works */
- rb->memcpy(state->savedboard,state->currentboard,81);
+ save_state(state);
state->x=0;
state->y=0;
@@ -775,7 +789,7 @@ bool load_sudoku(struct sudoku_state_t* state, char* filename)
/* Save a copy of the saved state - so we can reload without using the
disk */
- rb->memcpy(state->savedboard,state->currentboard,81);
+ save_state(state);
return(true);
}
@@ -823,18 +837,13 @@ bool save_sudoku(struct sudoku_state_t* state)
rb->reload_directory();
/* Save a copy of the saved state - so we can reload without
using the disk */
- rb->memcpy(state->savedboard,state->currentboard,81);
+ save_state(state);
return true;
} else {
return false;
}
}
-void restore_state(struct sudoku_state_t* state)
-{
- rb->memcpy(state->currentboard,state->savedboard,81);
-}
-
void clear_board(struct sudoku_state_t* state)
{
int r,c;
@@ -1107,7 +1116,7 @@ bool sudoku_generate(struct sudoku_state_t* state)
rb->splash(HZ*2, "Aborted");
}
/* initialize the saved board so reload function works */
- rb->memcpy(state->savedboard,state->currentboard,81);
+ save_state(state);
return res;
}