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):
+ 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
- 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
* 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
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
##########
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])
],
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?
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])
])
##########
+
+# 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
#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)
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)
#endif /* BOOKTEST */
-
-
/*
* Generate move strings in different formats.
*
* - 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
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';
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]);
}
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];
}
-
/*
* 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.
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
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);
char buf[20];
sprintf(buf, "%s mates!\n", ColorStr[opponent]);
- ShowMessage(buf);
+ dsp->ShowMessage(buf);
flag.mate = true;
}
}
}
}
- 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;
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;
}
-
void
skipb()
{
}
+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;
if (savefile[0]) {
strcpy(fname, savefile);
} else {
- ShowMessage("Enter file name: ");
+ dsp->ShowMessage("Enter file name: ");
RequestInputString(fname, sizeof(fname)-1);
}
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();
ZeroRPT();
InitializeStats();
- UpdateDisplay(0, 0, 1, 0);
+ dsp->UpdateDisplay(0, 0, 1, 0);
Sdepth = 0;
hint = 0;
}
-
-void
+static void
SaveGame(void)
{
FILE *fd;
if (savefile[0]) {
strcpy(fname, savefile);
} else {
- ShowMessage("Enter file name: ");
+ dsp->ShowMessage("Enter file name: ");
RequestInputString(fname, sizeof(fname)-1);
}
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;
short sq;
short side, isp;
- ShowMessage("Enter file name: ");
+ dsp->ShowMessage("Enter file name: ");
RequestInputString(fname, sizeof(fname)-1);
if (fname[0] == '\0')
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;
short sq, piece;
short side, isp;
- ShowMessage("Enter file name: ");
+ dsp->ShowMessage("Enter file name: ");
RequestInputString(fname, sizeof(fname)-1);
if (fname[0] == '\0')
}
-void
+static void
BookSave(void)
{
FILE *fd;
strcpy(fname, savefile);
} else {
/* Enter file name */
- ShowMessage("Enter file name: ");
+ dsp->ShowMessage("Enter file name: ");
RequestInputString(fname, sizeof(fname)-1);
}
fclose(fd);
- ShowMessage("Game saved");
+ dsp->ShowMessage("Game saved");
}
else
{
- ShowMessage("Could not open file");
+ dsp->ShowMessage("Could not open file");
}
}
-
void
ListGame(void)
{
}
-
-void
+static void
FlagMove(char c)
{
switch(c)
}
-
-
/*
* Undo the most recent half-move.
*/
-void
+static void
Undo(void)
{
short f, t;
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)
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;
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);
}
}
-
-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);
}
}
-
-
-
/* 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;
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))
Sdepth = 0;
#ifdef QUIETBACKGROUND
- ShowPrompt();
+ dsp->ShowPrompt();
have_shown_prompt = true;
#endif /* QUIETBACKGROUND */
{
#endif /* QUIETBACKGROUND */
- ShowPrompt();
+ dsp->ShowPrompt();
#ifdef QUIETBACKGROUND
}
#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 */
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;
}
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)
{
}
else if (strcmp(s, "help") == 0)
{
- help();
+ dsp->help();
}
else if (strcmp(s, "material") == 0)
{
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)
{
}
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)
{
}
else if (strcmp(s, "hint") == 0)
{
- GiveHint();
+ dsp->GiveHint();
}
else if (strcmp(s, "both") == 0)
{
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)
{
flag.force = false;
Sdepth = 0;
ok = true;
- UpdateDisplay(0, 0, 1, 0);
++ dsp->UpdateDisplay(0, 0, 1, 0);
}
else if (strcmp(s, "black") == 0)
{
}
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)
{
}
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)
{
#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
{
if (rpt >= 3)
{
DRAW = DRAW_REPETITION;
- ShowMessage(DRAW);
+ dsp->ShowMessage(DRAW);
GameList[GameCnt].flags |= draw;
flag.mate = true;
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);
-}
-
#include <ctype.h>
#include <signal.h>
#include <stdio.h>
+#include <stdarg.h>
#include <sys/param.h>
#include <sys/types.h>
#include <curses.h>
#include "gnushogi.h"
-#include "cursesdsp.h"
#if HAVE_UNISTD_H
#include <unistd.h>
#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.
}
-void
+static void
Curses_ClearScreen(void)
{
clear();
static void
+ ClearMessage(void)
+ {
+ gotoXY(TAB, 6);
+ ClearEoln();
+ }
+
-
-void
++static void
Curses_ShowCurrentMove(short pnt, short f, short t)
{
algbr(f, t, false);
}
-void
+static void
Curses_ShowDepth(char ch)
{
gotoXY(TAB, 4);
}
-void
+static void
Curses_ShowGameType(void)
{
if (flag.post)
}
-void
+static void
ShowHeader(void)
{
gotoXY(TAB, 2);
}
-void
+static void
Curses_ShowLine(unsigned short *bstline)
{
}
-void
+static void
Curses_ShowMessage(char *s)
{
gotoXY(TAB, 6);
}
-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);
}
-void
+static void
Curses_ShowNodeCnt(long NodeCnt)
{
gotoXY(TAB, 22);
}
-void
+static void
Curses_ShowPatternCount(short side, short n)
{
if (flag.post)
}
-void
+static void
Curses_ShowPrompt(void)
{
Curses_ShowSidetoMove();
}
-void
+static void
Curses_ShowResponseTime(void)
{
if (flag.post)
}
-void
+static void
Curses_ShowResults(short score, unsigned short *bstline, char ch)
{
unsigned char d, ply;
}
-void
+static void
Curses_ShowSidetoMove(void)
{
gotoXY(TAB, 14);
}
-void
+static void
Curses_ShowStage(void)
{
gotoXY(TAB, 19);
* End of trivial output routines.
****************************************/
-void
+static void
Curses_Initialize(void)
{
signal(SIGINT, Curses_Die);
}
-void
+static void
Curses_ExitShogi(void)
{
if (!nolist)
}
-void
+static void
Curses_Die(int sig)
{
char s[80];
}
-void
+static void
Curses_TerminateSearch(int sig)
{
signal(SIGINT, SIG_IGN);
}
-void
+static void
Curses_help(void)
{
Curses_ClearScreen();
}
- 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 };
/*
* 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];
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] == '#')
{
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);
}
-void
+static void
Curses_SearchStartStuff(short side)
{
short i;
}
-void
+static void
Curses_OutputMove(void)
{
t = (l + h) >> 1;
}
- ShowNodeCnt(NodeCnt);
+ Curses_ShowNodeCnt(NodeCnt);
gotoXY(TAB, 23);
printw("Max Tree = %5d", t);
ClearEoln();
}
-void
+static void
Curses_UpdateClocks(void)
{
short m, s;
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();
}
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);
}
/*
* 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
}
-void
+static void
Curses_ShowPostnValues(void)
{
short sq, score;
}
-void
+static void
Curses_UpdateDisplay(short f, short t, short redraw, short isspec)
{
short i, sq, z;
ShowPlayers();
i = 2;
- gotoXY(3, ++i);
+ gotoXY(MARGIN, ++i);
- printw(" +");
+ printw(" +");
for (j=0; j<NO_COLS; j++)
printw("----+");
while (i <= 1 + 2*NO_ROWS)
{
- gotoXY(1, ++i);
+ gotoXY(MARGIN, ++i);
if (flag.reverse)
z = (i / 2) - 1;
else
z = NO_ROWS + 2 - ((i + 1) / 2);
- printw(" %c |", ROW_NAME(z+1));
+ printw("%c |", ROW_NAME(z+1));
for (j=0; j<NO_COLS; j++)
printw(" |");
- gotoXY(3, ++i);
+ gotoXY(MARGIN, ++i);
if (i < 2 + 2*NO_ROWS)
{
- printw(" +");
+ printw(" +");
for (j=0; j<NO_COLS; j++)
printw("----+");
}
}
- printw(" +");
+ printw(" +");
for (j=0; j<NO_COLS; j++)
printw("----+");
- gotoXY(3, 4 + 2*NO_ROWS);
- printw(" ");
-
+ gotoXY(MARGIN, 4 + 2*NO_ROWS);
+ printw(" ");
#ifndef MINISHOGI
if (flag.reverse)
printw(" 1 2 3 4 5 6 7 8 9");
if (flag.reverse)
printw(" 1 2 3 4 5");
else
- printw(" 1 2 3 4 5");
+ printw(" 5 4 3 2 1");
#endif
for (sq = 0; sq < NO_SQUARES; sq++)
}
-void
+static void
Curses_ChangeAlphaWindow(void)
{
Curses_ShowMessage("WAwindow = ");
}
-void
+static void
Curses_ChangeBetaWindow(void)
{
Curses_ShowMessage("WBwindow = ");
}
-void
+static void
Curses_GiveHint(void)
{
char s[40];
}
-void
-Curses_ChangeSearchDepth(void)
+static void
+Curses_ChangeSearchDepth(char* sx)
{
Curses_ShowMessage("depth = ");
FLUSH_SCANW("%hd", &MaxSearchDepth);
}
-void
+static void
Curses_ChangeHashDepth(void)
{
Curses_ShowMessage("hashdepth = ");
}
-void
+static void
Curses_SetContempt(void)
{
Curses_ShowMessage("contempt = ");
}
-void
+static void
Curses_ChangeXwindow(void)
{
Curses_ShowMessage("xwndw= ");
}
-void
+static void
Curses_SelectLevel(char *sx)
{
int item;
}
-void
+static void
Curses_DoDebug(void)
{
short c, p, sq, tp, tc, tsq, score;
}
-void
+static void
Curses_DoTable(short table[NO_SQUARES])
{
short sq;
}
-void
+static void
Curses_PollForInput(void)
{
int i;
}
-void
+static void
Curses_SetupBoard(void)
{
Curses_ShowMessage("'setup' command is not supported in Cursesmode");
}
+
+
+struct display curses_display =
+{
+ .ChangeAlphaWindow = Curses_ChangeAlphaWindow,
+ .ChangeBetaWindow = Curses_ChangeBetaWindow,
+ .ChangeHashDepth = Curses_ChangeHashDepth,
+ .ChangeSearchDepth = Curses_ChangeSearchDepth,
+ .ChangeXwindow = Curses_ChangeXwindow,
+ .ClearScreen = Curses_ClearScreen,
+ .DoDebug = Curses_DoDebug,
+ .DoTable = Curses_DoTable,
+ .EditBoard = Curses_EditBoard,
+ .ExitShogi = Curses_ExitShogi,
+ .GiveHint = Curses_GiveHint,
+ .Initialize = Curses_Initialize,
+ .ShowNodeCnt = Curses_ShowNodeCnt,
+ .OutputMove = Curses_OutputMove,
+ .PollForInput = Curses_PollForInput,
+ .SetContempt = Curses_SetContempt,
+ .SearchStartStuff = Curses_SearchStartStuff,
+ .SelectLevel = Curses_SelectLevel,
+ .ShowCurrentMove = Curses_ShowCurrentMove,
+ .ShowDepth = Curses_ShowDepth,
+ .ShowGameType = Curses_ShowGameType,
+ .ShowLine = Curses_ShowLine,
+ .ShowMessage = Curses_ShowMessage,
+ .AlwaysShowMessage = Curses_AlwaysShowMessage,
+ .Printf = Curses_Printf,
+ .doRequestInputString = Curses_doRequestInputString,
+ .GetString = Curses_GetString,
+ .SetupBoard = Curses_SetupBoard,
+ .ShowPatternCount = Curses_ShowPatternCount,
+ .ShowPostnValue = Curses_ShowPostnValue,
+ .ShowPostnValues = Curses_ShowPostnValues,
+ .ShowPrompt = Curses_ShowPrompt,
+ .ShowResponseTime = Curses_ShowResponseTime,
+ .ShowResults = Curses_ShowResults,
+ .ShowSidetoMove = Curses_ShowSidetoMove,
+ .ShowStage = Curses_ShowStage,
+ .TerminateSearch = Curses_TerminateSearch,
+ .UpdateClocks = Curses_UpdateClocks,
+ .UpdateDisplay = Curses_UpdateDisplay,
+ .help = Curses_help,
+};
#include "debug.h"
#include "opts.h" /* Various option-setting #defines. */
+#include <stdarg.h>
+
/*
* Display options.
*/
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. */
#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)
/* 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))
#ifndef MINISHOGI
#define pxx (" PLNSGBRPLNSBRK ")
#define qxx (" plnsgbrplnsbrk ")
#else
#define pxx (" PSGBRPSBRK ")
#define qxx (" psgbrpsbrk ")
-#define rxx ("edcba")
-#define cxx ("54321")
#endif
/***************** Table limits ********************************************/
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;
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
{
short score,
short depth,
short ply,
- short alpha,
short beta,
unsigned short mv);
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_ */
#include <ctype.h>
#include <signal.h>
#include <stdarg.h>
+#include <stdio.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/file.h>
#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)
}
-void
+static void
Raw_ShowLine(unsigned short *bstline)
{
int i;
}
-void
+static void
Raw_ShowMessage(char *s)
{
if (!XSHOGI)
}
-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",
}
-void
+static void
Raw_ShowPatternCount(short side, short n)
{
if (flag.post)
}
-void
+static void
Raw_ShowResponseTime(void)
{
}
-void
+static void
Raw_ShowResults(short score, unsigned short *bstline, char ch)
{
if (flag.post && !XSHOGI)
}
-void
+static void
Raw_ShowSidetoMove(void)
{
}
-void
+static void
Raw_ShowStage(void)
{
printf("stage = %d\n", stage);
* End of trivial output routines.
****************************************/
-void
+static void
Raw_Initialize(void)
{
mycnt1 = mycnt2 = 0;
}
-void
+static void
Raw_ExitShogi(void)
{
/* CHECKME: what purpose does this next statement serve? */
}
-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
}
-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");
(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);
* 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;
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++)
}
ClearCaptured();
+ continue;
}
- if (s[0] == 'c')
+ if (s[0] == 'c') {
a = otherside[a];
+ continue;
+ }
if (s[1] == '*')
{
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);
* 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;
}
-void
+static void
Raw_SearchStartStuff(short side)
{
if (flag.post)
}
-void
+static void
Raw_OutputMove(void)
{
if (flag.illegal)
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))
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)
{
}
-void
+static void
Raw_ChangeAlphaWindow(void)
{
printf("WAwindow: ");
}
-void
+static void
Raw_ChangeBetaWindow(void)
{
printf("WBwindow: ");
}
-void
+static void
Raw_GiveHint(void)
{
if (hint)
}
-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 */
if (*p == 'f')
{
/* its a fischer clock game */
+ char *q;
p++;
TCminutes = (short)strtol(p, &q, 10);
TCadd = (short)strtol(q, NULL, 10) *100;
else
{
/* regular game */
+ char *q;
TCadd = 0;
TCmoves = (short)strtol(p, &q, 10);
TCminutes = (short)strtol(q, &q, 10);
}
-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 = ");
}
-void
+static void
Raw_SetContempt(void)
{
printf("contempt = ");
}
-void
+static void
Raw_ChangeXwindow(void)
{
printf("xwndw = ");
* 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)
{
}
-void
+static void
Raw_DoDebug(void)
{
short c, p, sq, tp, tc, tsq, score, j, k;
}
-void
+static void
Raw_DoTable(short table[NO_SQUARES])
{
short sq, j, k;
}
-void
+static void
Raw_ShowPostnValues(void)
{
short sq, score, j, k;
}
-void
+static void
Raw_PollForInput(void)
{
#ifdef WIN32
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 */
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,
+};
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];
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 == '?')
return 1;
}
-
+#endif
/*
* The field of a hashtable is computed as follows:
{
HashCol++;
- if (!barebones)
+ if (!XSHOGI)
{
ShowMessage("ttable collision detected");
ShowBD(ptbl->bd);
short score,
short depth,
short ply,
- short alpha,
short beta,
unsigned short mv)
{