int ymsg = max (yboard + xoffset + 1 + board->ysize, yhelp + lhelp + yoffset + 1);
int lmsg = xhelp - xmsg + strmaxlen (help, '\n');
+ /* cache */
+ cache_t *cache = initcache (board);
+
/* event loop */
int mode = 0;
int stop = 0;
sprintf (msg + strlen (msg), "Begin turn (%d)", nbmaxjumps);
break;
case 1:
- case 2:
jump = cursorwindow (board, xcursor, ycursor, 1);
sprintf (msg + strlen (msg), "Choose next (%d)", nbmaxjumps);
break;
- case 3:
+ case 2:
sprintf (msg + strlen (msg), "Validate turn");
break;
}
domove (board, &xcursor, &ycursor, 0);
break;
case 1:
- case 2:
if ((jump) && (testjump (board, xcursor, ycursor, 0))) {
+ pushcache (cache, board, xcursor, ycursor);
+ board = copyboard (board);
dopetjump (board, &xcursor, &ycursor, 0);
- mode = (testalljumps (board, xcursor, ycursor)) ? 2 : 3;
+ if (!testalljumps (board, xcursor, ycursor)) {
+ mode = 2;
+ }
} else if ((player == 1) && (!jump) && (getvalue (board, xcursor + 1, ycursor - 1) == '.')) {
+ pushcache (cache, board, xcursor, ycursor);
+ board = copyboard (board);
dopetmove (board, &xcursor, &ycursor, 0);
- mode = 3;
+ mode = 2;
}
break;
}
domove (board, &xcursor, &ycursor, 1);
break;
case 1:
- case 2:
if ((jump) && (testjump (board, xcursor, ycursor, 1))) {
+ pushcache (cache, board, xcursor, ycursor);
+ board = copyboard (board);
dopetjump (board, &xcursor, &ycursor, 1);
- mode = (testalljumps (board, xcursor, ycursor)) ? 2 : 3;
+ if (!testalljumps (board, xcursor, ycursor)) {
+ mode = 2;
+ }
} else if ((player == 1) && (!jump) && (getvalue (board, xcursor - 1, ycursor - 1) == '.')) {
+ pushcache (cache, board, xcursor, ycursor);
+ board = copyboard (board);
dopetmove (board, &xcursor, &ycursor, 1);
- mode = 3;
+ mode = 2;
}
break;
}
domove (board, &xcursor, &ycursor, 2);
break;
case 1:
- case 2:
if ((jump) && (testjump (board, xcursor, ycursor, 2))) {
+ pushcache (cache, board, xcursor, ycursor);
+ board = copyboard (board);
dopetjump (board, &xcursor, &ycursor, 2);
- mode = (testalljumps (board, xcursor, ycursor)) ? 2 : 3;
+ if (!testalljumps (board, xcursor, ycursor)) {
+ mode = 2;
+ }
} else if ((player == 0) && (!jump) && (getvalue (board, xcursor - 1, ycursor + 1) == '.')) {
+ pushcache (cache, board, xcursor, ycursor);
+ board = copyboard (board);
dopetmove (board, &xcursor, &ycursor, 2);
- mode = 3;
+ mode = 2;
}
break;
}
domove (board, &xcursor, &ycursor, 3);
break;
case 1:
- case 2:
if ((jump) && (testjump (board, xcursor, ycursor, 3))) {
+ pushcache (cache, board, xcursor, ycursor);
+ board = copyboard (board);
dopetjump (board, &xcursor, &ycursor, 3);
- mode = (testalljumps (board, xcursor, ycursor)) ? 2 : 3;
+ if (!testalljumps (board, xcursor, ycursor)) {
+ mode = 2;
+ }
} else if ((player == 0) && (!jump) && (getvalue (board, xcursor + 1, ycursor + 1) == '.')) {
+ pushcache (cache, board, xcursor, ycursor);
+ board = copyboard (board);
dopetmove (board, &xcursor, &ycursor, 3);
- mode = 3;
+ mode = 2;
}
break;
}
case '\n':
case '\r':
case 'v':
- if (mode == 3) {
+ if (mode == 2) {
player = (player == 0) ? 1 : 0;
+ emptycache (cache);
mode = 0;
}
break;
case 127:
case '\b':
case 'x':
+ if (cache->board) {
+ board = popcache (cache, &xcursor, &ycursor);
+ mode = 1;
+ }
break;
//case ERR:
//default:
}
endwin ();
-
+ freecache (cache);
freeboard (board);
return 0;