summaryrefslogtreecommitdiff
path: root/apps/plugins/sudoku/sudoku.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/sudoku/sudoku.c')
-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)
584 return; 584 return;
585} 585}
586 586
587/* Copies the current to the saved board */
588static void save_state(struct sudoku_state_t *state)
589{
590 rb->memcpy(state->savedboard, state->currentboard,
591 sizeof(state->savedboard));
592}
593
594/* Copies the saved to the current board */
595static void restore_state(struct sudoku_state_t *state)
596{
597 rb->memcpy(state->currentboard, state->savedboard,
598 sizeof(state->savedboard));
599}
600
587void default_state(struct sudoku_state_t* state) 601void default_state(struct sudoku_state_t* state)
588{ 602{
589 int r,c; 603 int r,c;
@@ -600,7 +614,7 @@ void default_state(struct sudoku_state_t* state)
600 } 614 }
601 615
602 /* initialize the saved board so reload function works */ 616 /* initialize the saved board so reload function works */
603 rb->memcpy(state->savedboard,state->currentboard,81); 617 save_state(state);
604 618
605 state->x=0; 619 state->x=0;
606 state->y=0; 620 state->y=0;
@@ -775,7 +789,7 @@ bool load_sudoku(struct sudoku_state_t* state, char* filename)
775 789
776 /* Save a copy of the saved state - so we can reload without using the 790 /* Save a copy of the saved state - so we can reload without using the
777 disk */ 791 disk */
778 rb->memcpy(state->savedboard,state->currentboard,81); 792 save_state(state);
779 return(true); 793 return(true);
780} 794}
781 795
@@ -823,18 +837,13 @@ bool save_sudoku(struct sudoku_state_t* state)
823 rb->reload_directory(); 837 rb->reload_directory();
824 /* Save a copy of the saved state - so we can reload without 838 /* Save a copy of the saved state - so we can reload without
825 using the disk */ 839 using the disk */
826 rb->memcpy(state->savedboard,state->currentboard,81); 840 save_state(state);
827 return true; 841 return true;
828 } else { 842 } else {
829 return false; 843 return false;
830 } 844 }
831} 845}
832 846
833void restore_state(struct sudoku_state_t* state)
834{
835 rb->memcpy(state->currentboard,state->savedboard,81);
836}
837
838void clear_board(struct sudoku_state_t* state) 847void clear_board(struct sudoku_state_t* state)
839{ 848{
840 int r,c; 849 int r,c;
@@ -1107,7 +1116,7 @@ bool sudoku_generate(struct sudoku_state_t* state)
1107 rb->splash(HZ*2, "Aborted"); 1116 rb->splash(HZ*2, "Aborted");
1108 } 1117 }
1109 /* initialize the saved board so reload function works */ 1118 /* initialize the saved board so reload function works */
1110 rb->memcpy(state->savedboard,state->currentboard,81); 1119 save_state(state);
1111 return res; 1120 return res;
1112} 1121}
1113 1122