summaryrefslogtreecommitdiff
path: root/apps/plugins/chessbox/chessbox.c
diff options
context:
space:
mode:
authorNils Wallménius <nils@rockbox.org>2007-09-02 10:11:46 +0000
committerNils Wallménius <nils@rockbox.org>2007-09-02 10:11:46 +0000
commit5ccf18019ed9529564300dc13313705ab35b94b3 (patch)
tree09530f364102c0e315e8df72ec60e10244f2e78c /apps/plugins/chessbox/chessbox.c
parentc00652b0a222b6d5a25437b972d34d72619b00a8 (diff)
downloadrockbox-5ccf18019ed9529564300dc13313705ab35b94b3.tar.gz
rockbox-5ccf18019ed9529564300dc13313705ab35b94b3.zip
Accept patch from FS#7174 by Mauricio Peccorini with canges by me and Igor Kuzmin, chessbox now saves played games in a pgn file called .rockbox/rocks/games/chessbox.pgn
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14575 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/chessbox/chessbox.c')
-rw-r--r--apps/plugins/chessbox/chessbox.c42
1 files changed, 38 insertions, 4 deletions
diff --git a/apps/plugins/chessbox/chessbox.c b/apps/plugins/chessbox/chessbox.c
index ab75765885..8e3d889dff 100644
--- a/apps/plugins/chessbox/chessbox.c
+++ b/apps/plugins/chessbox/chessbox.c
@@ -672,7 +672,6 @@ void cb_start_viewer(char* filename){
672 curr_ply = curr_ply->prev_node; 672 curr_ply = curr_ply->prev_node;
673 } else { 673 } else {
674 rb->splash ( 200 , "At the begining of the game" ); 674 rb->splash ( 200 , "At the begining of the game" );
675 cb_drawboard();
676 break; 675 break;
677 } 676 }
678 board[locn[curr_ply->row_from][curr_ply->column_from]] 677 board[locn[curr_ply->row_from][curr_ply->column_from]]
@@ -952,7 +951,8 @@ struct cb_command cb_getcommand (void) {
952/* ---- game main loop ---- */ 951/* ---- game main loop ---- */
953void cb_play_game(void) { 952void cb_play_game(void) {
954 struct cb_command command; 953 struct cb_command command;
955 char move_buffer[10]; 954 struct pgn_game_node *game;
955 char move_buffer[20];
956 956
957 /* init status */ 957 /* init status */
958 bool exit = false; 958 bool exit = false;
@@ -961,9 +961,13 @@ void cb_play_game(void) {
961 961
962 /* init board */ 962 /* init board */
963 GNUChess_Initialize(); 963 GNUChess_Initialize();
964
965 /* init PGN history data structures */
966 game = pgn_init_game(rb);
964 967
965 /* restore saved position, if saved */ 968 /* restore saved position, if saved */
966 cb_restoreposition(); 969 cb_restoreposition();
970 /* TODO: save/restore the PGN history of unfinished games */
967 971
968 /* draw the board */ 972 /* draw the board */
969 /* I don't like configscreens, start game inmediatly */ 973 /* I don't like configscreens, start game inmediatly */
@@ -973,17 +977,23 @@ void cb_play_game(void) {
973 if ( mate ) { 977 if ( mate ) {
974 rb->splash ( 500 , "Checkmate!" ); 978 rb->splash ( 500 , "Checkmate!" );
975 rb->button_get(true); 979 rb->button_get(true);
980 pgn_store_game(rb, game);
976 GNUChess_Initialize(); 981 GNUChess_Initialize();
982 game = pgn_init_game(rb);
977 cb_drawboard(); 983 cb_drawboard();
978 } 984 }
979 command = cb_getcommand (); 985 command = cb_getcommand ();
980 switch (command.type) { 986 switch (command.type) {
981 case COMMAND_MOVE: 987 case COMMAND_MOVE:
982 if ( ! VerifyMove ( command.mv_s , 0 , &command.mv ) ) { 988 if ( ! VerifyMove (opponent, command.mv_s , 0 , &command.mv, move_buffer ) ) {
983 rb->splash ( 50 , "Illegal move!" ); 989 rb->splash ( 50 , "Illegal move!" );
984 cb_drawboard(); 990 cb_drawboard();
985 } else { 991 } else {
986 cb_drawboard(); 992 cb_drawboard();
993
994 /* Add the ply to the PGN history (in algebraic notation) */
995 pgn_append_ply(rb, game, opponent, move_buffer, mate);
996
987 rb->splash ( 0 , "Thinking..." ); 997 rb->splash ( 0 , "Thinking..." );
988#ifdef HAVE_ADJUSTABLE_CPU_FREQ 998#ifdef HAVE_ADJUSTABLE_CPU_FREQ
989 rb->cpu_boost ( true ); 999 rb->cpu_boost ( true );
@@ -992,6 +1002,15 @@ void cb_play_game(void) {
992#ifdef HAVE_ADJUSTABLE_CPU_FREQ 1002#ifdef HAVE_ADJUSTABLE_CPU_FREQ
993 rb->cpu_boost ( false ); 1003 rb->cpu_boost ( false );
994#endif 1004#endif
1005 /* Add the ply to the PGN history (in algebraic notation) and check
1006 * for the result of the game which is only calculated in SelectMove
1007 */
1008 if (move_buffer[0] != '\0'){
1009 pgn_append_ply(rb, game, computer, move_buffer, mate);
1010 } else {
1011 pgn_set_result(rb, game, mate);
1012 }
1013
995 if ( wt_command == COMMAND_QUIT ) { 1014 if ( wt_command == COMMAND_QUIT ) {
996 exit = true; 1015 exit = true;
997 break; 1016 break;
@@ -1002,6 +1021,7 @@ void cb_play_game(void) {
1002#ifdef COMMAND_RESTART 1021#ifdef COMMAND_RESTART
1003 case COMMAND_RESTART: 1022 case COMMAND_RESTART:
1004 GNUChess_Initialize(); 1023 GNUChess_Initialize();
1024 game = pgn_init_game(rb);
1005 cb_drawboard(); 1025 cb_drawboard();
1006 break; 1026 break;
1007#endif 1027#endif
@@ -1017,7 +1037,10 @@ void cb_play_game(void) {
1017 1037
1018 /* init board */ 1038 /* init board */
1019 GNUChess_Initialize(); 1039 GNUChess_Initialize();
1020 1040
1041 /* init PGN history data structures */
1042 game = pgn_init_game(rb);
1043
1021 /* restore saved position, if saved */ 1044 /* restore saved position, if saved */
1022 cb_restoreposition(); 1045 cb_restoreposition();
1023 1046
@@ -1040,6 +1063,16 @@ void cb_play_game(void) {
1040#ifdef HAVE_ADJUSTABLE_CPU_FREQ 1063#ifdef HAVE_ADJUSTABLE_CPU_FREQ
1041 rb->cpu_boost ( false ); 1064 rb->cpu_boost ( false );
1042#endif 1065#endif
1066
1067 /* Add the ply to the PGN history (in algebraic notation) and check
1068 * for the result of the game which is only calculated in SelectMove
1069 */
1070 if (move_buffer[0] != '\0'){
1071 pgn_append_ply(rb, game, computer, move_buffer, mate);
1072 } else {
1073 pgn_set_result(rb, game, mate);
1074 }
1075
1043 if ( wt_command == COMMAND_QUIT ) { 1076 if ( wt_command == COMMAND_QUIT ) {
1044 exit = true; 1077 exit = true;
1045 break; 1078 break;
@@ -1057,6 +1090,7 @@ void cb_play_game(void) {
1057 } 1090 }
1058 1091
1059 cb_saveposition(); 1092 cb_saveposition();
1093 /* TODO: save/restore the PGN history of unfinished games */
1060 rb->lcd_setfont(FONT_UI); 1094 rb->lcd_setfont(FONT_UI);
1061 1095
1062} 1096}