4 ** the core routines for the program
5 ** compile it with C++ but most of it will probably be C
8 ** Copyright (C) 1998-1999 Kurt Van den Branden
10 ** This program is free software; you can redistribute it and/or modify
11 ** it under the terms of the GNU General Public License as published by
12 ** the Free Software Foundation; either version 2 of the License, or
13 ** (at your option) any later version.
15 ** This program is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ** GNU General Public License for more details.
20 ** You should have received a copy of the GNU General Public License
21 ** along with this program; if not, write to the Free Software
22 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 char versiontext
[] = "Gipf for one v 1.03 (28/02/2000)";
30 #include <FL/Fl_Menu_Button.H>
34 #include "callbacks.h"
35 #include "setup_win.h"
37 #include "configfile.h"
42 #include "i_blauw.xpm"
45 #ifdef MSWIN // for the icon
50 int stop_program
= 0; /* set by the callback from the main window */
52 board
* loadboard (void);
53 void saveboard (board
* boardptr
);
54 void savelog (gamelog
* logptr
);
57 int main (int argc
, char ** argv
)
63 configvalues gf1_config
;
64 gamestruct
* currentgame
= NULL
,
73 /* read configuration */
74 retrieveconfig (& gf1_config
);
76 /* create the main window */
77 mainwin
= create_mainwindow();
81 p
= XCreateBitmapFromData(fl_display
, DefaultRootWindow(fl_display
),
82 (char *) i_blauw_xpm
, 64, 64);
83 mainwin
->icon((char *)p
);
88 fl_display
= GetModuleHandle (NULL
);
90 mainwin
->icon((char *)LoadIcon(fl_display
, MAKEINTRESOURCE(GF1_ICON
)));
93 /* setup the gameboard */
94 gameboard
->setoutputwidgets(whitepieces
, lostwhite
, drawwhite
,
95 blackpieces
, lostblack
, drawblack
,
97 gameboard
->setexecbutton (button_execute
);
98 gameboard
->setshowposname (gf1_config
.showposname
);
100 /* create helpwindow but don't show it */
101 helpwin
= gf1_help ();
103 /* set interface-items */
104 changeinterface (INTERFACE_PLAY
, NULL
);
106 /* show the main window */
107 Fl::visual (FL_DOUBLE
|FL_INDEX
);
108 Fl::background (0xb0, 0xb0, 0xb0);
110 // mainwin->show(argc, argv); // don't do this, uses default user
114 ** on windows95 the window doesn't stay on for 5 seconds
115 ** if I don't add the following line
118 /* show the about-window, it will go away after 5 seconds */
123 /* The program must be stopped when wait() returns 0 */
130 while ((x
= Fl::readqueue()))
134 // printf ("mainwin event\n");
136 else if (x
== menubar
)
139 Fl_Menu_Bar
* y
= (Fl_Menu_Bar
*) x
;
144 newgame
= show_new (currentgame
);
147 stoptimer (currentgame
);
148 delete_game (currentgame
);
149 currentgame
= newgame
;
150 currentgame
->config
= & gf1_config
;
152 gameboard
->setboard (currentgame
->boards
[0]);
154 setupmove (currentgame
);
157 else if (z
== menu_loadgame
)
159 newgame
= loadgame ();
162 stoptimer (currentgame
);
163 delete_game (currentgame
);
164 currentgame
= newgame
;
165 currentgame
->config
= & gf1_config
;
167 gameboard
->setboard (newgame
->boards
[0]);
169 setupmove (currentgame
);
172 else if (z
== menu_savegame
)
174 savegame (currentgame
);
176 else if (z
== menu_savelog
)
178 if (currentgame
!= NULL
)
179 savelog (currentgame
->movelog
);
183 else if (z
== menu_setup
)
185 if (show_setup (&gf1_config
))
187 writeconfig (&gf1_config
);
188 gameboard
->setshowposname (gf1_config
.showposname
);
191 else if (z
== menu_exit
)
195 else if (z
== menu_edit
)
199 stoptimer (currentgame
);
200 if (currentgame
== NULL
)
202 tempboard
= b_new (T_TOURNAMENT
);
203 gameboard
->setboard (tempboard
);
207 { /* convert board to tournament configuration */
208 tempboard
= b_copy (gameboard
->getboard ());
209 if (b_white_gipf (gameboard
->getboard ()) == -1)
211 tempboard
->gipfwhite
= 0;
212 tempboard
->gipfblack
= 0;
213 tempboard
->white
+= 3;
214 tempboard
->black
+= 3;
216 tempboard
->movecounter
= 0;
217 gameboard
->setboard (tempboard
);
220 changeinterface (INTERFACE_EDIT
, currentgame
);
224 else if (z
== menu_start
)
226 newgame
= show_start (gameboard
->getboard ());
229 delete_game (currentgame
);
230 currentgame
= newgame
;
231 currentgame
->config
= & gf1_config
;
233 gameboard
->setboard (currentgame
->boards
[0]);
235 setupmove (currentgame
);
238 else if (z
== menu_compumove
)
240 newgame
= show_onemove (gameboard
->getboard (),
244 delete_game (currentgame
);
245 currentgame
= newgame
;
248 else if (z
== menu_clear
)
252 tempboard
= b_new (T_TOURNAMENT
);
253 gameboard
->setboard (tempboard
);
257 else if (z
== menu_restore
)
259 changeinterface (INTERFACE_PLAY
, currentgame
);
260 if (currentgame
== NULL
)
262 gameboard
->setboard (NULL
);
266 gameboard
->setboard (currentgame
->boards
[0]);
268 setupmove (currentgame
);
271 else if (z
== menu_loadboard
)
273 board
* tempboard
= NULL
;
275 if ((tempboard
= loadboard ()) != NULL
)
277 gameboard
->setboard (tempboard
);
283 else if (z
== menu_saveboard
)
285 saveboard (gameboard
->getboard());
287 else if (z
== menu_makedrawing
)
289 show_makegif (gameboard
->getboard ());
291 else if (z
== menu_undo
)
293 if ((currentgame
!= NULL
) &&
294 (currentgame
->boards
[2] != NULL
))
296 b_del (currentgame
->boards
[0]);
297 b_del (currentgame
->boards
[1]);
298 currentgame
->boards
[0] = currentgame
->boards
[2];
299 currentgame
->boards
[1] = NULL
;
300 currentgame
->boards
[2] = NULL
;
301 currentgame
->movecounter
-=
302 remlastmove (currentgame
->movelog
);
303 currentgame
->movecounter
-=
304 remlastmove (currentgame
->movelog
);
306 setupmove (currentgame
);
307 gameboard
->setboard (currentgame
->boards
[0]);
310 else if (z
== menu_help
)
314 else if (z
== menu_about
)
319 else if (x
== choice_piecetype
)
322 Fl_Choice
* y
= (Fl_Choice
*) x
;
325 if (z
== choice_white
)
327 gameboard
->seteditpiece ('o');
329 else if (z
== choice_whitegipf
)
331 gameboard
->seteditpiece ('O');
333 else if (z
== choice_black
)
335 gameboard
->seteditpiece ('x');
337 else if (z
== choice_blackgipf
)
339 gameboard
->seteditpiece ('X');
342 else if (x
== menu_piecetype
)
345 Fl_Menu_Button
* y
= (Fl_Menu_Button
*) x
;
350 choice_piecetype
->value (0);
351 gameboard
->seteditpiece ('o');
353 else if (z
== menu_whitegipf
)
355 choice_piecetype
->value (1);
356 gameboard
->seteditpiece ('O');
358 else if (z
== menu_black
)
360 choice_piecetype
->value (2);
361 gameboard
->seteditpiece ('x');
363 else if (z
== menu_blackgipf
)
365 choice_piecetype
->value (3);
366 gameboard
->seteditpiece ('X');
369 else if (x
== count_lostwhite
)
371 newval
= gameboard
->setlostwhite
372 ((int) count_lostwhite
->value());
373 /* just in case the new value is not valid */
374 count_lostwhite
->value ((double) newval
);
376 else if (x
== count_lostblack
)
378 newval
= gameboard
->setlostblack
379 ((int) count_lostblack
->value());
380 /* just in case the new value is not valid */
381 count_lostblack
->value ((double) newval
);
383 else if (x
== button_execute
)
385 if (currentgame
!= NULL
)
387 if (humanmove (currentgame
) != 0)
389 "invalid move, check the from- and to-position !");
391 setupmove (currentgame
);
402 stoptimer (currentgame
);
403 delete_game (currentgame
);
406 clearconfiglist (gf1_config
.configlist
);
413 ** load a board from a file
415 ** return NULL if nothing loaded
417 board
* loadboard (void)
419 const char * filename
;
421 xmlite_entity
* root
;
422 xmlite_parser
* theparser
;
425 if ((filename
= file_chooser ("load board", "*.brd", NULL
)) == NULL
)
430 theparser
= new xmlite_parser (filename
);
431 root
= theparser
->parse();
435 gf1_alert (" ERROR: wrong inputfile format");
439 newboard
= b_from_xml (root
);
447 ** save a board to a file
449 void saveboard (board
* boardptr
)
451 const char * filename
;
452 xmlite_entity
* root
;
454 if (boardptr
== NULL
)
456 gf1_alert (" no current board to be saved");
461 if ((filename
= file_chooser ("save board", "*.brd", "./board.brd"))
467 root
= b_to_xml (boardptr
);
468 root
->writetofile (filename
);
476 ** save a gamelog to a file
478 void savelog (gamelog
* logptr
)
480 const char * filename
;
485 gf1_alert (" no gamelog to be saved");
490 if ((filename
= file_chooser ("save board", "*.log", "./gamelog.log"))
496 if ((fp
= fopen (filename
, "w")) == NULL
)
498 gf1_alert (" ERROR: Can't create the file");
502 logtofile (logptr
, fp
);
509 extern "C" void checkwindowevents (void);
511 void checkwindowevents (void)