From: Yann Dirson Date: Mon, 17 Feb 2014 22:01:48 +0000 (+0100) Subject: Merge branch 'maint' into HEAD X-Git-Url: http://winboard.nl/cgi-bin?p=gnushogi.git;a=commitdiff_plain;h=7496586755298a8115a3988a8b52b32d41a4dcb7;hp=-c Merge branch 'maint' into HEAD Conflicts: NEWS configure.ac gnushogi/cursesdsp.c --- 7496586755298a8115a3988a8b52b32d41a4dcb7 diff --combined NEWS index b32a839,f954ffc..05e43f8 --- a/NEWS +++ b/NEWS @@@ -1,17 -1,19 +1,26 @@@ GNU shogi news -------------- +Changes in version 1.5.0 (unreleased): + +* Build system switched from pure autoconf to automake +* Support for cross-compilation using standard "./configure --host=...", + including building windows binaries (both 32bit and 64bit) using + the gcc-mingw toolchain + - Changes in version 1.4.2 (unreleased): + Changes in version 1.4.2 (02/2014): * XShogi is no longer included in the GNU Shogi source, it is available as a separate source archive. + * Fixes for edit mode: + - fixed clobbering of board on invalid input + - display a message on wrong input + * Fixed Curses mode display: + - reversed column number for MiniShogi + - clock and captures position for MiniShogi + - refresh display after "switch" to get player names updated + - layout fixes, notably when using only 80 columns + * Minor code cleanups. Changes in version 1.4.1 (01/2014): diff --combined TODO index 054e46a,f630830..8a41e7b --- a/TODO +++ b/TODO @@@ -1,10 -1,15 +1,17 @@@ + Known bugs: + + - some positions show problem in the evaluation algorithm + - minishogi repetition rule, different from standard shogi, is + not implemented + - with no piece on board, computer generates invalid move + Target for v1.5: -- refactor dspwrappers into a driver-like structure -- integrate H.G.Muller's work on the xboard protocol on top of that +- integrate H.G.Muller's work on the xboard protocol on top of new driver-like + display handling - deprecate xshogi in favor of xboard +- use ~/.gnushogi for binary book and hash file + - make minishogi a run-time option rather than a compile-time one, using the "variant" mechanism of the xboard protocol @@@ -12,11 -17,12 +19,11 @@@ Generic cleanup - switch cli parsing to getopt - hunt for extern's and prototypes spread all over the source -- use automake - hunt for more hardcoded variant-specific constants - position of captured pieces in curses mode - compile with bound-checker - add autosave mode to ease hunt for segfaults ? -- use 2D array for the board, get rid of the (i)nunmap stuff +- ? use 2D array for the board, get rid of the (i)nunmap stuff - fixup build procedure to support parallel make runs - investigate those preexisting "overflow in implicit constant conversion" warnings @@@ -30,13 -36,3 +37,13 @@@ Minishogi-related stuf * OPENING_HINT - add minishogi stuff to the doc - use valid minishogi moves in online help + +Improvements + +- find out why the engine is so weak + - make it battle against Mutz-era gnushogi, and other engines, and + compare their evaluation results + - see what needs updating in book +- express available commands as display-dependant, instead of using if(XSHOGI) + - make "help" list commands available for current display +- make X and raw two different display drivers diff --combined configure.ac index 60dac7a,ce334dc..bdfde4e --- a/configure.ac +++ b/configure.ac @@@ -5,15 -5,13 +5,15 @@@ dnl Process this file with autoconf to produce a configure script. AC_PREREQ(2.57) - AC_INIT([gnushogi],[1.4.1+],[https://savannah.gnu.org/bugs/?group=gnushogi]) + AC_INIT([gnushogi],[1.4.2+],[https://savannah.gnu.org/bugs/?group=gnushogi]) +AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([gnushogi/gnushogi.h]) AC_CONFIG_HEADER(config.h) ########## AC_MSG_NOTICE([C compiler]) AC_PROG_CC +AC_CANONICAL_BUILD AC_PROG_INSTALL ########## @@@ -30,8 -28,7 +30,8 @@@ LIBCURSES AS_IF([test "x$with_curses" != xno], [AC_CHECK_LIB([curses], [clrtoeol], [AC_SUBST([LIBCURSES], [-lcurses]) - AC_SUBST([CURSESDSP], [cursesdsp.o]) + AC_SUBST([CURSESDSP], [gnushogi-cursesdsp.o]) + AC_SUBST([CURSESDSPMINI], [gnuminishogi-cursesdsp.o]) AC_DEFINE([HAVE_LIBCURSES], [1], [Define if you have lib]) ], @@@ -51,7 -48,7 +51,7 @@@ AC_CHECK_LIB([termcap], [tgoto] if [[ $ac_cv_c_compiler_gnu = yes ]] then -WARNINGS="-Wall -Wno-implicit-int -Wstrict-prototypes -ansi -pedantic" +WARNINGS="-Wall -Wno-implicit-int -Wstrict-prototypes" CEXTRAFLAGS="-fsigned-char -funroll-loops" else # Who knows what warnings your compiler uses? @@@ -92,6 -89,7 +92,6 @@@ AC_CHECK_SIZEOF(long AC_MSG_NOTICE([library functions]) AC_PROG_GCC_TRADITIONAL -AC_FUNC_MALLOC AC_TYPE_SIGNAL AC_CHECK_FUNCS([gettimeofday memset pow]) AC_CHECK_FUNCS([strchr strerror strrchr strstr strtol]) @@@ -113,15 -111,8 +113,15 @@@ AC_SUBST([PROGNAME], [gnuminishogi] ]) ########## + +# don't build pat2inc when cross-compiling, we don't need it +if test "$cross_compiling" = no; then + AC_SUBST([PAT2INC], [pat2inc]) + AC_SUBST([PAT2INCEXE], [pat2inc$(EXEEXT)]) +fi + +########## AC_CONFIG_FILES([Makefile gnushogi/Makefile - win32/config.h doc/Makefile]) AC_OUTPUT diff --combined gnushogi/commondsp.c index 90a3ca0,33d1068..e5efc17 --- a/gnushogi/commondsp.c +++ b/gnushogi/commondsp.c @@@ -50,9 -50,8 +50,9 @@@ #include "gnushogi.h" char mvstr[4][6]; -char *InPtr; -int InBackground = false; +int mycnt1, mycnt2; +static char *InPtr; +struct display *dsp = &raw_display; #if defined(BOOKTEST) @@@ -94,20 -93,20 +94,20 @@@ movealgbr(short m, char *s s++; *s = '*'; s++; - *s = cxx[column(t)]; + *s = COL_NAME(column(t)); s++; - *s = rxx[row(t)]; + *s = ROW_NAME(row(t)); s++; } else { - *s = cxx[column(f)]; + *s = COL_NAME(column(f)); s++; - *s = rxx[row(f)]; + *s = ROW_NAME(row(f)); s++; - *s = cxx[column(t)]; + *s = COL_NAME(column(t)); s++; - *s = rxx[row(t)]; + *s = ROW_NAME(row(t)); s++; if (flag & promote) @@@ -129,6 -128,8 +129,6 @@@ #endif /* BOOKTEST */ - - /* * Generate move strings in different formats. * @@@ -138,10 -139,7 +138,10 @@@ * - NO_SQUARES <= f NO_SQUARES + 2*NO_PIECES dropped piece modulo NO_PIECES * - t & 0x7f target square * - t & 0x80 promotion flag - * - flag FIXME: must be zero ? + * - flag + * - if flag & dropmask, piece type encoded in flag & pmask + * + * FIXME: that makes 2 ways to specify drops and promotions, why ? * * OUTPUT: * - GLOBAL mvstr @@@ -170,8 -168,8 +170,8 @@@ algbr(short f, short t, short flag if ((f == t) && ((f != 0) || (t != 0))) { - if (!barebones) { - Printf("error in algbr: FROM=TO=%d, flag=0x%4x\n", t, flag); + if (!XSHOGI) { + dsp->Printf("error in algbr: FROM=TO=%d, flag=0x%4x\n", t, flag); } mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0'; @@@ -182,8 -180,8 +182,8 @@@ mvstr[0][0] = pxx[piece]; mvstr[0][1] = '*'; - mvstr[0][2] = cxx[column(t)]; - mvstr[0][3] = rxx[row(t)]; + mvstr[0][2] = COL_NAME(column(t)); + mvstr[0][3] = ROW_NAME(row(t)); mvstr[0][4] = '\0'; strcpy(mvstr[1], mvstr[0]); strcpy(mvstr[2], mvstr[0]); @@@ -191,27 -189,20 +191,27 @@@ } else if ((f != 0) || (t != 0)) { - /* algebraic notation */ - mvstr[0][0] = cxx[column(f)]; - mvstr[0][1] = rxx[row(f)]; - mvstr[0][2] = cxx[column(t)]; - mvstr[0][3] = rxx[row(t)]; - mvstr[0][4] = mvstr[3][0] = '\0'; + /* pure coordinates notation */ + mvstr[0][0] = COL_NAME(column(f)); + mvstr[0][1] = ROW_NAME(row(f)); + mvstr[0][2] = COL_NAME(column(t)); + mvstr[0][3] = ROW_NAME(row(t)); + mvstr[0][4] = '\0'; + + /* algebraic notation without disambiguation */ mvstr[1][0] = pxx[board[f]]; + mvstr[1][1] = mvstr[0][2]; /* to column */ + mvstr[1][2] = mvstr[0][3]; /* to row */ + mvstr[1][3] = '\0'; + /* algebraic notation with row disambiguation */ mvstr[2][0] = mvstr[1][0]; mvstr[2][1] = mvstr[0][1]; + mvstr[2][2] = mvstr[0][2]; /* to column */ + mvstr[2][3] = mvstr[0][3]; /* to row */ + mvstr[2][4] = '\0'; - mvstr[2][2] = mvstr[1][1] = mvstr[0][2]; /* to column */ - mvstr[2][3] = mvstr[1][2] = mvstr[0][3]; /* to row */ - mvstr[2][4] = mvstr[1][3] = '\0'; + /* algebraic notation with column disambiguation */ strcpy(mvstr[3], mvstr[2]); mvstr[3][1] = mvstr[0][0]; @@@ -230,6 -221,7 +230,6 @@@ } - /* * Compare the string 's' to the list of legal moves available for the * opponent. If a match is found, make the move on the board. @@@ -310,7 -302,7 +310,7 @@@ VerifyMove(char *s, VerifyMove_mode iop if (SqAttacked(PieceList[opponent][0], computer, &blocked)) { UnmakeMove(opponent, &xnode, &tempb, &tempc, &tempsf, &tempst); - AlwaysShowMessage("Illegal move (in check) %s", s); + dsp->AlwaysShowMessage("Illegal move (in check) %s", s); return false; } else @@@ -318,7 -310,7 +318,7 @@@ if (iop == VERIFY_AND_TRY_MODE) return true; - UpdateDisplay(xnode.f, xnode.t, 0, (short) xnode.flags); + dsp->UpdateDisplay(xnode.f, xnode.t, 0, (short) xnode.flags); GameList[GameCnt].depth = GameList[GameCnt].score = 0; GameList[GameCnt].nodes = 0; ElapsedTime(COMPUTE_AND_INIT_MODE); @@@ -343,7 -335,7 +343,7 @@@ char buf[20]; sprintf(buf, "%s mates!\n", ColorStr[opponent]); - ShowMessage(buf); + dsp->ShowMessage(buf); flag.mate = true; } } @@@ -352,20 -344,21 +352,20 @@@ } } - AlwaysShowMessage("Illegal move (no match) %s", s); + dsp->AlwaysShowMessage("Illegal move (no match) %s", s); - if (!barebones && (cnt > 1)) + if (!XSHOGI && (cnt > 1)) { sprintf(buffer, "Ambiguous Move %s!", s); - ShowMessage(buffer); + dsp->ShowMessage(buffer); } return false; } - static int -parser(char *f, int side, short *fpiece) +parser(char *f, short *fpiece) { int c1, r1, c2, r2; short i, p = false; @@@ -384,17 -377,17 +384,17 @@@ if (f[1] == '*' || f[1] == '\'') { - c2 = COL_NAME(f[2]); - r2 = ROW_NAME(f[3]); + c2 = COL_NUM(f[2]); + r2 = ROW_NUM(f[3]); return ((NO_SQUARES + *fpiece) << 8) | locn(r2, c2); } else { - c1 = COL_NAME(f[1]); - r1 = ROW_NAME(f[2]); - c2 = COL_NAME(f[3]); - r2 = ROW_NAME(f[4]); + c1 = COL_NUM(f[1]); + r1 = ROW_NUM(f[2]); + c2 = COL_NUM(f[3]); + r2 = ROW_NUM(f[4]); p = (f[5] == '+') ? 0x80 : 0; return (locn(r1, c1) << 8) | locn(r2, c2) | p; @@@ -413,6 -406,7 +413,6 @@@ skip( } - void skipb() { @@@ -421,25 -415,8 +421,25 @@@ } +void RequestInputString(char* buffer, unsigned bufsize) +{ + static char fmt[10]; + int ret = snprintf(fmt, sizeof(fmt), "%%%us", bufsize); + if (ret < 0 ) { + perror("RequestInputString snprintf"); + exit(1); + } + if (ret >= sizeof(fmt)) { + fprintf(stderr, + "Insufficient format-buffer size in %s for bufsize=%u\n", + __FUNCTION__, bufsize); + exit(1); + } + dsp->doRequestInputString(fmt, buffer); +} -void + +static void GetGame(void) { FILE *fd; @@@ -451,7 -428,7 +451,7 @@@ if (savefile[0]) { strcpy(fname, savefile); } else { - ShowMessage("Enter file name: "); + dsp->ShowMessage("Enter file name: "); RequestInputString(fname, sizeof(fname)-1); } @@@ -603,7 -580,7 +603,7 @@@ InPtr = fname; skipb(); g = &GameList[GameCnt]; - g->gmove = parser(InPtr, side, &g->fpiece); + g->gmove = parser(InPtr, &g->fpiece); skip(); g->score = atoi(InPtr); skip(); @@@ -656,13 -633,14 +656,13 @@@ ZeroRPT(); InitializeStats(); - UpdateDisplay(0, 0, 1, 0); + dsp->UpdateDisplay(0, 0, 1, 0); Sdepth = 0; hint = 0; } - -void +static void SaveGame(void) { FILE *fd; @@@ -675,7 -653,7 +675,7 @@@ if (savefile[0]) { strcpy(fname, savefile); } else { - ShowMessage("Enter file name: "); + dsp->ShowMessage("Enter file name: "); RequestInputString(fname, sizeof(fname)-1); } @@@ -800,21 -778,22 +800,21 @@@ fclose(fd); - ShowMessage("Game saved"); + dsp->ShowMessage("Game saved"); } else { - ShowMessage("Could not open file"); + dsp->ShowMessage("Could not open file"); } } - /* * GetXGame, SaveXGame and BookGame used to only be defined if * xshogi wasn't defined -- wonder why? */ -void +static void GetXGame(void) { FILE *fd; @@@ -823,7 -802,7 +823,7 @@@ short sq; short side, isp; - ShowMessage("Enter file name: "); + dsp->ShowMessage("Enter file name: "); RequestInputString(fname, sizeof(fname)-1); if (fname[0] == '\0') @@@ -937,13 -916,13 +937,13 @@@ Game50 = 1; ZeroRPT(); InitializeStats(); - UpdateDisplay(0, 0, 1, 0); + dsp->UpdateDisplay(0, 0, 1, 0); Sdepth = 0; hint = 0; } -void +static void SaveXGame(void) { FILE *fd; @@@ -952,7 -931,7 +952,7 @@@ short sq, piece; short side, isp; - ShowMessage("Enter file name: "); + dsp->ShowMessage("Enter file name: "); RequestInputString(fname, sizeof(fname)-1); if (fname[0] == '\0') @@@ -1023,7 -1002,7 +1023,7 @@@ } -void +static void BookSave(void) { FILE *fd; @@@ -1034,7 -1013,7 +1034,7 @@@ strcpy(fname, savefile); } else { /* Enter file name */ - ShowMessage("Enter file name: "); + dsp->ShowMessage("Enter file name: "); RequestInputString(fname, sizeof(fname)-1); } @@@ -1106,15 -1085,16 +1106,15 @@@ fclose(fd); - ShowMessage("Game saved"); + dsp->ShowMessage("Game saved"); } else { - ShowMessage("Could not open file"); + dsp->ShowMessage("Could not open file"); } } - void ListGame(void) { @@@ -1242,7 -1222,8 +1242,7 @@@ } - -void +static void FlagMove(char c) { switch(c) @@@ -1264,11 -1245,13 +1264,11 @@@ } - - /* * Undo the most recent half-move. */ -void +static void Undo(void) { short f, t; @@@ -1317,15 -1300,69 +1317,15 @@@ flag.mate = false; Sdepth = 0; player = player ^ 1; - ShowSidetoMove(); - UpdateDisplay(0, 0, 1, 0); + dsp->ShowSidetoMove(); + dsp->UpdateDisplay(0, 0, 1, 0); if (flag.regularstart) Book = false; } - -void -FlagString(unsigned short flags, char *s) -{ - short l, piece; - *s = '\0'; - - if (flags & promote) - strcat(s, " promote"); - - if (flags & dropmask) - strcat(s, " drop:"); - - if ((piece = (flags & pmask))) - { - l = strlen(s); - - if (is_promoted[piece]) - s[l++] = '+'; - - s[l++] = pxx[piece]; - s[l] = '\0'; - } - - if (flags & capture) - strcat(s, " capture"); - - if (flags & exact) - strcat(s, " exact"); - - if (flags & tesuji) - strcat(s, " tesuji"); - - if (flags & check) - strcat(s, " check"); - - if (flags & draw) - strcat(s, " draw"); - - if (flags & stupid) - strcat(s, " stupid"); - - if (flags & questionable) - strcat(s, " questionable"); - - if (flags & kingattack) - strcat(s, " kingattack"); - - if (flags & book) - strcat(s, " book"); -} - - - -void +static void TestSpeed(void(*f)(short side, short ply, short in_check, short blockable), unsigned j) @@@ -1375,14 -1412,15 +1375,14 @@@ else et = 1; - ShowNodeCnt(cnt); + dsp->ShowNodeCnt(cnt); } - -void +static void TestPSpeed(short(*f) (short side), unsigned j) { - short i; + unsigned i; long cnt, t1, t2; #ifdef HAVE_GETTIMEOFDAY struct timeval tv; @@@ -1412,22 -1450,24 +1412,22 @@@ else et = 1; - ShowNodeCnt(cnt); + dsp->ShowNodeCnt(cnt); } - -void -SetOppTime(char *s) +static void +SetOppTime(char *time) { int m, t, sec; sec = 0; - time = &s[strlen("otime")]; t = (int)strtol(time, &time, 10); if (*time == ':') { time++; + /* FIXME: sec is parsed but ignored */ sec = (int)strtol(time, &time, 10); } @@@ -1449,18 -1489,20 +1449,18 @@@ } - -void -SetMachineTime(char *s) +static void +SetMachineTime(char *time) { - char *time; int m, t, sec; - time = &s[strlen("time")]; sec = 0; t = (int)strtol(time, &time, 10); if (*time == ':') { time++; + /* FIXME: sec is parsed but ignored */ sec = (int)strtol(time, &time, 10); } @@@ -1482,19 -1524,24 +1482,19 @@@ } - - - /* FIXME! This is truly the function from hell! */ /* * Process the user's command. If easy mode is OFF (the computer is thinking * on opponents time) and the program is out of book, then make the 'hint' * move on the board and call SelectMove() to find a response. The user - * terminates the search by entering ^C (quit siqnal) before entering a - * command. If the opponent does not make the hint move, then set Sdepth to - * zero. + * terminates the search by entering a command. If the opponent does not make + * the hint move, then set Sdepth to zero. */ void InputCommand(char *command) { - int eof = 0; short have_shown_prompt = false; short ok, done, is_move = false; unsigned short mv; @@@ -1521,8 -1568,10 +1521,8 @@@ algbr((short) hint >> 8, (short) hint & 0xff, false); strcpy(s, mvstr[0]); -#if !defined NOPOST if (flag.post) - GiveHint(); -#endif + dsp->GiveHint(); /* do the hint move */ if (VerifyMove(s, VERIFY_AND_TRY_MODE, &mv)) @@@ -1530,7 -1579,7 +1530,7 @@@ Sdepth = 0; #ifdef QUIETBACKGROUND - ShowPrompt(); + dsp->ShowPrompt(); have_shown_prompt = true; #endif /* QUIETBACKGROUND */ @@@ -1577,7 -1626,7 +1577,7 @@@ { #endif /* QUIETBACKGROUND */ - ShowPrompt(); + dsp->ShowPrompt(); #ifdef QUIETBACKGROUND } @@@ -1586,16 -1635,21 +1586,16 @@@ #endif /* QUIETBACKGROUND */ if (command == NULL) { - if (NOT_CURSES) - s[0] = '\0'; - - eof = GetString(sx); + int eof = dsp->GetString(sx); + if (eof) + dsp->ExitShogi(); } else { strcpy(sx, command); done = true; } - sscanf(sx, "%s", s); - - if (eof) - ExitShogi(); - - if (s[0] == '\0') + /* extract first word */ + if (sscanf(sx, "%s", s) < 1) continue; if (strcmp(s, "bd") == 0) /* bd -- display board */ @@@ -1606,8 -1660,8 +1606,8 @@@ if (old_xshogi) display_type = DISPLAY_RAW; - ClearScreen(); - UpdateDisplay(0, 0, 1, 0); + dsp->ClearScreen(); + dsp->UpdateDisplay(0, 0, 1, 0); if (old_xshogi) display_type = DISPLAY_X; @@@ -1618,21 -1672,27 +1618,21 @@@ } else if (strcmp(s, "alg") == 0) { - /* noop */ ; /* alg */ + /* noop */ ; } else if ((strcmp(s, "quit") == 0) || (strcmp(s, "exit") == 0)) { flag.quit = true; } else if ((strcmp(s, "set") == 0) || (strcmp(s, "edit") == 0)) { - EditBoard(); + dsp->EditBoard(); } - else if ((strcmp(s, "setup") == 0)) + else if (strcmp(s, "setup") == 0) { - SetupBoard(); + dsp->SetupBoard(); } else if (strcmp(s, "first") == 0) { @@@ -1656,7 -1716,7 +1656,7 @@@ } else if (strcmp(s, "help") == 0) { - help(); + dsp->help(); } else if (strcmp(s, "material") == 0) { @@@ -1682,19 -1742,16 +1682,19 @@@ else if (strcmp(s, "new") == 0) { NewGame(); - UpdateDisplay(0, 0, 1, 0); + dsp->UpdateDisplay(0, 0, 1, 0); } else if (strcmp(s, "list") == 0) { ListGame(); } - else if ((strcmp(s, "level") == 0) - || (strcmp(s, "clock") == 0)) + else if (strcmp(s, "level") == 0) { - SelectLevel(sx); + dsp->SelectLevel(sx + strlen("level")); + } + else if (strcmp(s, "clock") == 0) + { + dsp->SelectLevel(sx + strlen("clock")); } else if (strcmp(s, "hash") == 0) { @@@ -1710,19 -1767,19 +1710,19 @@@ } else if (strcmp(s, "time") == 0) { - SetMachineTime(sx); + SetMachineTime(sx + strlen("time")); } else if (strcmp(s, "otime") == 0) { - SetOppTime(sx); + SetOppTime(sx + strlen("otime")); } else if (strcmp(s, "Awindow") == 0) { - ChangeAlphaWindow(); + dsp->ChangeAlphaWindow(); } else if (strcmp(s, "Bwindow") == 0) { - ChangeBetaWindow(); + dsp->ChangeBetaWindow(); } else if (strcmp(s, "rcptr") == 0) { @@@ -1730,7 -1787,7 +1730,7 @@@ } else if (strcmp(s, "hint") == 0) { - GiveHint(); + dsp->GiveHint(); } else if (strcmp(s, "both") == 0) { @@@ -1744,8 -1801,8 +1744,8 @@@ else if (strcmp(s, "reverse") == 0) { flag.reverse = !flag.reverse; - ClearScreen(); - UpdateDisplay(0, 0, 1, 0); + dsp->ClearScreen(); + dsp->UpdateDisplay(0, 0, 1, 0); } else if (strcmp(s, "switch") == 0) { @@@ -1755,6 -1812,7 +1755,7 @@@ flag.force = false; Sdepth = 0; ok = true; - UpdateDisplay(0, 0, 1, 0); ++ dsp->UpdateDisplay(0, 0, 1, 0); } else if (strcmp(s, "black") == 0) { @@@ -1823,15 -1881,11 +1824,15 @@@ } else if (strcmp(s, "depth") == 0) { - ChangeSearchDepth(); + dsp->ChangeSearchDepth(sx + strlen("depth")); + } + else if (strcmp(s, "sd") == 0) + { + dsp->ChangeSearchDepth(sx + strlen("sd")); } else if (strcmp(s, "hashdepth") == 0) { - ChangeHashDepth(); + dsp->ChangeHashDepth(); } else if (strcmp(s, "random") == 0) { @@@ -1851,26 -1905,26 +1852,26 @@@ } else if (strcmp(s, "contempt") == 0) { - SetContempt(); + dsp->SetContempt(); } else if (strcmp(s, "xwndw") == 0) { - ChangeXwindow(); + dsp->ChangeXwindow(); } else if (strcmp(s, "rv") == 0) { flag.rv = !flag.rv; - UpdateDisplay(0, 0, 1, 0); + dsp->UpdateDisplay(0, 0, 1, 0); } else if (strcmp(s, "coords") == 0) { flag.coords = !flag.coords; - UpdateDisplay(0, 0, 1, 0); + dsp->UpdateDisplay(0, 0, 1, 0); } else if (strcmp(s, "stars") == 0) { flag.stars = !flag.stars; - UpdateDisplay(0, 0, 1, 0); + dsp->UpdateDisplay(0, 0, 1, 0); } else if (!XSHOGI && strcmp(s, "moves") == 0) { @@@ -1888,44 -1942,44 +1889,44 @@@ #endif SwagHt = 0; - ShowMessage("Testing MoveList Speed"); + dsp->ShowMessage("Testing MoveList Speed"); temp = generate_move_flags; generate_move_flags = true; TestSpeed(MoveList, 1); generate_move_flags = temp; - ShowMessage("Testing CaptureList Speed"); + dsp->ShowMessage("Testing CaptureList Speed"); TestSpeed(CaptureList, 1); - ShowMessage("Testing Eval Speed"); + dsp->ShowMessage("Testing Eval Speed"); ExaminePosition(opponent); TestPSpeed(ScorePosition, 1); } else if (!XSHOGI && strcmp(s, "test") == 0) { #ifdef SLOW_CPU - ShowMessage("Testing MoveList Speed"); + dsp->ShowMessage("Testing MoveList Speed"); TestSpeed(MoveList, 2000); - ShowMessage("Testing CaptureList Speed"); + dsp->ShowMessage("Testing CaptureList Speed"); TestSpeed(CaptureList, 3000); - ShowMessage("Testing Eval Speed"); + dsp->ShowMessage("Testing Eval Speed"); ExaminePosition(opponent); TestPSpeed(ScorePosition, 1500); #else - ShowMessage("Testing MoveList Speed"); + dsp->ShowMessage("Testing MoveList Speed"); TestSpeed(MoveList, 20000); - ShowMessage("Testing CaptureList Speed"); + dsp->ShowMessage("Testing CaptureList Speed"); TestSpeed(CaptureList, 30000); - ShowMessage("Testing Eval Speed"); + dsp->ShowMessage("Testing Eval Speed"); ExaminePosition(opponent); TestPSpeed(ScorePosition, 15000); #endif } else if (!XSHOGI && strcmp(s, "p") == 0) { - ShowPostnValues(); + dsp->ShowPostnValues(); } else if (!XSHOGI && strcmp(s, "debug") == 0) { - DoDebug(); + dsp->DoDebug(); } else { @@@ -1941,7 -1995,7 +1942,7 @@@ if (rpt >= 3) { DRAW = DRAW_REPETITION; - ShowMessage(DRAW); + dsp->ShowMessage(DRAW); GameList[GameCnt].flags |= draw; flag.mate = true; @@@ -1972,5 -2026,48 +1973,5 @@@ printf("%d. %s %ld\n", ++mycnt2, s, TimeControl.clock[player] * 10); } - -#ifdef notdef /* optional pass best line to frontend with move */ -# if !defined NOPOST - - if (flag.post && !flag.mate) - { - int i; - - printf(" %6d ", MSCORE); - - for (i = 1; MV[i] > 0; i++) - { - algbr((short) (MV[i] >> 8), (short) (MV[i] & 0xFF), false); - printf("%5s ", mvstr[0]); - } - } -# endif - printf("\n"); -#endif } } - - - - -void -SetTimeControl(void) -{ - if (TCflag) - { - TimeControl.moves[black] = TimeControl.moves[white] = TCmoves; - TimeControl.clock[black] += 6000L * TCminutes + TCseconds * 100; - TimeControl.clock[white] += 6000L * TCminutes + TCseconds * 100; - } - else - { - TimeControl.moves[black] = TimeControl.moves[white] = 0; - TimeControl.clock[black] = TimeControl.clock[white] = 0; - } - - flag.onemove = (TCmoves == 1); - et = 0; - ElapsedTime(COMPUTE_AND_INIT_MODE); -} - diff --combined gnushogi/cursesdsp.c index bf37999,d2b336b..2ee21ae --- a/gnushogi/cursesdsp.c +++ b/gnushogi/cursesdsp.c @@@ -37,7 -37,6 +37,7 @@@ #include #include #include +#include #include #include @@@ -45,6 -44,7 +45,6 @@@ #include #include "gnushogi.h" -#include "cursesdsp.h" #if HAVE_UNISTD_H #include @@@ -62,22 -62,24 +62,23 @@@ #define FLUSH_SCANW fflush(stdout), scanw -int mycnt1, mycnt2; - + #define MARGIN (5) #define TAB (58) #define VIR_C(s) ((flag.reverse) ? (NO_COLS - 1 - column(s)) : column(s)) #define VIR_R(s) ((flag.reverse) ? (NO_ROWS - 1 - row(s)) : row(s)) -unsigned short MV[MAXDEPTH]; -int MSCORE; -char *DRAW; +/**************************************** + * forward declarations + ****************************************/ -/* Forward declarations. */ /* FIXME: change this name, puh-leeze! */ static void UpdateCatched(void); static void DrawPiece(short sq); static void ShowScore(short score); +static void Curses_UpdateDisplay(short f, short t, short redraw, short isspec); +static void Curses_Die(int sig); +static void Curses_ShowSidetoMove(void); /**************************************** * Trivial output functions. @@@ -91,7 -93,7 +92,7 @@@ ClearEoln(void } -void +static void Curses_ClearScreen(void) { clear(); @@@ -107,6 -109,14 +108,13 @@@ gotoXY(short x, short y static void + ClearMessage(void) + { + gotoXY(TAB, 6); + ClearEoln(); + } + - -void ++static void Curses_ShowCurrentMove(short pnt, short f, short t) { algbr(f, t, false); @@@ -115,7 -125,7 +123,7 @@@ } -void +static void Curses_ShowDepth(char ch) { gotoXY(TAB, 4); @@@ -124,7 -134,7 +132,7 @@@ } -void +static void Curses_ShowGameType(void) { if (flag.post) @@@ -135,7 -145,7 +143,7 @@@ } -void +static void ShowHeader(void) { gotoXY(TAB, 2); @@@ -143,13 -153,13 +151,13 @@@ } -void +static void Curses_ShowLine(unsigned short *bstline) { } -void +static void Curses_ShowMessage(char *s) { gotoXY(TAB, 6); @@@ -158,38 -168,32 +166,38 @@@ } -void -Curses_AlwaysShowMessage(const char *format, va_list ap) +static void +Curses_AlwaysShowMessage(const char *format, ...) { static char buffer[60]; + va_list ap; + va_start(ap, format); vsnprintf(buffer, sizeof(buffer), format, ap); Curses_ShowMessage(buffer); + va_end(ap); } -void -Curses_Printf(const char *format, va_list ap) +static void +Curses_Printf(const char *format, ...) { static char buffer[60]; + va_list ap; + va_start(ap, format); vsnprintf(buffer, sizeof(buffer), format, ap); printw("%s", buffer); + va_end(ap); } -void +static void Curses_doRequestInputString(const char* fmt, char* buffer) { FLUSH_SCANW(fmt, buffer); } -int +static int Curses_GetString(char* sx) { fflush(stdout); @@@ -197,7 -201,7 +205,7 @@@ } -void +static void Curses_ShowNodeCnt(long NodeCnt) { gotoXY(TAB, 22); @@@ -208,7 -212,7 +216,7 @@@ } -void +static void Curses_ShowPatternCount(short side, short n) { if (flag.post) @@@ -233,7 -237,7 +241,7 @@@ ShowPlayers(void } -void +static void Curses_ShowPrompt(void) { Curses_ShowSidetoMove(); @@@ -243,7 -247,7 +251,7 @@@ } -void +static void Curses_ShowResponseTime(void) { if (flag.post) @@@ -257,7 -261,7 +265,7 @@@ } -void +static void Curses_ShowResults(short score, unsigned short *bstline, char ch) { unsigned char d, ply; @@@ -301,7 -305,7 +309,7 @@@ ShowScore(short score } -void +static void Curses_ShowSidetoMove(void) { gotoXY(TAB, 14); @@@ -310,7 -314,7 +318,7 @@@ } -void +static void Curses_ShowStage(void) { gotoXY(TAB, 19); @@@ -323,7 -327,7 +331,7 @@@ * End of trivial output routines. ****************************************/ -void +static void Curses_Initialize(void) { signal(SIGINT, Curses_Die); @@@ -333,7 -337,7 +341,7 @@@ } -void +static void Curses_ExitShogi(void) { if (!nolist) @@@ -349,7 -353,7 +357,7 @@@ } -void +static void Curses_Die(int sig) { char s[80]; @@@ -368,7 -372,7 +376,7 @@@ } -void +static void Curses_TerminateSearch(int sig) { signal(SIGINT, SIG_IGN); @@@ -384,7 -388,7 +392,7 @@@ } -void +static void Curses_help(void) { Curses_ClearScreen(); @@@ -442,8 -446,8 +450,8 @@@ } - static const short x0[2] = { 54, 2 }; - static const short y0[2] = { 20, 4 }; + static const short x0[2] = { MARGIN + 5*NO_COLS + 4, 2 }; + static const short y0[2] = { 4 + 2 * (NO_ROWS - 1), 4 }; /* @@@ -452,10 -456,10 +460,10 @@@ * P* will put a pawn to the captured pieces. */ -void +static void Curses_EditBoard(void) { - short a, c, sq, i; + short a, c, sq, i, found; short r = 0; char s[80]; @@@ -463,23 -467,28 +471,28 @@@ Book = BOOKFAIL; Curses_ClearScreen(); Curses_UpdateDisplay(0, 0, 1, 0); - gotoXY(TAB, 3); + gotoXY(TAB, 11); printw(". Exit to main\n"); - gotoXY(TAB, 4); + gotoXY(TAB, 12); printw("# Clear board\n"); - gotoXY(TAB, 5); + gotoXY(TAB, 13); printw("c Change sides\n"); gotoXY(TAB, 7); printw("Enter piece & location: "); a = black; - do + while(1) { - gotoXY(TAB, 6); + gotoXY(TAB, 4); printw("Editing: %s", ColorStr[a]); - gotoXY(TAB + 24, 7); + gotoXY(TAB + 2, 8); ClearEoln(); FLUSH_SCANW("%s", s); + found = 0; + ClearMessage(); + + if (s[0] == '.') + break; if (s[0] == '#') { @@@ -492,50 -501,61 +505,61 @@@ ClearCaptured(); UpdateCatched(); + continue; } - if (s[0] == 'c') + if (s[0] == 'c') { a = otherside[a]; + continue; + } if (s[1] == '*') { for (i = NO_PIECES; i > no_piece; i--) { if ((s[0] == pxx[i]) || (s[0] == qxx[i])) + { + Captured[a][unpromoted[i]]++; + UpdateCatched(); + found = 1; break; + } } - - Captured[a][unpromoted[i]]++; - UpdateCatched(); - c = -1; + if (!found) - AlwaysShowMessage("Invalid piece type '%c'", s[0]); ++ dsp->AlwaysShowMessage("Invalid piece type '%c'", s[0]); + continue; } - else - { - c = COL_NAME(s[1]); - r = ROW_NAME(s[2]); + + c = COL_NUM(s[1]); + r = ROW_NUM(s[2]); + + if ((c < 0) || (c >= NO_COLS) || (r < 0) || (r >= NO_ROWS)) { - AlwaysShowMessage("Out-of-board '%c%c'", s[1], s[2]); ++ dsp->AlwaysShowMessage("Out-of-board '%c%c'", s[1], s[2]); + continue; } - if ((c >= 0) && (c < NO_COLS) && (r >= 0) && (r < NO_ROWS)) - { - sq = locn(r, c); + sq = locn(r, c); - for (i = NO_PIECES; i > no_piece; i--) + for (i = NO_PIECES; i > no_piece; i--) + { + if ((s[0] == pxx[i]) || (s[0] == qxx[i])) { - if ((s[0] == pxx[i]) || (s[0] == qxx[i])) - break; + color[sq] = a; + if (s[3] == '+') + board[sq] = promoted[i]; + else + board[sq] = unpromoted[i]; + + found = 1; + break; } + } - if (s[3] == '+') - i = promoted[i]; - else - i = unpromoted[i]; + if (!found) - AlwaysShowMessage("Invalid piece type '%c'", s[0]); ++ dsp->AlwaysShowMessage("Invalid piece type '%c'", s[0]); - board[sq] = i; - color[sq] = ((board[sq] == no_piece) ? neutral : a); - DrawPiece(sq); - } + DrawPiece(sq); } - while (s[0] != '.'); for (sq = 0; sq < NO_SQUARES; sq++) Mvboard[sq] = ((board[sq] != Stboard[sq]) ? 10 : 0); @@@ -601,7 -621,7 +625,7 @@@ UpdateCatched( } -void +static void Curses_SearchStartStuff(short side) { short i; @@@ -617,7 -637,7 +641,7 @@@ } -void +static void Curses_OutputMove(void) { @@@ -672,7 -692,7 +696,7 @@@ t = (l + h) >> 1; } - ShowNodeCnt(NodeCnt); + Curses_ShowNodeCnt(NodeCnt); gotoXY(TAB, 23); printw("Max Tree = %5d", t); ClearEoln(); @@@ -682,7 -702,7 +706,7 @@@ } -void +static void Curses_UpdateClocks(void) { short m, s; @@@ -706,15 -726,15 +730,15 @@@ s = 0; if (player == black) - gotoXY(20, (flag.reverse) ? 2 : 23); + gotoXY(20, (flag.reverse) ? 2 : (5 + 2*NO_ROWS)); else - gotoXY(20, (flag.reverse) ? 23 : 2); + gotoXY(20, (flag.reverse) ? (5 + 2*NO_ROWS) : 2); /* printw("%d:%02d %ld ", m, s, dt); */ printw("%d:%02d ", m, s); if (flag.post) - ShowNodeCnt(NodeCnt); + Curses_ShowNodeCnt(NodeCnt); refresh(); } @@@ -753,7 -773,7 +777,7 @@@ DrawPiece(short sq y = pxx[(int)piece]; } - gotoXY(8 + 5 * VIR_C(sq), 4 + 2 * ((NO_ROWS - 1) - VIR_R(sq))); + gotoXY(MARGIN + 3 + 5 * VIR_C(sq), 4 + 2 * ((NO_ROWS - 1) - VIR_R(sq))); printw("%c%c%c%c", l, p, y, r); } @@@ -761,11 -781,13 +785,11 @@@ /* * Curses_ShowPostnValue(): must have called ExaminePosition() first */ -void +static void Curses_ShowPostnValue(short sq) { - short score; - gotoXY(4 + 5 * VIR_C(sq), 5 + 2 * (7 - VIR_R(sq))); /* CHECKME */ - score = ScorePosition(color[sq]); + (void) ScorePosition(color[sq]); if (color[sq] != neutral) #if defined SAVE_SVALUE @@@ -784,7 -806,7 +808,7 @@@ } -void +static void Curses_ShowPostnValues(void) { short sq, score; @@@ -804,7 -826,7 +828,7 @@@ } -void +static void Curses_UpdateDisplay(short f, short t, short redraw, short isspec) { short i, sq, z; @@@ -816,42 -838,41 +840,41 @@@ ShowPlayers(); i = 2; - gotoXY(3, ++i); + gotoXY(MARGIN, ++i); - printw(" +"); + printw(" +"); for (j=0; j + /* * Display options. */ @@@ -60,11 -58,14 +60,11 @@@ typedef enum extern display_t display_type; #define XSHOGI (display_type == DISPLAY_X) -#define NOT_CURSES ((display_type == DISPLAY_X) \ - || (display_type == DISPLAY_RAW)) /* Miscellaneous globals. */ extern short hard_time_limit; /* If you exceed time limit, you lose. */ -extern short barebones; /* Don't print of stats for x interface. */ extern short nolist; /* Don't list game after exit. */ @@@ -170,19 -171,19 +170,21 @@@ extern void movealgbr(short m, char *s) #define NO_PTYPE_PIECES 11 #define NO_COLS 5 #define NO_ROWS 5 +#define NO_CAMP_ROWS 1 #else #define NO_PIECES 15 #define MAX_CAPTURED 19 #define NO_PTYPE_PIECES 15 #define NO_COLS 9 #define NO_ROWS 9 +#define NO_CAMP_ROWS 3 #endif #define NO_SQUARES (NO_COLS*NO_ROWS) #define ROW_NAME(n) ('a' + NO_ROWS - 1 - n) #define COL_NAME(n) ('1' + NO_COLS - 1 - n) + #define ROW_NUM(c) ('a' + NO_ROWS - 1 - c) + #define COL_NUM(c) ('1' + NO_COLS - 1 - c) #if defined HASHFILE || defined CACHE # define PTBLBDSIZE (NO_SQUARES + NO_PIECES) @@@ -230,8 -231,13 +232,8 @@@ /* board properties */ -#ifndef MINISHOGI -#define InBlackCamp(sq) ((sq) < 27) -#define InWhiteCamp(sq) ((sq) > 53) -#else -#define InBlackCamp(sq) ((sq) < 5) -#define InWhiteCamp(sq) ((sq) > 19) -#endif +#define InBlackCamp(sq) ((sq) < (NO_COLS * NO_CAMP_ROWS)) +#define InWhiteCamp(sq) ((sq) >= (NO_COLS * (NO_ROWS - NO_CAMP_ROWS))) #define InPromotionZone(side, sq) \ (((side) == black) ? InWhiteCamp(sq) : InBlackCamp(sq)) @@@ -326,9 -332,13 +328,9 @@@ enum #ifndef MINISHOGI #define pxx (" PLNSGBRPLNSBRK ") #define qxx (" plnsgbrplnsbrk ") #else #define pxx (" PSGBRPSBRK ") #define qxx (" psgbrpsbrk ") -#define rxx ("edcba") -#define cxx ("54321") #endif /***************** Table limits ********************************************/ @@@ -675,6 -685,8 +677,6 @@@ extern long znodes extern char ColorStr[2][10]; extern char mvstr[4][6]; -extern unsigned short MV[MAXDEPTH]; -extern int MSCORE; extern int mycnt1, mycnt2; extern short ahead; extern struct leaf rootnode; @@@ -905,8 -917,10 +907,8 @@@ extern void Unlock_data(void); /* i extern void Initialize_dist(void); /* init.c */ extern void Initialize_eval(void); /* eval.c */ extern void NewGame(void); -extern int parse(FILE * fd, unsigned short *mv, - short side, char *opening); extern void GetOpenings(void); -extern int OpeningBook(unsigned short *hint, short side); +extern int OpeningBook(unsigned short *hint); typedef enum { @@@ -953,6 -967,7 +955,6 @@@ PutInTTable(short side short score, short depth, short ply, - short alpha, short beta, unsigned short mv); @@@ -1112,55 -1127,6 +1114,55 @@@ typedef enu extern int VerifyMove(char *s, VerifyMove_mode iop, unsigned short *mv); extern unsigned short TTage; -#include "dspwrappers.h" /* Display functions. */ +/* display driver framework */ + +struct display +{ + void (*ChangeAlphaWindow)(void); + void (*ChangeBetaWindow)(void); + void (*ChangeHashDepth)(void); + void (*ChangeSearchDepth)(char *sx); + void (*ChangeXwindow)(void); + void (*ClearScreen)(void); + void (*DoDebug)(void); + void (*DoTable)(short table[NO_SQUARES]); + void (*EditBoard)(void); + void (*ExitShogi)(void); + void (*GiveHint)(void); + void (*Initialize)(void); + void (*ShowNodeCnt)(long NodeCnt); + void (*OutputMove)(void); + void (*PollForInput)(void); + void (*SetContempt)(void); + void (*SearchStartStuff)(short side); + void (*SelectLevel)(char *sx); + void (*ShowCurrentMove)(short pnt, short f, short t); + void (*ShowDepth)(char ch); + void (*ShowGameType)(void); + void (*ShowLine)(unsigned short *bstline); + void (*ShowMessage)(char *s); + void (*AlwaysShowMessage)(const char *format, ...); + void (*Printf)(const char *format, ...); + void (*doRequestInputString)(const char* fmt, char* buffer); + int (*GetString)(char* sx); + void (*SetupBoard)(void); + void (*ShowPatternCount)(short side, short n); + void (*ShowPostnValue)(short sq); + void (*ShowPostnValues)(void); + void (*ShowPrompt)(void); + void (*ShowResponseTime)(void); + void (*ShowResults)(short score, unsigned short *bstline, char ch); + void (*ShowSidetoMove)(void); + void (*ShowStage)(void); + void (*TerminateSearch)(int sig); + void (*UpdateClocks)(void); + void (*UpdateDisplay)(short f, short t, short redraw, short isspec); + void (*help)(void); +}; + +extern struct display *dsp; + +extern struct display raw_display; +extern struct display curses_display; #endif /* _GNUSHOGI_H_ */ diff --combined gnushogi/rawdsp.c index 0a4e473,54bb7a1..588f13f --- a/gnushogi/rawdsp.c +++ b/gnushogi/rawdsp.c @@@ -33,7 -33,6 +33,7 @@@ #include #include #include +#include #include #include #include @@@ -43,48 -42,57 +43,48 @@@ #endif #include "gnushogi.h" -#include "rawdsp.h" -unsigned short MV[MAXDEPTH]; -int MSCORE; - -int mycnt1, mycnt2; -char *DRAW; -extern char *InPtr; -extern short pscore[]; +/**************************************** + * forward declarations + ****************************************/ +static void Raw_UpdateDisplay(short f, short t, short redraw, short isspec); /**************************************** * Trivial output functions. ****************************************/ -void +static void Raw_ClearScreen(void) { - if (!barebones && !XSHOGI) + if (!XSHOGI) printf("\n"); } -void +static void Raw_ShowPrompt(void) { - if (!barebones && !XSHOGI) - { + if (!XSHOGI) fputs("\nYour move is? ", stdout); } -void +static void Raw_ShowCurrentMove(short pnt, short f, short t) { } -void +static void Raw_ShowDepth(char ch) { - if (!barebones && !XSHOGI) - { - printf("Depth= %d%c ", Sdepth, ch); - printf("\n"); - } + if (!XSHOGI) + printf("Depth= %d%c \n", Sdepth, ch); } -void +static void Raw_ShowGameType(void) { if (flag.post) @@@ -92,7 -100,7 +92,7 @@@ } -void +static void Raw_ShowLine(unsigned short *bstline) { int i; @@@ -110,7 -118,7 +110,7 @@@ } -void +static void Raw_ShowMessage(char *s) { if (!XSHOGI) @@@ -118,54 -126,41 +118,54 @@@ } -void -Raw_AlwaysShowMessage(const char *format, va_list ap) +static void +Raw_AlwaysShowMessage(const char *format, ...) { + va_list ap; + va_start(ap, format); vprintf(format, ap); printf("\n"); + va_end(ap); } -void -Raw_Printf(const char *format, va_list ap) +static void +Raw_Printf(const char *format, ...) { + va_list ap; + va_start(ap, format); vprintf(format, ap); + va_end(ap); } -void +static void Raw_doRequestInputString(const char* fmt, char* buffer) { scanf(fmt, buffer); } -int +static int Raw_GetString(char* sx) { int eof = 0; + char *nl; sx[0] = '\0'; while(!eof && !sx[0]) eof = (fgets(sx, 80, stdin) == NULL); + + /* remove any trailing newline */ + nl = strchr(sx, '\n'); + if (nl) + nl[0] = '\0'; + return eof; } -void +static void Raw_ShowNodeCnt(long NodeCnt) { printf("Nodes = %ld Nodes/sec = %ld\n", @@@ -173,7 -168,7 +173,7 @@@ } -void +static void Raw_ShowPatternCount(short side, short n) { if (flag.post) @@@ -181,13 -176,13 +181,13 @@@ } -void +static void Raw_ShowResponseTime(void) { } -void +static void Raw_ShowResults(short score, unsigned short *bstline, char ch) { if (flag.post && !XSHOGI) @@@ -200,13 -195,13 +200,13 @@@ } -void +static void Raw_ShowSidetoMove(void) { } -void +static void Raw_ShowStage(void) { printf("stage = %d\n", stage); @@@ -218,7 -213,7 +218,7 @@@ * End of trivial output routines. ****************************************/ -void +static void Raw_Initialize(void) { mycnt1 = mycnt2 = 0; @@@ -250,7 -245,7 +250,7 @@@ } -void +static void Raw_ExitShogi(void) { /* CHECKME: what purpose does this next statement serve? */ @@@ -263,7 -258,20 +263,7 @@@ } -void -Raw_Die(int sig) -{ - char s[80]; - - Raw_ShowMessage("Abort? "); - scanf("%s", s); - - if (strcmp(s, "yes") == 0) - Raw_ExitShogi(); -} - - -void +static void Raw_TerminateSearch(int sig) { #ifdef INTERRUPT_TEST @@@ -277,53 -285,35 +277,53 @@@ } -void +static void Raw_help(void) { Raw_ClearScreen(); printf("GNU Shogi %s command summary\n", PACKAGE_VERSION); - printf("----------------------------------" - "------------------------------\n"); - fputs ("7g7f move from 7g to 7f quit Exit Shogi\n", stdout); - printf("S6h move silver to 6h beep turn %s\n", (flag.beep) ? "OFF" : "ON"); - printf("2d2c+ move to 2c and promote material turn %s\n", (flag.material) ? "OFF" : "ON"); - printf("P*5e drop pawn to 5e easy turn %s\n", (flag.easy) ? "OFF" : "ON"); - printf("tsume toggle tsume mode hash turn %s\n", (flag.hash) ? "OFF" : "ON"); - fputs ("bd redraw board reverse board display\n", stdout); - printf("list game to shogi.lst book turn %s used %d of %d\n", (Book) ? "OFF" : "ON", bookcount, booksize); - fputs ("undo undo last ply remove take back a move\n", stdout); - fputs ("edit edit board force toggle manual move mode\n", stdout); - fputs ("switch sides with computer both computer match\n", stdout); - fputs ("black computer plays black white computer plays white\n", stdout); - fputs ("depth set search depth clock set time control\n", stdout); - fputs ("post principle variation hint suggest a move\n", stdout); - fputs ("save game to file get game from file\n", stdout); - printf("xsave pos. to xshogi file xget" - " pos. from xshogi file\n"); - fputs("random randomize play new start new game\n", stdout); - printf("--------------------------------" - "--------------------------------\n"); + printf("----------------------------------------------------------------\n"); + printf("7g7f move from 7g to 7f quit Exit Shogi\n"); + printf("S6h move silver to 6h beep turn %s\n", + (flag.beep) ? "OFF" : "ON"); + printf("2d2c+ move to 2c and promote material turn %s\n", + (flag.material) ? "OFF" : "ON"); + printf("P*5e drop pawn to 5e easy turn %s\n", + (flag.easy) ? "OFF" : "ON"); + printf("tsume toggle tsume mode hash turn %s\n", + (flag.hash) ? "OFF" : "ON"); + printf("bd redraw board reverse board display\n"); + printf("list game to shogi.lst book turn %s used %d of %d\n", + (Book) ? "OFF" : "ON", bookcount, booksize); + printf("undo undo last ply remove take back a move\n"); + printf("edit edit board force toggle manual move mode\n"); + printf("switch sides with computer both computer match\n"); + printf("black computer plays black white computer plays white\n"); + printf("sd set search depth clock set time control\n"); + printf("post principle variation hint suggest a move\n"); + printf("save game to file get game from file\n"); + printf("xsave pos. to xshogi file xget pos. from xshogi file\n"); + printf("random randomize play new start new game\n"); + printf("setup first \n"); + printf("go computer plays now material turn %s\n", + flag.material ? "OFF" : "ON"); + printf("level time control gamein \n"); + printf("time set engine clock otime set opponent clock\n"); + printf("Awindow Bwindow \n"); + printf("rcptr turn %3s bsave book save\n", + flag.rcptr ? "OFF" : "ON "); + printf("hashdepth hard turn easy OFF\n"); + printf("contempt xwndw \n"); + printf("rv turn %3s coords turn %s\n", + flag.rv ? "OFF" : "ON ", flag.coords ? "OFF" : "ON"); + printf("stars turn %3s moves \n", + flag.stars ? "OFF" : "ON "); + printf("test p \n"); + printf("debug depth alias for 'sd'\n"); + printf("----------------------------------------------------------------\n"); printf("Computer: %-12s Opponent: %s\n", ColorStr[computer], ColorStr[opponent]); - printf("Depth: %-12d Response time: %d sec\n", + printf("Depth: %-12d Response time: %ld sec\n", MaxSearchDepth, MaxResponseTime/100); printf("Random: %-12s Easy mode: %s\n", (dither) ? "ON" : "OFF", (flag.easy) ? "ON" : "OFF"); @@@ -331,7 -321,7 +331,7 @@@ (flag.beep) ? "ON" : "OFF", (flag.hash) ? "ON" : "OFF"); printf("Tsume: %-12s Force: %s\n", (flag.tsume) ? "ON" : "OFF", (flag.force) ? "ON" : "OFF"); - printf("Time Control %s %d moves %d sec %d add %d depth\n", + printf("Time Control %s %d moves %ld sec %d add %d depth\n", (TCflag) ? "ON" : "OFF", TimeControl.moves[black], TimeControl.clock[black] / 100, TCadd/100, MaxSearchDepth); @@@ -342,7 -332,7 +342,7 @@@ * Set up a board position. Pieces are entered by typing the piece followed * by the location. For example, Nf3 will place a knight on square f3. */ -void +static void Raw_EditBoard(void) { short a, r, c, sq, i, found; @@@ -352,18 -342,21 +352,21 @@@ Book = BOOKFAIL; Raw_ClearScreen(); Raw_UpdateDisplay(0, 0, 1, 0); - fputs(". Exit to main\n", stdout); - fputs("# Clear board\n", stdout); - fputs("c Change sides\n", stdout); - fputs("enter piece & location: \n", stdout); + printf(". Exit to main\n"); + printf("# Clear board\n"); + printf("c Change sides\n"); + printf("enter piece & location:\n"); a = black; - do + while(1) { scanf("%s", s); found = 0; + if (s[0] == '.') + break; + if (s[0] == '#') { for (sq = 0; sq < NO_SQUARES; sq++) @@@ -373,10 -366,13 +376,13 @@@ } ClearCaptured(); + continue; } - if (s[0] == 'c') + if (s[0] == 'c') { a = otherside[a]; + continue; + } if (s[1] == '*') { @@@ -389,41 -385,39 +395,39 @@@ break; } } - - c = -1; - r = -1; + if (!found) + printf("# Invalid piece type '%c'\n", s[0]); + continue; } - else - { - c = COL_NAME(s[1]); - r = ROW_NAME(s[2]); + + c = COL_NUM(s[1]); + r = ROW_NUM(s[2]); + + if ((c < 0) || (c >= NO_COLS) || (r < 0) || (r >= NO_ROWS)) { + printf("# Out-of-board position '%c%c'\n", s[1], s[2]); + continue; } - if ((c >= 0) && (c < NO_COLS) && (r >= 0) && (r < NO_ROWS)) - { - sq = locn(r, c); - color[sq] = a; - board[sq] = no_piece; + sq = locn(r, c); - for (i = no_piece; i <= king; i++) + for (i = no_piece; i <= king; i++) + { + if ((s[0] == pxx[i]) || (s[0] == qxx[i])) { - if ((s[0] == pxx[i]) || (s[0] == qxx[i])) - { - if (s[3] == '+') - board[sq] = promoted[i]; - else - board[sq] = i; - - found = 1; - break; - } + color[sq] = a; + if (s[3] == '+') + board[sq] = promoted[i]; + else + board[sq] = i; + + found = 1; + break; } - - if (found == 0) - color[sq] = neutral; } + + if (!found) + printf("# Invalid piece type '%c'\n", s[0]); } - while (s[0] != '.'); for (sq = 0; sq < NO_SQUARES; sq++) Mvboard[sq] = ((board[sq] != Stboard[sq]) ? 10 : 0); @@@ -443,7 -437,7 +447,7 @@@ * Nine lines of nine characters are used to setup the board. 9a-1a is the * first line. White pieces are represented by uppercase characters. */ -void +static void Raw_SetupBoard(void) { short r, c, sq, i; @@@ -493,7 -487,7 +497,7 @@@ } -void +static void Raw_SearchStartStuff(short side) { if (flag.post) @@@ -505,7 -499,7 +509,7 @@@ } -void +static void Raw_OutputMove(void) { if (flag.illegal) @@@ -518,11 -512,15 +522,11 @@@ goto nomove; if (XSHOGI) /* add remaining time in milliseconds to xshogi */ printf("%d. ... %s %ld\n", ++mycnt1, mvstr[0], (TimeControl.clock[player] - et) * 10); - } else - { printf("%d. ... %s\n", ++mycnt1, mvstr[0]); - } nomove: if ((root->flags & draw) || (root->score == -(SCORE_LIMIT + 999)) @@@ -567,29 -565,39 +571,29 @@@ summary: if (root->flags & draw) - { fputs("Drawn game!\n", stdout); - } else if (root->score == -(SCORE_LIMIT + 999)) - { printf("%s mates!\n", ColorStr[opponent]); - } else if (root->score == (SCORE_LIMIT + 998)) - { printf("%s mates!\n", ColorStr[computer]); - } #ifdef VERYBUGGY - else if (!barebones && (root->score < -SCORE_LIMIT)) - { + else if (!XSHOGI && (root->score < -SCORE_LIMIT)) printf("%s has a forced mate in %d moves!\n", ColorStr[opponent], SCORE_LIMIT + 999 + root->score - 1); - } - else if (!barebones && (root->score > SCORE_LIMIT)) - { + else if (!XSHOGI && (root->score > SCORE_LIMIT)) printf("%s has a forced mate in %d moves!\n", ColorStr[computer], SCORE_LIMIT + 998 - root->score - 1); - } #endif /* VERYBUGGY */ } -void +static void Raw_UpdateClocks(void) { } -void +static void Raw_UpdateDisplay(short f, short t, short redraw, short isspec) { @@@ -648,7 -656,7 +652,7 @@@ } -void +static void Raw_ChangeAlphaWindow(void) { printf("WAwindow: "); @@@ -658,7 -666,7 +662,7 @@@ } -void +static void Raw_ChangeBetaWindow(void) { printf("WBwindow: "); @@@ -668,7 -676,7 +672,7 @@@ } -void +static void Raw_GiveHint(void) { if (hint) @@@ -681,20 -689,31 +685,20 @@@ } -void +static void Raw_SelectLevel(char *sx) { + /* FIXME: NO_SQUARES is nonsense here */ + char T[NO_SQUARES + 1], *p; - char T[NO_SQUARES + 1], *p, *q; - - if ((p = strstr(sx, "level")) != NULL) - p += strlen("level"); - else if ((p = strstr(sx, "clock")) != NULL) - p += strlen("clock"); - - strcat(sx, "XX"); - q = T; - *q = '\0'; + strncpy(T, sx, NO_SQUARES); + T[NO_SQUARES] = '\0'; - for (; *p != 'X'; *q++ = *p++); - - *q = '\0'; - - /* line empty ask for input */ + /* if line empty, ask for input */ if (!T[0]) { fputs("Enter #moves #minutes: ", stdout); fgets(T, NO_SQUARES + 1, stdin); - strcat(T, "XX"); } /* skip blackspace */ @@@ -704,7 -723,6 +708,7 @@@ if (*p == 'f') { /* its a fischer clock game */ + char *q; p++; TCminutes = (short)strtol(p, &q, 10); TCadd = (short)strtol(q, NULL, 10) *100; @@@ -714,7 -732,6 +718,7 @@@ else { /* regular game */ + char *q; TCadd = 0; TCmoves = (short)strtol(p, &q, 10); TCminutes = (short)strtol(q, &q, 10); @@@ -754,22 -771,16 +758,22 @@@ } -void -Raw_ChangeSearchDepth(void) +static void +Raw_ChangeSearchDepth(char *sx) { - printf("depth = "); - scanf("%hd", &MaxSearchDepth); + char buf[80+1]; + strncpy(buf, sx, 80); buf[80] = '\0'; + /* if line empty, ask for input */ + if (!buf[0]) { + printf("depth = "); + fgets(buf, 80+1, stdin); + } + sscanf(buf, "%hd", &MaxSearchDepth); TCflag = !(MaxSearchDepth > 0); } -void +static void Raw_ChangeHashDepth(void) { printf("hashdepth = "); @@@ -779,7 -790,7 +783,7 @@@ } -void +static void Raw_SetContempt(void) { printf("contempt = "); @@@ -787,7 -798,7 +791,7 @@@ } -void +static void Raw_ChangeXwindow(void) { printf("xwndw = "); @@@ -799,10 -810,11 +803,10 @@@ * Raw_ShowPostnValue(short sq) * must have called ExaminePosition() first */ -void +static void Raw_ShowPostnValue(short sq) { - short score; - score = ScorePosition(color[sq]); + (void) ScorePosition(color[sq]); if (color[sq] != neutral) { @@@ -819,7 -831,7 +823,7 @@@ } -void +static void Raw_DoDebug(void) { short c, p, sq, tp, tc, tsq, score, j, k; @@@ -897,7 -909,7 +901,7 @@@ } -void +static void Raw_DoTable(short table[NO_SQUARES]) { short sq, j, k; @@@ -916,7 -928,7 +920,7 @@@ } -void +static void Raw_ShowPostnValues(void) { short sq, score, j, k; @@@ -941,7 -953,7 +945,7 @@@ } -void +static void Raw_PollForInput(void) { #ifdef WIN32 @@@ -949,12 -961,12 +953,12 @@@ if (!PeekNamedPipe(GetStdHandle(STD_INPUT_HANDLE), NULL, 0, NULL, &cnt, NULL)) cnt = 1; #else - static struct pollfd pollfds[1] = { /* [0] = */ { /* .fd = */ STDIN_FILENO, - /* .events = */ POLLIN } }; + static struct pollfd pollfds[1] = { [0] = { .fd = STDIN_FILENO, + .events = POLLIN } }; int cnt = poll(pollfds, sizeof(pollfds)/sizeof(pollfds[0]), 0); if (cnt < 0) { perror("polling standard input"); - ExitShogi(); + Raw_ExitShogi(); } #endif if (cnt) { /* if anything to read, or error occured */ @@@ -963,47 -975,3 +967,47 @@@ flag.bothsides = false; } } + +struct display raw_display = +{ + .ChangeAlphaWindow = Raw_ChangeAlphaWindow, + .ChangeBetaWindow = Raw_ChangeBetaWindow, + .ChangeHashDepth = Raw_ChangeHashDepth, + .ChangeSearchDepth = Raw_ChangeSearchDepth, + .ChangeXwindow = Raw_ChangeXwindow, + .ClearScreen = Raw_ClearScreen, + .DoDebug = Raw_DoDebug, + .DoTable = Raw_DoTable, + .EditBoard = Raw_EditBoard, + .ExitShogi = Raw_ExitShogi, + .GiveHint = Raw_GiveHint, + .Initialize = Raw_Initialize, + .ShowNodeCnt = Raw_ShowNodeCnt, + .OutputMove = Raw_OutputMove, + .PollForInput = Raw_PollForInput, + .SetContempt = Raw_SetContempt, + .SearchStartStuff = Raw_SearchStartStuff, + .SelectLevel = Raw_SelectLevel, + .ShowCurrentMove = Raw_ShowCurrentMove, + .ShowDepth = Raw_ShowDepth, + .ShowGameType = Raw_ShowGameType, + .ShowLine = Raw_ShowLine, + .ShowMessage = Raw_ShowMessage, + .AlwaysShowMessage = Raw_AlwaysShowMessage, + .Printf = Raw_Printf, + .doRequestInputString = Raw_doRequestInputString, + .GetString = Raw_GetString, + .SetupBoard = Raw_SetupBoard, + .ShowPatternCount = Raw_ShowPatternCount, + .ShowPostnValue = Raw_ShowPostnValue, + .ShowPostnValues = Raw_ShowPostnValues, + .ShowPrompt = Raw_ShowPrompt, + .ShowResponseTime = Raw_ShowResponseTime, + .ShowResults = Raw_ShowResults, + .ShowSidetoMove = Raw_ShowSidetoMove, + .ShowStage = Raw_ShowStage, + .TerminateSearch = Raw_TerminateSearch, + .UpdateClocks = Raw_UpdateClocks, + .UpdateDisplay = Raw_UpdateDisplay, + .help = Raw_help, +}; diff --combined gnushogi/util.c index 927f3d8,0c7911d..96c702f --- a/gnushogi/util.c +++ b/gnushogi/util.c @@@ -36,9 -36,9 +36,9 @@@ unsigned int TTadd = 0 short recycle; short ISZERO = 1; - +#if 0 int -parse(FILE * fd, unsigned short *mv, short side, char *opening) +parse(FILE * fd, unsigned short *mv, char *opening) { int c, i, r1, r2, c1, c2; char s[128]; @@@ -85,10 -85,10 +85,10 @@@ return 0; } - c1 = COL_NAME(s[0]); - r1 = ROW_NAME(s[1]); - c2 = COL_NAME(s[2]); - r2 = ROW_NAME(s[3]); + c1 = COL_NUM(s[0]); + r1 = ROW_NUM(s[1]); + c2 = COL_NUM(s[2]); + r2 = ROW_NUM(s[3]); *mv = (locn(r1, c1) << 8) | locn(r2, c2); if (c == '?') @@@ -100,7 -100,7 +100,7 @@@ return 1; } - +#endif /* * The field of a hashtable is computed as follows: @@@ -174,7 -174,7 +174,7 @@@ ProbeTTable (short side { HashCol++; - if (!barebones) + if (!XSHOGI) { ShowMessage("ttable collision detected"); ShowBD(ptbl->bd); @@@ -227,6 -227,7 +227,6 @@@ PutInTTable(short side short score, short depth, short ply, - short alpha, short beta, unsigned short mv) {