do {
int piece = move->piece;
int to = move->to, from = pieceList[piece];
- if(!found) { // if already found just scan to game end for final piece count
+ if(found < 0) { // if already found just scan to game end for final piece count
if(QuickCompare(soughtBoard, minSought, maxSought) ||
appData.ignoreColors && QuickCompare(reverseBoard, minReverse, maxReverse) ||
flipSearch && (QuickCompare(flipBoard, minSought, maxSought) ||
if(stretch++ == 0) for(i=0; i<EmptySquare; i++) lastCounts[i] = counts[i]; // remember actual material
} else stretch = 0;
if(stretch && (appData.searchMode == 1 || stretch >= appData.stretch)) found = cnt + 1 - stretch;
- if(found && !appData.minPieces) return found;
+ if(found >= 0 && !appData.minPieces) return found;
}
if(piece <= Q_PROMO) { // special moves encoded by otherwise invalid piece numbers 1-4
if(!piece) return (appData.minPieces && (total < appData.minPieces || total > appData.maxPieces) ? -1 : found);
}
}
if(appData.searchMode > 2) counts[pieceType[quickBoard[to]]]--; // account capture
- if((total -= (quickBoard[to] != 0)) < soughtTotal) return -1; // piece count dropped below what we search for
+ if((total -= (quickBoard[to] != 0)) < soughtTotal && found < 0) return -1; // piece count dropped below what we search for
quickBoard[from] = 0;
aftercastle:
quickBoard[to] = piece;
}
}
-/* Save game in PGN style and close the file */
-int
-SaveGamePGN (FILE *f)
+/* Save game in PGN style */
+static void
+SaveGamePGN2 (FILE *f)
{
int i, offset, linelen, newblock;
// char *movetext;
} else {
fprintf(f, "%s\n\n", PGNResult(gameInfo.result));
}
+}
+/* Save game in PGN style and close the file */
+int
+SaveGamePGN (FILE *f)
+{
+ SaveGamePGN2(f);
fclose(f);
lastSavedGame = GameCheckSum(); // [HGM] save: remember ID of last saved game to prevent double saving
return TRUE;
hintRequested = TRUE;
}
+int
+SaveSelected (FILE *g, int dummy, char *dummy2)
+{
+ ListGame * lg = (ListGame *) gameList.head;
+ int nItem, cnt=0;
+ FILE *f;
+
+ if( !(f = GameFile()) || ((ListGame *) gameList.tailPred)->number <= 0 ) {
+ DisplayError(_("Game list not loaded or empty"), 0);
+ return 0;
+ }
+
+ creatingBook = TRUE; // suppresses stuff during load game
+
+ /* Get list size */
+ for (nItem = 1; nItem <= ((ListGame *) gameList.tailPred)->number; nItem++){
+ if(lg->position >= 0) { // selected?
+ LoadGame(f, nItem, "", TRUE);
+ SaveGamePGN2(g); // leaves g open
+ cnt++;
+ }
+ lg = (ListGame *) lg->node.succ;
+ }
+
+ fclose(g);
+ creatingBook = FALSE;
+
+ return cnt;
+}
+
void
CreateBookEvent ()
{
int LoadGameFromFile P((char *filename, int n, char *title, int useList));
int CmailLoadGame P((FILE *f, int n, char *title, int useList));
int ReloadGame P((int offset));
+int SaveSelected P((FILE *f, int dummy, char *dummy2));
int SaveGame P((FILE *f, int dummy, char *dummy2));
int SaveGameToFile P((char *filename, int append));
int LoadPosition P((FILE *f, int n, char *title));
ScheduleDelayedEvent(CreateBookEvent, 50);
}
+void
+SaveSelectedProc ()
+{
+ FileNamePopUp(_("Save game file name?"),
+ "",
+ ".pgn",
+ SaveSelected, "a");
+}
+
/*
* Menu definition tables
*/
{"----", NULL, NULL, NothingProc},
{N_("Save Game"), "<Ctrl>s", "SaveGame", SaveGameProc},
{N_("Save Position"), "<Ctrl><Shift>s", "SavePosition", SavePositionProc},
+ {N_("Save Selected Games"), NULL, "SaveSelected", SaveSelectedProc},
{N_("Save Games as Book"), NULL, "CreateBook", CreateBookDelayed},
{"----", NULL, NULL, NothingProc},
{N_("Mail Move"), NULL, "MailMove", MailMoveEvent},
if (saveSettingsOnExit) {
MarkMenuItem("Options.SaveSettingsonExit", True);
}
+ EnableNamedMenuItem("File.SaveSelected", False);
}
page = 0;
GameListReplace(0); // [HGM] filter: code put in separate routine, and also called to set title
MarkMenu("View.GameList", GameListDlg);
+ EnableNamedMenuItem("File.SaveSelected", TRUE);
}
FILE *
GameListDestroy ()
{
if (glc == NULL) return;
+ EnableNamedMenuItem("File.SaveSelected", FALSE);
PopDown(GameListDlg);
if (glc->strings != NULL) {
char **st;
#define OPT_GameListFind 1981\r
#define OPT_Grid 1983\r
#define IDM_LoadProg2 1984\r
-#define OPT_Range 1985\r
+#define OPT_Counts 1985\r
#define OPT_Ranget 1986\r
+#define IDM_SaveSelected 1987\r
\r
\r
// Next default values for new objects\r
gameFileName = StrSave(filename);\r
}\r
CheckMenuItem(GetMenu(hwndMain), IDM_ShowGameList, MF_CHECKED);\r
+ EnableMenuItem(GetMenu(hwndMain), IDM_SaveSelected, MF_ENABLED);\r
if (gameListDialog) {\r
SendMessage(gameListDialog, WM_INITDIALOG, 0, 0);\r
if (!gameListUp) ShowWindow(gameListDialog, SW_SHOW);\r
VOID GameListPopDown(void)\r
{\r
CheckMenuItem(GetMenu(hwndMain), IDM_ShowGameList, MF_UNCHECKED);\r
+ EnableMenuItem(GetMenu(hwndMain), IDM_SaveSelected, MF_GRAYED);\r
if (gameListDialog) ShowWindow(gameListDialog, SW_HIDE);\r
gameListUp = FALSE;\r
}\r
(void) CheckMenuItem(hmenu, IDM_SaveSettingsOnExit,\r
MF_BYCOMMAND|(saveSettingsOnExit ?\r
MF_CHECKED : MF_UNCHECKED));\r
+ EnableMenuItem(hmenu, IDM_SaveSelected, MF_GRAYED);\r
}\r
\r
//---------------------------------------------------------------------------------------------------------\r
}\r
break;\r
\r
+ case IDM_SaveSelected:\r
+ f = OpenFileDialog(hwnd, "a", "",\r
+ "pgn",\r
+ GAME_FILT,\r
+ _("Save Game to File"), NULL, fileTitle, NULL);\r
+ if (f != NULL) {\r
+ SaveSelected(f, 0, "");\r
+ }\r
+ break;\r
+\r
case IDM_CreateBook:\r
CreateBookEvent();\r
break;\r
EDITTEXT OPT_date,16,90,28,14,ES_AUTOHSCROLL\r
LTEXT "co&nsecutive positions",OPT_Stretcht,46,114,94,8,NOT WS_GROUP\r
EDITTEXT OPT_Stretch,16,110,28,14,ES_AUTOHSCROLL\r
+ LTEXT "final piece count",OPT_Ranget,46,134,94,8,NOT WS_GROUP\r
+ EDITTEXT OPT_Counts,16,130,28,14,ES_AUTOHSCROLL\r
CONTROL "Match exact &position",OPT_Exact,"Button",\r
- BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,6,136,159,10\r
+ BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,6,156,159,10\r
CONTROL "Match if position is s&ubset",OPT_Subset,"Button",\r
- BS_AUTORADIOBUTTON | WS_TABSTOP,6,149,159,10\r
+ BS_AUTORADIOBUTTON | WS_TABSTOP,6,169,159,10\r
CONTROL "Match material with e&xact pawn structure",OPT_Struct,"Button",\r
- BS_AUTORADIOBUTTON | WS_TABSTOP,6,162,159,10\r
+ BS_AUTORADIOBUTTON | WS_TABSTOP,6,182,159,10\r
CONTROL "Match &material",OPT_Material,"Button",\r
- BS_AUTORADIOBUTTON | WS_TABSTOP,6,175,159,10\r
+ BS_AUTORADIOBUTTON | WS_TABSTOP,6,195,159,10\r
CONTROL "Material &range (upper board-half is optional)",OPT_Range,"Button",\r
- BS_AUTORADIOBUTTON | WS_TABSTOP,6,188,159,10\r
+ BS_AUTORADIOBUTTON | WS_TABSTOP,6,208,159,10\r
CONTROL "Material &difference (optional material balanced)",OPT_Difference,"Button",\r
- BS_AUTORADIOBUTTON | WS_TABSTOP,6,201,159,10\r
- GROUPBOX "Search Mode: ",OPT_SearchMode,3,126,164,87,WS_GROUP\r
+ BS_AUTORADIOBUTTON | WS_TABSTOP,6,221,159,10\r
+ GROUPBOX "Search Mode: ",OPT_SearchMode,3,146,164,87,WS_GROUP\r
CONTROL "Also match reversed &colors",OPT_Reversed,"Button",\r
- BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,4,214,160,10\r
+ BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,4,234,160,10\r
CONTROL "Also match &left-right mirror image",OPT_Mirror,"Button",\r
- BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,4,227,160,10\r
- LTEXT "final piece count",OPT_Ranget,46,242,94,8,NOT WS_GROUP\r
- EDITTEXT OPT_Range,16,242,28,14,ES_AUTOHSCROLL\r
+ BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,4,247,160,10\r
PUSHBUTTON "OK",IDOK,56,262,50,14,WS_GROUP\r
PUSHBUTTON "Cancel",IDCANCEL,112,262,50,14\r
END\r
MENUITEM "S&ave Position...\tCtrl+Shift+S",IDM_SavePosition\r
MENUITEM SEPARATOR\r
MENUITEM "Save as &Diagram...", IDM_SaveDiagram\r
+ MENUITEM "Save Selected Games...", IDM_SaveSelected\r
MENUITEM "Save Games to &Book", IDM_CreateBook\r
MENUITEM SEPARATOR\r
MENUITEM "&Quit", IDM_Exit\r
SetDlgItemInt(hDlg, OPT_Stretch, appData.stretch, FALSE);\r
CheckDlgButton(hDlg, OPT_Reversed, appData.ignoreColors);\r
CheckDlgButton(hDlg, OPT_Mirror, appData.findMirror);\r
- SetDlgItemText(hDlg, OPT_Range, "");\r
+ SetDlgItemText(hDlg, OPT_Counts, "");\r
switch (appData.searchMode) {\r
case 1:\r
CheckDlgButton(hDlg, OPT_Exact, TRUE);\r
appData.searchMode = LoadOptionsWhichRadio(hDlg);\r
appData.ignoreColors = IsDlgButtonChecked(hDlg, OPT_Reversed);\r
appData.findMirror = IsDlgButtonChecked(hDlg, OPT_Mirror);\r
- appData.eloThreshold1 = GetDlgItemText(hDlg, OPT_Range, buf, MSG_SIZ);\r
+ GetDlgItemText(hDlg, OPT_Counts, buf, MSG_SIZ);\r
appData.minPieces = appData.maxPieces = 0;\r
- sscanf(buf, "%d-%d", appData.minPieces, appData.maxPieces);\r
+ sscanf(buf, "%d-%d", &appData.minPieces, &appData.maxPieces);\r
if(appData.maxPieces < appData.minPieces) appData.maxPieces = appData.minPieces;\r
EndDialog(hDlg, TRUE);\r
return TRUE;\r