LongLongNim::PLAYER LongLongNim::checkWin(int curNum, LongLongNim::PLAYER first) { if(curNum < mMove[0]) return swap_player(first); // curNum is equal to one of the number in move if(curNum <= mMove[mMoveLen-1]) { int i=0; for(; i<mMoveLen && mMove[i]!=curNum; i++); if(i<mMoveLen) { return first; } } // curNum (mMove[0], mMove[n-1]), but not equal to move[i], or // curNum is bigger than mMove[n-1] LongLongNim::PLAYER second = swap_player(first); LongLongNim::PLAYER winner = second; for(int i=0; i<mMoveLen && curNum<mMove[i]; i++) { // check mCache int num = curNum - mMove[i]; winner = checkCache(num); if(first == winner) { break; } assert(winner == second); // if the first can win only one of path, it will win finally. winner = checkWin(num, second); if(first == winner) { break; } } // add the result into cache RESULT res; res.num = curNum; res.winner = winner; mCache->add(res); return winner; }
static void process_move3 (gint c) { play_sound (SOUND_DROP); vstr[++moves] = '1' + c; vstr[moves + 1] = '0'; check_game_state (); if (gameover) { score[winner]++; scorebox_update (); prompt_player (); } else { swap_player (); if (!is_player_human ()) { if (player == PLAYER1) { vstr[0] = vlevel[p.level[PLAYER1]]; } else { vstr[0] = vlevel[p.level[PLAYER2]]; } c = playgame (vstr, vboard) - 1; if (c < 0) gameover = TRUE; g_timeout_add (SPEED_DROP, (GSourceFunc) next_move, GINT_TO_POINTER (c)); } } }
static void on_game_undo (GtkMenuItem * m, gpointer data) { gint r, c; if (timeout) return; c = vstr[moves] - '0' - 1; r = first_empty_row (c) + 1; vstr[moves] = '0'; vstr[moves + 1] = '\0'; moves--; if (gameover) { score[winner]--; scorebox_update (); gameover = FALSE; prompt_player (); } else { swap_player (); } move_cursor (c); gboard[r][c] = TILE_CLEAR; gfx_draw_tile (r, c); if (get_n_human_players () == 1 && !is_player_human ()) { if (moves > 0) { c = vstr[moves] - '0' - 1; r = first_empty_row (c) + 1; vstr[moves] = '0'; vstr[moves + 1] = '\0'; moves--; swap_player (); move_cursor (c); gboard[r][c] = TILE_CLEAR; gfx_draw_tile (r, c); } } }