From 59b1cc298aea6705d93b73fe3e227199c5f73af3 Mon Sep 17 00:00:00 2001 From: jlam Date: Sun, 15 Oct 2000 08:38:22 +0000 Subject: KnightCap: chess engine with 3D OpenGL-rendered chessboard --- games/knightcap/Makefile | 33 ++++++++++++ games/knightcap/files/md5 | 3 ++ games/knightcap/files/patch-sum | 9 ++++ games/knightcap/patches/patch-aa | 62 ++++++++++++++++++++++ games/knightcap/patches/patch-ab | 13 +++++ games/knightcap/patches/patch-ac | 111 +++++++++++++++++++++++++++++++++++++++ games/knightcap/patches/patch-ad | 58 ++++++++++++++++++++ games/knightcap/patches/patch-ae | 54 +++++++++++++++++++ games/knightcap/patches/patch-af | 55 +++++++++++++++++++ games/knightcap/patches/patch-ag | 22 ++++++++ games/knightcap/pkg/COMMENT | 1 + games/knightcap/pkg/DESCR | 29 ++++++++++ games/knightcap/pkg/PLIST | 4 ++ 13 files changed, 454 insertions(+) create mode 100644 games/knightcap/Makefile create mode 100644 games/knightcap/files/md5 create mode 100644 games/knightcap/files/patch-sum create mode 100644 games/knightcap/patches/patch-aa create mode 100644 games/knightcap/patches/patch-ab create mode 100644 games/knightcap/patches/patch-ac create mode 100644 games/knightcap/patches/patch-ad create mode 100644 games/knightcap/patches/patch-ae create mode 100644 games/knightcap/patches/patch-af create mode 100644 games/knightcap/patches/patch-ag create mode 100644 games/knightcap/pkg/COMMENT create mode 100644 games/knightcap/pkg/DESCR create mode 100644 games/knightcap/pkg/PLIST (limited to 'games/knightcap') diff --git a/games/knightcap/Makefile b/games/knightcap/Makefile new file mode 100644 index 00000000000..58f6dbaf752 --- /dev/null +++ b/games/knightcap/Makefile @@ -0,0 +1,33 @@ +# $NetBSD: Makefile,v 1.1.1.1 2000/10/15 08:38:22 jlam Exp $ + +DISTNAME= KnightCap-3.6 +PKGNAME= knightcap-3.6nb1 +CATEGORIES= games +MASTER_SITES= ftp://samba.anu.edu.au/pub/KnightCap/ + +MAINTAINER= jlam@netbsd.org +HOMEPAGE= http://anu.samba.org/KnightCap/ + +DEPENDS+= Mesa-*:../../graphics/Mesa + +USE_X11= # defined +NO_CONFIGURE= # defined + +WRKSRC= ${WRKDIR}/Export +ALL_TARGET= KnightCap + +EVAL_PREFIX+= MESADIR=Mesa +MAKE_ENV+= MESA=${MESADIR} +MAKE_ENV+= DEFINES="${DEFINES}" + +DEFINES= -DTB_DIR=\\\"${TBDIR}\\\" + +TBDIR= ${PREFIX}/share/egtb +DOCDIR= ${PREFIX}/share/doc/knightcap + +do-install: + ${INSTALL_PROGRAM} ${WRKSRC}/KnightCap ${PREFIX}/bin + ${INSTALL_DATA_DIR} ${DOCDIR} + ${INSTALL_DATA} ${WRKSRC}/README ${DOCDIR} + +.include "../../mk/bsd.pkg.mk" diff --git a/games/knightcap/files/md5 b/games/knightcap/files/md5 new file mode 100644 index 00000000000..56c056d1abe --- /dev/null +++ b/games/knightcap/files/md5 @@ -0,0 +1,3 @@ +$NetBSD: md5,v 1.1.1.1 2000/10/15 08:38:22 jlam Exp $ + +MD5 (KnightCap-3.6.tar.gz) = b3e912cc6d4ef68f8063c45620526d1a diff --git a/games/knightcap/files/patch-sum b/games/knightcap/files/patch-sum new file mode 100644 index 00000000000..cda55417b16 --- /dev/null +++ b/games/knightcap/files/patch-sum @@ -0,0 +1,9 @@ +$NetBSD: patch-sum,v 1.1.1.1 2000/10/15 08:38:22 jlam Exp $ + +MD5 (patch-aa) = d347485e2db74ccd9cb539cdddfa3a9b +MD5 (patch-ab) = 02e2f9d74428a7122647f0154f65f12c +MD5 (patch-ac) = d8f56572558b40a5ac0db85d10fe46f9 +MD5 (patch-ad) = ca3efe3638de753bc37566df8f6c9c65 +MD5 (patch-ae) = 10d8e3b3e2e1439a6e44b24922db49cd +MD5 (patch-af) = 71fdc331e2b280699c6374b2fbd0b4a8 +MD5 (patch-ag) = 101285e87b7585f9cf26b61cf3d0db20 diff --git a/games/knightcap/patches/patch-aa b/games/knightcap/patches/patch-aa new file mode 100644 index 00000000000..a00ec0e593b --- /dev/null +++ b/games/knightcap/patches/patch-aa @@ -0,0 +1,62 @@ +$NetBSD: patch-aa,v 1.1.1.1 2000/10/15 08:38:22 jlam Exp $ + +--- Makefile.orig Sun May 17 19:09:21 1998 ++++ Makefile +@@ -5,8 +5,8 @@ + CC = gcc + + # What compiler switches do you want? These ones work well with gcc +-#OPT = -O2 -fshort-enums -Wall +-OPT = -g -fshort-enums -Wall ++OPT = -O2 -fshort-enums -Wall ++#OPT = -g -fshort-enums -Wall + + # If you don't have gcc then perhaps try this instead. You only need + # the null definition for inline if your C compiler doesn't know about +@@ -21,31 +21,36 @@ + # display (or you don't have OpenGL and Glut libraries) + # If you do have these libs then make sure the first three + # lines point at the right places +-MESA = /usr/local/Mesa-2.1 +-GLUT = /usr/local/Mesa-2.1/glut-3.2 +-X11 = /usr/X11R6 +-GLUT_LIBS = -L$(GLUT)/lib/glut -lglut +-MESA_LIBS = -L$(MESA)/lib -lMesaGLU -lMesaGL -lm +-XLIBS = -L$(X11)/lib -lXmu -lXt -lXext -lX11 -lXi +-DISPLAYFLAGS = -I$(MESA)/include -I$(GLUT) -DRENDERED_DISPLAY=1 ++MESA ?= ${X11BASE} ++GLUT = $(MESA) ++X11 = ${X11BASE} ++GLUT_LIBS = -L$(GLUT)/lib -Wl,-R$(GLUT)/lib -lglut ++MESA_LIBS = -L$(MESA)/lib -Wl,-R$(MESA)/lib -lGLU -lGL -lm ++XLIBS = -L$(X11)/lib -lXmu -lXt -lXext -lX11 -lXi -lICE -lSM ++DISPLAYFLAGS = -I$(MESA)/include -I$(GLUT)/include -DRENDERED_DISPLAY=1 + + # comment out the following line if you don't want KnightCap's + # evaluation function learning turned on. +-LEARNFLAGS = -DLEARN_EVAL=1 ++# ++# On NetBSD, this causes mysterious segfaults that GDB can't track down, ++# so disable the evaluation function learning. ++# ++# LEARNFLAGS = -DLEARN_EVAL=1 + + # you shouldn't need to edit anything below this line. Unless + # something goes wrong. + + INCLUDE = $(DISPLAYFLAGS) +-CFLAGS = $(OPT) $(INCLUDE) $(LEARNFLAGS) ++CFLAGS += $(OPT) $(DEFINES) $(INCLUDE) $(LEARNFLAGS) + +-LIBS = $(GLUT_LIBS) $(MESA_LIBS) $(XLIBS) ++LIBS = $(LDFLAGS) $(GLUT_LIBS) $(MESA_LIBS) $(XLIBS) + + TARGET = KnightCap + + OBJS = knightcap.o trackball.o move.o util.o generate.o eval.o movement.o \ + ordering.o hash.o board.o log.o prog.o timer.o ics.o display.o \ + testsuite.o brain.o td.o tactics.o ++OBJS+= epd.o epdglue.o + + $(TARGET): $(OBJS) + -mv $@ $@.old diff --git a/games/knightcap/patches/patch-ab b/games/knightcap/patches/patch-ab new file mode 100644 index 00000000000..142b2fcd42e --- /dev/null +++ b/games/knightcap/patches/patch-ab @@ -0,0 +1,13 @@ +$NetBSD: patch-ab,v 1.1.1.1 2000/10/15 08:38:22 jlam Exp $ + +--- display.c.orig Sun May 17 19:09:21 1998 ++++ display.c +@@ -12,8 +12,6 @@ + #include + #include "trackball.h" + +-static int window_size = 500; +- + #define SLEEP_TIME 100000 /* microseconds */ + + diff --git a/games/knightcap/patches/patch-ac b/games/knightcap/patches/patch-ac new file mode 100644 index 00000000000..52e55d513b0 --- /dev/null +++ b/games/knightcap/patches/patch-ac @@ -0,0 +1,111 @@ +$NetBSD: patch-ac,v 1.1.1.1 2000/10/15 08:38:22 jlam Exp $ + +--- knightcap.c.orig Sun May 17 19:09:21 1998 ++++ knightcap.c +@@ -6,7 +6,7 @@ + #include "trackball.h" + #include "knightcap.h" + +-static int window_size = 500; ++int window_size = 500; + + #define SLEEP_TIME 100000 /* microseconds */ + #define REFRESH_TIME 20 /* in seconds */ +@@ -21,6 +21,7 @@ + int seek_answering=0; + int demo_mode = 0; + ++static int starts = 0; /* default to no computer play */ + static int opponent; + static int always_think; + static int no_display; +@@ -56,7 +57,7 @@ + char *ics_master = NULL; + char *coeffs_file = NULL; + char *bad_eval_file = "bad_eval.dat"; +-char *tb_path = "../EGTB"; ++char *tb_path = TB_DIR; + + char play_target[100]; + +@@ -82,7 +83,7 @@ + void reset_board(void) + { + setup_board(&state->position); +- state->computer = 0; ++ state->computer = starts; + state->moved = 0; + state->always_think = always_think; + state->use_mulling = use_mulling; +@@ -945,7 +946,7 @@ + reset_board(); + init_movements(); + +- signal(SIGCLD, SIG_IGN); ++ signal(SIGCHLD, SIG_IGN); + + pid1 = getpid(); + +@@ -1000,6 +1001,11 @@ + "-T target ICS opponent\n" \ + "-G endgame tablebsae directory\n" \ + "-y don't mull\n" \ ++"-1 Computer plays white\n" \ ++"-2 Computer plays black\n" \ ++"-0 Computer plays neither white nor black\n" \ ++"\n" \ ++"call xboard with: xboard -fcp 'KnightCap -n -X -A -2'\n" \ + "\n"); + } + +@@ -1010,7 +1016,11 @@ + #ifdef SUNOS4 + extern char *optarg; + #endif +- char *opt = "c:s:w:nI:t:hXAD:l:aH:M:ezdm:f:g:ByEpT:"; ++ /* ++ * Add support for specifying what colour the computer plays ++ * at start. ++ */ ++ char *opt = "012c:s:w:nI:t:hXAD:l:aH:M:ezdm:f:g:ByEpT:"; + int c; + int seed = getpid(); + +@@ -1030,6 +1040,7 @@ + if (getcid()) break; + #endif + window_size = atoi(optarg); ++ lprintf(0, "Window size: %d\n", window_size); + break; + + case 'c': +@@ -1151,6 +1162,15 @@ + case 'g': + tb_path = optarg; + break; ++ case '0': ++ starts = 0; ++ break; ++ case '1': ++ starts = 1; ++ break; ++ case '2': ++ starts = -1; ++ break; + } + } + +@@ -1178,6 +1198,13 @@ + parse_options(argc, argv); + + create_threads(); ++ ++ /* ++ * Initialize colour the computer plays to what's specified, ++ * or default to playing neither side. ++ */ ++ state->computer = starts; ++ state->colour = starts; + + state->ics_robot = ics_mode; + state->autoplay = ics_mode; diff --git a/games/knightcap/patches/patch-ad b/games/knightcap/patches/patch-ad new file mode 100644 index 00000000000..309aa2d0d52 --- /dev/null +++ b/games/knightcap/patches/patch-ad @@ -0,0 +1,58 @@ +$NetBSD: patch-ad,v 1.1.1.1 2000/10/15 08:38:23 jlam Exp $ + +--- knightcap.h.orig Sun May 17 19:09:21 1998 ++++ knightcap.h +@@ -92,7 +92,22 @@ + #define USE_PBRAIN 1 + #endif + +-#define BRAIN_FILE "brain.dat" ++/* ++ * Support finding brain.dat in another directory (BRAIN_DIR) determined ++ * at compile-time. ++ */ ++#ifndef BRAIN_DIR ++#define BRAIN_DIR "./" ++#endif ++#define BRAIN_FILE BRAIN_DIR "brain.dat" ++ ++/* ++ * Support finding endgame tables in another direcotry (TB_DIR) determined ++ * at compile-time. ++ */ ++#ifndef TB_DIR ++#define TB_DIR "../EGTB" ++#endif + + #ifndef RESIGN_VALUE + #define RESIGN_VALUE (ROOK_VALUE) +@@ -296,10 +311,19 @@ + + #define INITIAL_MATERIAL (KING_VALUE + QUEEN_VALUE + 2*ROOK_VALUE + 2*BISHOP_VALUE + 2*KNIGHT_VALUE + 8*PAWN_VALUE) + ++#if defined(__NetBSD__) ++#include ++ ++typedef int16_t int16; ++typedef u_int16_t uint16; ++typedef u_int32_t uint32; ++typedef u_int64_t uint64; ++#else + typedef short int16; + typedef unsigned short uint16; + typedef unsigned uint32; + typedef unsigned long long uint64; ++#endif + + typedef enum {B_KING = -6,B_QUEEN = -5,B_ROOK = -4,B_BISHOP = -3, + B_KNIGHT = -2,B_PAWN = -1, +@@ -884,4 +908,8 @@ + return pop_count16((x) & 0xFFFF) + pop_count16((x) >> 16); + } + +- ++/* ++ * Make window_size global so that the GL board can be displayed at ++ * correct initial size. window_size is defined in knightcap.c. ++ */ ++extern int window_size; diff --git a/games/knightcap/patches/patch-ae b/games/knightcap/patches/patch-ae new file mode 100644 index 00000000000..6b9e7fa3102 --- /dev/null +++ b/games/knightcap/patches/patch-ae @@ -0,0 +1,54 @@ +$NetBSD: patch-ae,v 1.1.1.1 2000/10/15 08:38:23 jlam Exp $ + +--- log.c.orig Sun May 17 19:09:21 1998 ++++ log.c +@@ -6,6 +6,9 @@ + static FILE *cfile; + static FILE *dfile; + ++/* Make this buffer big enough to print the help file. */ ++#define FMT_SIZE (4096) ++ + void log_close(void) + { + fclose(logfile); +@@ -15,7 +18,7 @@ + int lprintf(int level, char *format_str, ...) + { + va_list ap; +- char fmt[1024]; ++ char fmt[FMT_SIZE]; + char *p; + + if (!logfile) { +@@ -29,7 +32,9 @@ + va_start(ap, format_str); + + +- strcpy(fmt, format_str); ++ /* Make this safer by using strncpy() instead of strcpy(). */ ++ strncpy(fmt, format_str, FMT_SIZE - 1); ++ fmt[FMT_SIZE - 1] = '\0'; + if (sizeof(short) == sizeof(etype)) { + while ((p = strstr(fmt, "%e"))) { + p[1] = 'd'; +@@ -63,7 +68,7 @@ + int status_printf(int rew, char *format_str, ...) + { + va_list ap; +- char fmt[1024]; ++ char fmt[FMT_SIZE]; + char *p; + + if (!sfile) { +@@ -80,7 +85,9 @@ + va_start(ap, format_str); + + +- strcpy(fmt, format_str); ++ /* Make this safer by using strncpy() instead of strcpy(). */ ++ strncpy(fmt, format_str, FMT_SIZE - 1); ++ fmt[FMT_SIZE - 1] = '\0'; + if (sizeof(short) == sizeof(etype)) { + while ((p = strstr(fmt, "%e"))) { + p[1] = 'd'; diff --git a/games/knightcap/patches/patch-af b/games/knightcap/patches/patch-af new file mode 100644 index 00000000000..4894c4e7002 --- /dev/null +++ b/games/knightcap/patches/patch-af @@ -0,0 +1,55 @@ +$NetBSD: patch-af,v 1.1.1.1 2000/10/15 08:38:23 jlam Exp $ + +--- movement.c.orig Sun May 17 19:09:21 1998 ++++ movement.c +@@ -258,33 +258,38 @@ + } + + ++ /* ++ * There's some weird gcc codegen bug here when going NORTH_WEST, ++ * even with no optimization, but when it's re-written to go ++ * SOUTH_EAST, everything's fine. Ugh! ++ */ + for (i=0;i<8;i++) { +- dir = NORTH_WEST; +- p1 = A1 + i*EAST; +- p2 = A1 + i*NORTH; ++ dir = SOUTH_EAST; ++ p1 = A1 + i*NORTH; ++ p2 = A1 + i*EAST; + + mask = 0; +- for (s1=p1; s1>=p2; s1+=dir) ++ for (s1=p1; s1=p2;s1+=dir) +- for (s2=p1;s2>=p2;s2+=dir) ++ for (s1=p1;s1=p2; s1+=dir) ++ for (s1=p1; s1=p2;s1+=dir) +- for (s2=p1;s2>=p2;s2+=dir) ++ for (s1=p1;s1= 0) +- sprintf(fn, "/usr/local/chess/large_coeffs%d.h", round); ++ sprintf(fn, "large_coeffs%d.h", round); + else + sprintf(fn,"large_coeffs.h"); + large = (FILE *)fopen(fn, "w"); +@@ -123,7 +123,7 @@ + small = (FILE *)fopen(fn, "w"); + #else + if (round >= 0) +- sprintf(fn, "/usr/local/chess/small_coeffs%d.h", round); ++ sprintf(fn, "small_coeffs%d.h", round); + else + sprintf(fn, "small_coeffs.h"); + large = (FILE *)fopen(fn, "w"); diff --git a/games/knightcap/pkg/COMMENT b/games/knightcap/pkg/COMMENT new file mode 100644 index 00000000000..3dd374dfbff --- /dev/null +++ b/games/knightcap/pkg/COMMENT @@ -0,0 +1 @@ +chess engine with 3D OpenGL-rendered chessboard diff --git a/games/knightcap/pkg/DESCR b/games/knightcap/pkg/DESCR new file mode 100644 index 00000000000..be662c43e3a --- /dev/null +++ b/games/knightcap/pkg/DESCR @@ -0,0 +1,29 @@ +KnightCap is a chess program written for the Fujitsu AP1000+ parallel +computer (running AP/Linux). It will also run on most unixes, although +you may need to tweak the includes.h file and Makefile. + +The principal differences between KnightCap and other chess programs +are: + + - KnightCap has an optional fully rendered 3D interface, giving a feel much + more like an "over the board" game. + + - KnightCap was developed to run on a parallel distributed memory + machine, although it also runs on normal unix boxes. + + - KnightCap does not have an opening book---instead it keeps a file + (brain.dat) of losing moves and inserts them in the hash table at the + start of each search. At present it has about 1500 entries, and + this makes it a pretty competitive opening player. + + - KnightCap learns the parameters of its evaluation function as it + plays. The most dramatic example of how this helps is an experiment + we conducted on FICS in which KnightCap learnt from a 1650 player + to a 2100 player in just 300 games. See + http://keating.anu.edu.au/~jon/papers/knigtcap.ps.gz for more info on + its learning algorithm. + +KnightCap now beats gnuchess consistently and is within "coo-ee" of +crafty, although I think it needs deeper search or some more dramatic +selective search to be truly competitive with the best micro +programs. diff --git a/games/knightcap/pkg/PLIST b/games/knightcap/pkg/PLIST new file mode 100644 index 00000000000..a742bfa773d --- /dev/null +++ b/games/knightcap/pkg/PLIST @@ -0,0 +1,4 @@ +@comment $NetBSD: PLIST,v 1.1.1.1 2000/10/15 08:38:22 jlam Exp $ +bin/KnightCap +share/doc/knightcap/README +@dirrm share/doc/knightcap -- cgit v1.2.3