# HG changeset patch # User nobody_special # Date 1618277047 14400 # Node ID eab69ba077aa5c1bddb63f4b4069c5145f1ac30b # Parent b1478befa1842d409bea10bacec44905a0a60fdc import chdb(7) from 2e diff -r b1478befa184 -r eab69ba077aa lib/chess/hist.m.out Binary file lib/chess/hist.m.out has changed diff -r b1478befa184 -r eab69ba077aa sys/man/7/chdb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/man/7/chdb Mon Apr 12 21:24:07 2021 -0400 @@ -0,0 +1,243 @@ +.TH CHDB 7 +.SH NAME +chdb \- chess database browser +.SH SYNOPSIS +.B chdb +[ +.I file ... +] +.SH DESCRIPTION +.I Chdb +reads the given +.I files +of chess games +.RB ( hist +by default) +and accepts commands to search, +play through, and display the games in these files. +If +.I x +is the name of the file, it is looked for under the names +.IR x , +.IB x .m.out\f1, +and +.BI /lib/chess/ x .m.out\f1. +.PP +After reading the files, +.I chdb +displays a chess board, +a text window with +a command line, and +vertical and +horizontal scroll bars +along the edges of the board. +The text window holds 6 lines of information about the game and position +and, at the bottom, a command line in which to type. +The displayed text contains chess symbols\(emuse a suitable font. +.PP +The vertical scroll bar scans through the games to select a game; +the horizontal bar then scans through the moves of the selected game. +Both scroll bars use button 1 to +scan backwards, +button 3 to scan forwards, and +button 2 to jump to an absolute position. +With buttons 1 and 3, the scroll bars are calibrated in units +of 1 through 8 corresponding to the ranks and +files of the board. The units measure games on the vertical +scroll bar, ply (half-moves) on the horizontal scroll bar. +For example, clicking button 3 on the horizontal scroll bar +under the +.B d +file steps through the game two full moves. +.PP +Moves may be made on the chess board by +pointing with button 1. +There are two methods to point at moves. +For the first method, +point at the piece to be moved, +press button 1, +point to the place to move that piece, +and release button 1. +In the second method, +point at the place where a piece is to +move and press button 1. +The smallest/least-central piece that can move there +is highlighted. +Releasing button 1 without moving the +mouse will make the highlighted move. +Moving the mouse to the desired piece +and releasing the button will move the +selected piece. +.PP +Typed lines of text are +echoed in the command line and executed. +The available commands are: +.TP +.BI f " n n +Set the format for display of moves in the text window. The first number +is the verbosity, with 0 minimal. The second number is 0 for algebraic, +1 for English, and 2 for figurine (default). +.TP +.BI g " n +Go to the game with ordinal number +.I n +in the input files. +If +.I n +is prefixed with a +.B + +or +.BR - , +it is interpreted as a relative position in the current set of games (see below). +.I N +defaults to +.BR +1 . +.TP +.BI p " n +Go to whole move +.I n +in the current game. +If +.I n +is prefixed with a +.B + +or +.BR - , +it is interpreted as an offset in +.I ply +from the current position. +.I N +defaults to +.BR +1 . +.TP +.BI k " n +Mark the current set of games with tag +.I n +(see patterns, below). +.TP +.BI w " type file +Write the current set of games to +.IR file . +.I Type +is either +.B a +(write the games as text) or +.B m +(write the games in binary format suitable for +.IR chdb ). +.PP +Patterns select subsets of the games. +A pattern is one of the following, in decreasing precedence order. +Parentheses can be used for grouping. +.TP +.BR . +The current game. +.TP +.B * +All games originally read. +.TP +.BI ' n +The games previously +marked with a +.B k +command with the same +.IR n . +.TP +.B [] +.TP +.BI [ number ] +All games in +.B * +that contain the positions that can +be reached in +the specified number of +plies from the current position. +A missing number is the same as zero, +meaning just the current position. +Positions are matched with black/white +transpositions. +.TP +.BI / regular\ expression / fields +This pattern matches the regular expression +against the various text windows. +.I Fields +is a list of characters from +the set +.BR abdefoprw . +.B A +is for all, +.B b +for black, +.B d +for date, +.B e +for event, +.B f +for file, +.B o +for opening, +.B p +for person (white and black), +.B r +for result, +and +.B w +for white. +If multiple fields are given, +the expression is matched on the +union of the specified fields. +If no field is given, +.B p +is assumed. +.TP +.BI ! pattern +The set subtraction of +.B * +and the given pattern. +.TP +.IB pattern - pattern +The set subtraction of +the given patterns. +.TP +.IB pattern + pattern +.TP +.IB pattern | pattern +The set union of +the given patterns. +.TP +.I pattern pattern +.TP +.IB pattern & pattern +The set intersection of +the given patterns. +.TP +.BI + pattern +.TP +.BI - pattern +.TP +.BI & pattern +.TP +.BI | pattern +These patterns have +the current set of games +as an implied first operand. +.SH EXAMPLE +Select games that Botvinnik lost: +.IP +.EX +(/Botv/w/0-1/r)|(/Botv/b/1-0/r) +.EE +.SH FILES +.TF /lib/chess +.TP +.B /lib/chess +directory of databases. +.SH SOURCE +.B /sys/src/cmd/chdb +.SH SEE ALSO +.IR regexp (6). +.SH BUGS +The browser is only a prototype. +.PP +Most of the databases are protected +by copyright and not distributed. diff -r b1478befa184 -r eab69ba077aa sys/src/cmd/chdb/cd.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/cmd/chdb/cd.c Mon Apr 12 21:24:07 2021 -0400 @@ -0,0 +1,90 @@ +#include +#include +#include "gen.h" + +schar dir[] = +{ + U1|L1, U1|L2, U1 , U1 , U1 , U1 , U1|R2, U1|R1, + U2|L1, U2|L2, U2 , U2 , U2 , U2 , U2|R2, U2|R1, + L1, L2, 0, 0, 0, 0, R2, R1, + L1, L2, 0, 0, 0, 0, R2, R1, + L1, L2, 0, 0, 0, 0, R2, R1, + L1, L2, 0, 0, 0, 0, R2, R1, + D2|L1, D2|L2, D2 , D2 , D2 , D2 , D2|R2, D2|R1, + D1|L1, D1|L2, D1 , D1 , D1 , D1 , D1|R2, D1|R1, +}; +schar attab[] = +{ + U2R1, -15, + U1R2, -6, + D1R2, 10, + D2R1, 17, + D2L1, 15, + D1L2, 6, + U1L2, -10, + U2L1, -17, + + ULEFT, -9, + URIGHT, -7, + DLEFT, 7, + DRIGHT, 9, + + UP, -8, + LEFT, -1, + RIGHT, 1, + DOWN, 8, +}; +Posn initp = +{ + INIT+BROOK, + INIT+BKNIGHT, + INIT+BBISHOP, + INIT+BQUEEN, + INIT+BKING, + INIT+BBISHOP, + INIT+BKNIGHT, + INIT+BROOK, + INIT+BPAWN, + INIT+BPAWN, + INIT+BPAWN, + INIT+BPAWN, + INIT+BPAWN, + INIT+BPAWN, + INIT+BPAWN, + INIT+BPAWN, + 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + INIT+WPAWN, + INIT+WPAWN, + INIT+WPAWN, + INIT+WPAWN, + INIT+WPAWN, + INIT+WPAWN, + INIT+WPAWN, + INIT+WPAWN, + INIT+WROOK, + INIT+WKNIGHT, + INIT+WBISHOP, + INIT+WQUEEN, + INIT+WKING, + INIT+WBISHOP, + INIT+WKNIGHT, + INIT+WROOK, + 0, /* eppos */ + 0, /* moveno */ + 0, /* moves */ +}; + +schar color[] = +{ + 0, + 1, 1, 1, 1, 1, 1, 1, + 0, + -1, -1, -1, -1, -1, -1, -1, + 0, + 1, 1, 1, 1, 1, 1, 1, + 0, + -1, -1, -1, -1, -1, -1, -1, +}; diff -r b1478befa184 -r eab69ba077aa sys/src/cmd/chdb/cdb/cdb.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/cmd/chdb/cdb/cdb.c Mon Apr 12 21:24:07 2021 -0400 @@ -0,0 +1,734 @@ +/* + * cdb -- + * read ascii chess games in either + * individual or archive formats and + * write 16-bit move binary format + * m.out. + * -o option will add opening + * -f option will use this filename for 'file:' line + */ + +#include +#include +#include +#include +#include +#include "../gen.h" + +#define STRSIZE 200 +#define coffsetof(t,x) ((ulong)&((t*)0)->x) + +char openfile[] = "/lib/chess/opening.m.out"; + +typedef struct String String; +typedef struct Open Open; +typedef struct ar_hdr Ahdr; + +struct String +{ + char file[STRSIZE]; + char white[STRSIZE]; + char black[STRSIZE]; + char event[STRSIZE]; + char result[STRSIZE]; + char opening[STRSIZE]; + char date[STRSIZE]; +}; +struct Open +{ + ulong xa; + ulong xb; + char* book; +}; + +Ahdr arhdr; +ulong blposxa; +ulong blposxb; +ulong btmxora; +ulong btmxorb; +Biobuf bufi; +Biobuf bufo; +long fisize; +ulong initpxora; +ulong initpxorb; +char* lastbook; +int lastposn; +char line[STRSIZE]; +char* lp; +long lineno; +int mverror; +int nfiles; +int ngames; +int oflag; +int fflag; +long opencur; +Open* opening; +long openmax; +String strings; +int subfile; +ulong whposxa; +ulong whposxb; +char word[STRSIZE]; +char* wp; +char xbd[64]; +ulong xora[16*64]; +ulong xorb[16*64]; +char xpc[32]; + +void doxor(int, int); +void flushgame(char*); +int getshort(void); +int getstr(char*); +void initopen(void); +void install(char*); +int istr(char*); +int ocmp(Open*, Open*); +void putshort(int); +void putstr(char*); +int rline(void); +int rword(void); +ulong urand(void); +void xorinit(void); +void xormove(int); + +void +main(int argc, char* argv[]) +{ + int i, fi, fo; + char fname[200]; + + chessinit('G', 0, 2); + fo = create("m.out", OWRITE, 0666); + Binit(&bufo, fo, OWRITE); + + ARGBEGIN { + case 'o': + oflag++; + initopen(); + break; + case 'f': + fflag++; + break; + default: + fprint(2, "usage: cdb [-o] files\n"); + exits("flag"); + } ARGEND + + for(i=0; i='0' && c<='9') || c == '.') { + wp++; + c = *wp; + } + if(c == 0) + continue; + m = chessin(wp); + if(m == 0) { + if(!mverror) { + print("%s %ld: illegal move %s\n", fname, lineno, word); + mverror = 1; + } + continue; + } + if(oflag) { + xormove(m); + cmove(m); + k1 = 0; + k2 = opencur; + for(;;) { + k = (k1+k2) / 2; + o = &opening[k]; + if(k <= k1) + break; + if(whposxa > o->xa) { + k1 = k; + continue; + } + if(whposxa < o->xa) { + k2 = k; + continue; + } + if(whposxb >= o->xb) { + k1 = k; + continue; + } + k2 = k; + } + if(whposxa == o->xa) + if(whposxb == o->xb) { + lastbook = o->book; + lastposn = mvno; + } + } else + cmove(m); + } +} + +void +flushgame(char *fname) +{ + int i, m, c, pos; + char *book; + + if(!mverror && moveno == 0) + return; + if(!strings.file[0] || fflag) + if(subfile >= 0) + sprint(strings.file, "%s:%d", fname, subfile); + else + sprint(strings.file, "%s", fname); + if(!strings.white[0]) { + print("%s %ld: white missing\n", fname, lineno); + sprint(strings.white, "none"); + } + if(!strings.black[0]) { + print("%s %ld: black missing\n", fname, lineno); + sprint(strings.black, "none"); + } + if(!strings.event[0]) { + print("%s %ld: event missing\n", fname, lineno); + sprint(strings.event, "none"); + } + if(!strings.result[0]) { + print("%s %ld: result missing\n", fname, lineno); + sprint(strings.result, "none"); + } + if(mverror) + strcat(strings.result, " error"); + if(oflag) { + book = "A00/00"; + pos = 0; + if(lastbook) { + book = lastbook; + pos = lastposn; + } + sprint(strings.opening, "%s %d", book, (pos+2)/2); + book = strchr(strings.opening, 0); + if(pos & 1) + *book++ = '.'; + m = mvno; + while(mvno > pos) + rmove(); + if(mvno < m) + sprint(book, " %G", mvlist[mvno]); + else + sprint(book, " *"); + while(mvno < m) + cmove(mvlist[mvno]); + } + if(!strings.opening[0]) { + print("%s %ld: opening missing\n", fname, lineno); + sprint(strings.opening, "none"); + } + m = strlen(strings.event); + if(m <= 4) + goto nodate; + for(i=1; i<=4; i++) { + c = strings.event[m-i]; + if(c < '0' || c > '9') + goto nodate; + } + if(strings.event[m-5] != ' ') + goto nodate; + strcpy(strings.date, strings.event+m-4); + for(i=1; i<=5; i++) + strings.event[m-i] = 0; + +nodate: + m = 7; + m += strlen(strings.file); + m += strlen(strings.white); + m += strlen(strings.black); + m += strlen(strings.event); + m += strlen(strings.result); + m += strlen(strings.opening); + m += strlen(strings.date); + i = m; + if(i & 1) + i++; + putshort(i/sizeof(short)); /* shorts worth of strings */ + + putstr(strings.file); + putstr(strings.white); + putstr(strings.black); + putstr(strings.event); + putstr(strings.result); + putstr(strings.opening); + putstr(strings.date); + if(m & 1) + putstr(""); + putshort(mvno); /* shorts worth of moves */ + for(i=0; i= 0) + subfile++; +} + +int +rline(void) +{ + int c; + + lp = line; + for(;;) { + if(fisize == 0) + return 1; + fisize--; + c = Bgetc(&bufi); + if(c == '\n' || c == '\t') { + *lp = 0; + lp = line; + return 0; + } + if(c <= 0) { + fisize = 0; + return 1; + } + *lp++ = c; + } + return 0; +} + +int +rword(void) +{ + int c; + + wp = word; + for(;;) { + c = *lp; + if(c == 0) + return 1; + if(c != ' ' && c != '\t') + break; + lp++; + } + for(;;) { + c = *lp; + if(c == 0) + break; + if(c == ' ' || c == '\t') + break; + *wp++ = c; + lp++; + } + *wp = 0; + wp = word; + return 0; +} + +int +istr(char *s) +{ + char *c; + + for(c = lp; *s;) + if(*s++ != *c++) + return 0; + lp = c; + return 1; +} + +void +putstr(char *s) +{ + int c; + + do { + c = *s++; + Bputc(&bufo, c); + } while(c); +} + +void +putshort(int h) +{ + + Bputc(&bufo, h>>8); + Bputc(&bufo, h); +} + +ulong +urand(void) +{ + ulong x; + + x = lrand() >> 8; + x ^= lrand() << 8; + return x; +} + +void +xorinit(void) +{ + int i, j; + + for(i=0; i>6) & 077; + to = (mov>>0) & 077; + + p = board[from] & 017; + doxor(board[to], to); + doxor(p, from); + doxor(p, to); + doxor(0, from); + + typ = (mov>>12) & 017; + switch(typ) { + case TNPRO: + doxor(p, to); + doxor(WKNIGHT | (p&BLACK), to); + break; + case TBPRO: + doxor(p, to); + doxor(WBISHOP | (p&BLACK), to); + break; + case TRPRO: + doxor(p, to); + doxor(WROOK | (p&BLACK), to); + break; + case TQPRO: + doxor(p, to); + doxor(WQUEEN | (p&BLACK), to); + break; + case TOO: + from = to+1; + to--; + goto mv; + case TOOO: + from = to-2; + to++; + mv: + p = board[from] & 017; + doxor(board[to], to); + doxor(p, from); + doxor(p, to); + doxor(0, from); + break; + case TENPAS: + if(moveno & 1) + to -= 8; + else + to += 8; + doxor(board[to], to); + doxor(0, to); + } +} + +int +ocmp(Open *a, Open *b) +{ + if(a->xa > b->xa) + return 1; + if(a->xa < b->xa) + return -1; + if(a->xb > b->xb) + return 1; + if(a->xb < b->xb) + return -1; + return strcmp(a->book, b->book); +} + +void +initopen(void) +{ + int f, n, m, i; + char *book, *bookr; + Open *o, *oa, *oe; + + print("start oinit ..."); + xorinit(); + f = open(openfile, OREAD); + if(f < 0) { + fprint(2, "cannot open %s\n", openfile); + exits("open"); + } + Binit(&bufi, f, OREAD); + + openmax = 416100; + opencur = 0; + opening = malloc(openmax*sizeof(Open)); + o = &opening[opencur]; + for(;;) { + n = getshort(); + if(n < 0) + break; + m = getstr(strings.file); + m += getstr(strings.white); + m += getstr(strings.black); + m += getstr(strings.event); + m += getstr(strings.result); + m += getstr(strings.opening); + m += getstr(strings.date); + if(m & 1) { + Bgetc(&bufi); + m++; + } + if(n != m/sizeof(short)) { + fprint(2, "sanity check\n"); + exits("sanity"); + } + + book = strdup(strings.event); + strcat(strings.event, " cr"); + bookr = strdup(strings.event); + + n = getshort(); + opencur += n*2; + if(opencur >= openmax) { + fprint(2, "had to realloc\n"); + exits("realloc"); + } + ginit(&initp); + whposxa = initpxora; + whposxb = initpxorb; + blposxa = whposxa ^ btmxora; + blposxb = whposxb ^ btmxorb; + for(i=0; ixa = whposxa; + o->xb = whposxb; + o->book = book; + o++; + o->xa = blposxa; + o->xb = blposxb; + o->book = bookr; + o++; + } + } + close(f); + + qsort(opening, opencur, sizeof(Open), ocmp); + oa = opening; + oe = oa + opencur; + for(o=oa+1; oxa != oa->xa || + o->xb != oa->xb) { + oa++; + *oa = *o; + } + opencur = oa - opening; + print("\n"); +} + +int +getshort(void) +{ + int c1, c2; + + c1 = Bgetc(&bufi); + if(c1 < 0) + return c1; + c2 = Bgetc(&bufi); + if(c2 < 0) + return c2; + return (c1<<8) | c2; +} + +int +getstr(char *s) +{ + int c; + char *is; + + is = s; + for(;;) { + c = Bgetc(&bufi); + if(c < 0) { + fprint(2, "eof in string\n"); + exits("eof"); + } + *s++ = c; + if(c == 0) + return s-is; + } +} diff -r b1478befa184 -r eab69ba077aa sys/src/cmd/chdb/cdb/dat.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/cmd/chdb/cdb/dat.c Mon Apr 12 21:24:07 2021 -0400 @@ -0,0 +1,7027 @@ +#include +#include "vec.h" + +short bpawn[] = /* V002 */ +{ + 117, 36, + 118, 46, + 121, 58, + 129, 72, + 142, 86, + 156, 96, + 168, 103, + 179, 108, + 183, 110, + 190, 112, + 191, 113, + 205, 116, + 209, 119, + 201, 133, + 196, 148, + 195, 154, + 194, 169, + 194, 184, + 196, 189, + 199, 202, + 203, 217, + 208, 230, + 213, 244, + 216, 252, + 216, 267, + 215, 270, + 200, 270, + 194, 270, + 185, 270, + 170, 270, + 155, 270, + 140, 270, + 134, 271, + 132, 273, + 131, 278, + 131, 293, + 136, 307, + 144, 321, + 158, 336, + 170, 344, + 178, 349, + 186, 353, + 195, 357, + 199, 358, + 200, 359, + 207, 361, + 207, 391, + 211, 405, + 219, 420, + 231, 431, + 240, 436, + 245, 436, + 245, 438, + 260, 438, + 270, 437, + 279, 434, + 288, 427, + 298, 415, + 303, 405, + 304, 403, + 307, 389, + 307, 374, + 308, 361, + 316, 359, + 316, 358, + 327, 355, + 327, 354, + 335, 351, + 348, 344, + 362, 332, + 372, 320, + 379, 307, + 382, 298, + 383, 292, + 383, 277, + 382, 274, + 367, 274, + 352, 274, + 337, 274, + 322, 274, + 307, 273, + 305, 272, + 303, 266, + 303, 251, + 308, 237, + 314, 222, + 316, 217, + 320, 208, + 325, 197, + 328, 184, + 329, 173, + 329, 158, + 327, 146, + 322, 131, + 316, 121, + 316, 119, + 323, 117, + 327, 115, + 336, 113, + 336, 112, + 347, 109, + 349, 107, + 356, 105, + 358, 103, + 362, 102, + 377, 92, + 392, 78, + 401, 64, + 406, 51, + 407, 44, + 406, 36, + 391, 36, + 376, 36, + 361, 36, + 346, 36, + 331, 36, + 316, 36, + 315, 35, + 300, 35, + 285, 35, + 270, 35, + 255, 35, + 240, 35, + 225, 35, + 210, 35, + 195, 35, + 180, 35, + 165, 35, + 150, 35, + 149, 34, + 149, 33, + 134, 33, + 131, 33, + 119, 33, + 117, 36, + End, End +}; +short bknight[] = /* V003 */ +{ + 45, 206, + 45, 218, + 53, 233, + 66, 245, + 71, 248, + 78, 263, + 79, 265, + 85, 278, + 92, 292, + 99, 306, + 105, 319, + 112, 334, + 119, 348, + 125, 362, + 129, 369, + 132, 377, + 131, 388, + 128, 403, + 125, 417, + 122, 431, + 121, 435, + 122, 448, + 124, 450, + 136, 449, + 151, 436, + 156, 432, + 161, 432, + 165, 447, + 167, 453, + 169, 464, + 173, 470, + 185, 469, + 188, 466, + 200, 456, + 214, 442, + 220, 437, + 228, 436, + 243, 436, + 243, 435, + 253, 434, + 253, 433, + 267, 431, + 271, 430, + 271, 429, + 284, 426, + 284, 425, + 295, 422, + 297, 420, + 303, 418, + 305, 416, + 308, 415, + 313, 412, + 322, 408, + 327, 404, + 334, 400, + 349, 389, + 363, 376, + 377, 361, + 389, 347, + 399, 332, + 408, 317, + 415, 304, + 421, 291, + 427, 277, + 432, 264, + 437, 249, + 441, 236, + 445, 221, + 448, 208, + 450, 199, + 453, 184, + 455, 170, + 457, 157, + 458, 147, + 459, 138, + 460, 125, + 460, 110, + 461, 106, + 461, 46, + 460, 35, + 458, 34, + 458, 33, + 443, 33, + 428, 33, + 413, 33, + 398, 33, + 383, 33, + 368, 33, + 353, 33, + 338, 33, + 323, 33, + 308, 33, + 293, 33, + 278, 33, + 263, 33, + 248, 33, + 233, 33, + 218, 33, + 203, 33, + 188, 33, + 173, 33, + 158, 33, + 146, 34, + 145, 38, + 145, 68, + 148, 83, + 152, 97, + 158, 111, + 166, 126, + 176, 140, + 190, 155, + 205, 168, + 219, 180, + 233, 192, + 233, 193, + 218, 193, + 203, 193, + 188, 183, + 174, 173, + 159, 163, + 151, 151, + 145, 148, + 143, 147, + 137, 146, + 124, 146, + 124, 147, + 121, 147, + 111, 147, + 105, 143, + 93, 141, + 79, 141, + 79, 142, + 73, 143, + 64, 149, + 62, 154, + 58, 169, + 55, 177, + 51, 190, + 46, 204, + 45, 206, + End, + 79, 213, + 83, 218, + 92, 218, + 92, 199, + 90, 196, + 84, 196, + 80, 202, + 79, 213, + End, + 151, 278, + 151, 287, + 157, 300, + 164, 314, + 175, 315, + 190, 315, + 205, 315, + 208, 313, + 209, 304, + 205, 301, + 198, 300, + 194, 293, + 184, 286, + 178, 284, + 168, 283, + 165, 281, + 160, 275, + 155, 275, + 151, 278, + End, + 188, 408, + 194, 408, + 209, 408, + 224, 408, + 239, 408, + 239, 407, + 246, 406, + 257, 404, + 258, 403, + 271, 400, + 271, 399, + 278, 397, + 280, 395, + 285, 393, + 298, 386, + 311, 378, + 324, 368, + 339, 355, + 353, 341, + 365, 326, + 375, 311, + 383, 298, + 391, 283, + 397, 270, + 403, 255, + 408, 240, + 412, 228, + 416, 214, + 419, 202, + 422, 189, + 425, 174, + 426, 164, + 427, 156, + 428, 144, + 429, 143, + 429, 128, + 430, 116, + 431, 114, + 431, 69, + 430, 66, + 422, 66, + 407, 66, + 407, 67, + 406, 73, + 406, 88, + 405, 98, + 405, 113, + 404, 127, + 403, 137, + 402, 147, + 401, 154, + 399, 167, + 397, 178, + 395, 187, + 392, 202, + 389, 213, + 385, 228, + 380, 242, + 375, 255, + 369, 270, + 362, 284, + 354, 298, + 344, 313, + 332, 328, + 318, 343, + 303, 356, + 289, 367, + 274, 376, + 260, 384, + 254, 386, + 251, 388, + 244, 390, + 241, 392, + 229, 395, + 229, 396, + 225, 397, + 211, 399, + 211, 400, + 203, 401, + 194, 402, + 190, 404, + 188, 408, + End, End +}; +short bbishop[] = /* V004 */ +{ + 38, 51, + 38, 66, + 39, 78, + 47, 92, + 55, 100, + 62, 104, + 77, 104, + 92, 104, + 105, 102, + 105, 101, + 115, 100, + 125, 99, + 139, 98, + 139, 97, + 154, 97, + 159, 99, + 160, 102, + 160, 177, + 159, 177, + 158, 186, + 148, 195, + 142, 206, + 137, 213, + 132, 226, + 129, 236, + 127, 247, + 127, 277, + 128, 279, + 129, 287, + 132, 301, + 136, 313, + 142, 327, + 150, 342, + 159, 357, + 167, 371, + 176, 385, + 184, 398, + 190, 408, + 192, 412, + 192, 420, + 188, 426, + 187, 430, + 187, 445, + 188, 453, + 194, 464, + 205, 471, + 220, 471, + 229, 467, + 239, 457, + 243, 444, + 243, 429, + 239, 418, + 241, 413, + 248, 409, + 252, 405, + 260, 405, + 271, 417, + 270, 424, + 268, 427, + 266, 433, + 266, 448, + 268, 457, + 277, 469, + 280, 470, + 282, 472, + 286, 473, + 301, 473, + 306, 472, + 315, 464, + 316, 464, + 321, 452, + 322, 448, + 322, 433, + 317, 421, + 315, 418, + 316, 413, + 325, 405, + 336, 390, + 346, 377, + 354, 362, + 357, 356, + 360, 350, + 365, 337, + 369, 323, + 373, 310, + 375, 298, + 377, 283, + 377, 238, + 376, 228, + 374, 215, + 371, 200, + 367, 186, + 363, 174, + 358, 160, + 357, 156, + 357, 111, + 358, 103, + 360, 100, + 375, 100, + 390, 100, + 403, 101, + 405, 102, + 414, 103, + 423, 104, + 438, 104, + 453, 104, + 459, 103, + 473, 92, + 480, 80, + 483, 68, + 483, 53, + 480, 39, + 474, 27, + 474, 26, + 465, 27, + 457, 29, + 457, 30, + 444, 32, + 429, 32, + 414, 32, + 399, 32, + 384, 32, + 369, 32, + 354, 32, + 345, 33, + 345, 34, + 330, 34, + 328, 35, + 317, 36, + 309, 37, + 309, 38, + 297, 40, + 294, 40, + 293, 42, + 283, 45, + 278, 48, + 269, 52, + 266, 55, + 265, 56, + 261, 58, + 252, 57, + 241, 49, + 229, 43, + 225, 42, + 225, 41, + 213, 38, + 211, 37, + 206, 36, + 198, 35, + 187, 35, + 183, 35, + 168, 35, + 153, 35, + 144, 34, + 143, 33, + 128, 33, + 127, 33, + 113, 33, + 98, 33, + 95, 32, + 86, 31, + 81, 30, + 80, 29, + 70, 27, + 69, 26, + 58, 23, + 54, 21, + 49, 21, + 42, 35, + 39, 47, + 38, 51, + End, + 190, 174, + 190, 203, + 196, 204, + 206, 205, + 216, 206, + 216, 207, + 231, 207, + 246, 207, + 261, 207, + 276, 207, + 291, 207, + 301, 206, + 313, 205, + 327, 203, + 329, 200, + 329, 171, + 316, 172, + 307, 173, + 297, 173, + 296, 175, + 281, 175, + 266, 175, + 251, 175, + 244, 175, + 236, 175, + 221, 175, + 213, 174, + 199, 172, + 199, 171, + 191, 171, + 190, 174, + End, + 191, 103, + 191, 133, + 195, 135, + 205, 136, + 211, 137, + 212, 138, + 227, 138, + 242, 138, + 257, 138, + 272, 138, + 287, 138, + 295, 137, + 304, 136, + 314, 135, + 322, 134, + 322, 133, + 329, 132, + 329, 102, + 319, 103, + 307, 104, + 294, 105, + 294, 106, + 279, 106, + 264, 106, + 249, 106, + 234, 106, + 219, 106, + 215, 105, + 203, 104, + 191, 103, + End, + 244, 162, + 246, 166, + 250, 167, + 265, 167, + 270, 163, + 270, 156, + 266, 152, + 260, 150, + 260, 149, + 253, 149, + 252, 151, + 249, 151, + 245, 154, + 244, 162, + End, + 280, 385, + 287, 393, + 299, 393, + 307, 383, + 318, 368, + 323, 358, + 329, 349, + 335, 334, + 340, 319, + 343, 307, + 344, 305, + 345, 298, + 347, 287, + 348, 276, + 344, 276, + 342, 281, + 337, 295, + 331, 309, + 324, 322, + 316, 337, + 306, 350, + 295, 365, + 281, 380, + 280, 385, + End, End +}; +short brook[] = /* V005 */ +{ + 91, 38, + 91, 98, + 92, 104, + 104, 118, + 109, 127, + 113, 142, + 114, 148, + 129, 161, + 143, 175, + 144, 177, + 144, 312, + 143, 327, + 133, 336, + 121, 351, + 115, 356, + 107, 365, + 106, 368, + 106, 443, + 105, 445, + 120, 445, + 135, 445, + 150, 445, + 165, 445, + 173, 445, + 177, 432, + 182, 418, + 195, 418, + 200, 428, + 205, 443, + 207, 449, + 207, 450, + 222, 450, + 237, 450, + 252, 450, + 267, 450, + 282, 450, + 292, 450, + 298, 435, + 304, 422, + 307, 417, + 321, 418, + 327, 432, + 332, 444, + 332, 445, + 347, 445, + 361, 445, + 362, 445, + 377, 445, + 392, 445, + 397, 445, + 397, 370, + 396, 361, + 384, 351, + 375, 340, + 368, 335, + 361, 325, + 361, 190, + 362, 180, + 374, 165, + 387, 150, + 391, 145, + 395, 130, + 406, 116, + 418, 101, + 419, 98, + 419, 83, + 420, 73, + 420, 43, + 421, 38, + 419, 37, + 419, 36, + 404, 36, + 389, 36, + 374, 36, + 359, 36, + 344, 36, + 329, 36, + 314, 36, + 299, 36, + 284, 36, + 269, 36, + 254, 36, + 251, 37, + 236, 37, + 221, 37, + 206, 37, + 191, 37, + 176, 37, + 161, 37, + 146, 37, + 131, 37, + 116, 37, + 105, 37, + 101, 37, + 91, 38, + End, + 173, 328, + 173, 343, + 183, 344, + 198, 344, + 213, 344, + 228, 344, + 243, 344, + 258, 344, + 273, 344, + 288, 344, + 303, 344, + 318, 344, + 333, 344, + 333, 318, + 331, 316, + 324, 316, + 309, 316, + 294, 316, + 279, 316, + 264, 316, + 249, 316, + 234, 316, + 219, 316, + 204, 316, + 189, 316, + 175, 316, + 174, 316, + 174, 317, + 173, 328, + End, + 175, 153, + 175, 181, + 184, 181, + 199, 181, + 214, 181, + 229, 181, + 244, 181, + 259, 181, + 274, 181, + 289, 181, + 304, 181, + 319, 181, + 334, 181, + 334, 156, + 332, 153, + 325, 153, + 310, 153, + 295, 153, + 280, 153, + 265, 153, + 250, 153, + 235, 153, + 220, 153, + 205, 153, + 190, 153, + 175, 153, + End, End +}; +short bqueen[] = /* V006 */ +{ + 25, 320, + 25, 335, + 35, 348, + 40, 350, + 41, 351, + 56, 351, + 68, 347, + 76, 340, + 83, 328, + 84, 324, + 85, 320, + 84, 306, + 85, 302, + 93, 299, + 97, 296, + 100, 295, + 103, 293, + 109, 291, + 112, 289, + 117, 287, + 128, 281, + 131, 281, + 134, 278, + 139, 277, + 146, 276, + 149, 290, + 152, 305, + 154, 313, + 155, 320, + 156, 322, + 159, 337, + 162, 352, + 164, 360, + 166, 371, + 162, 376, + 155, 381, + 147, 395, + 144, 405, + 144, 420, + 147, 432, + 156, 444, + 161, 448, + 164, 449, + 167, 451, + 182, 451, + 192, 451, + 194, 448, + 202, 443, + 207, 435, + 211, 430, + 214, 421, + 215, 416, + 215, 401, + 212, 389, + 207, 381, + 207, 376, + 214, 363, + 221, 349, + 228, 336, + 235, 322, + 243, 307, + 245, 304, + 250, 304, + 257, 318, + 265, 333, + 273, 348, + 280, 361, + 288, 376, + 290, 379, + 289, 384, + 286, 389, + 284, 397, + 283, 405, + 284, 419, + 289, 432, + 299, 444, + 306, 448, + 309, 449, + 310, 450, + 325, 450, + 331, 449, + 333, 449, + 341, 445, + 350, 434, + 354, 424, + 355, 420, + 355, 405, + 353, 395, + 346, 381, + 336, 373, + 331, 370, + 331, 357, + 332, 357, + 335, 342, + 338, 329, + 341, 316, + 344, 302, + 347, 290, + 350, 277, + 351, 273, + 358, 273, + 362, 277, + 375, 285, + 390, 295, + 404, 304, + 409, 307, + 411, 310, + 412, 324, + 418, 336, + 430, 348, + 436, 350, + 436, 351, + 451, 351, + 461, 347, + 470, 336, + 472, 330, + 472, 315, + 468, 304, + 459, 293, + 450, 288, + 446, 287, + 445, 286, + 433, 285, + 428, 272, + 423, 258, + 418, 244, + 413, 229, + 408, 215, + 403, 201, + 398, 186, + 397, 183, + 396, 177, + 395, 166, + 394, 157, + 393, 142, + 392, 131, + 391, 121, + 390, 109, + 389, 96, + 388, 81, + 386, 67, + 373, 58, + 370, 57, + 367, 55, + 361, 53, + 358, 51, + 351, 49, + 350, 48, + 338, 45, + 338, 44, + 327, 42, + 323, 41, + 321, 40, + 309, 38, + 300, 37, + 299, 36, + 287, 35, + 283, 35, + 272, 35, + 257, 35, + 256, 34, + 256, 33, + 241, 33, + 226, 33, + 222, 34, + 213, 35, + 202, 36, + 201, 37, + 186, 39, + 179, 40, + 179, 41, + 166, 43, + 163, 43, + 162, 45, + 149, 48, + 149, 49, + 144, 50, + 138, 52, + 135, 54, + 130, 55, + 117, 63, + 115, 66, + 114, 74, + 112, 89, + 110, 103, + 109, 113, + 107, 126, + 106, 137, + 105, 142, + 104, 151, + 102, 165, + 101, 170, + 100, 181, + 98, 191, + 93, 202, + 88, 217, + 85, 222, + 80, 236, + 74, 249, + 69, 262, + 62, 277, + 59, 285, + 57, 287, + 47, 290, + 43, 293, + 40, 293, + 39, 296, + 32, 301, + 26, 313, + 25, 320, + End, + 128, 200, + 128, 215, + 135, 217, + 138, 219, + 150, 222, + 151, 223, + 155, 224, + 167, 226, + 168, 227, + 181, 229, + 192, 230, + 192, 231, + 198, 232, + 213, 232, + 228, 232, + 243, 232, + 258, 232, + 273, 232, + 288, 232, + 302, 231, + 302, 230, + 310, 229, + 318, 228, + 327, 227, + 327, 226, + 332, 225, + 344, 223, + 344, 222, + 358, 219, + 358, 218, + 366, 216, + 370, 213, + 370, 202, + 369, 193, + 368, 184, + 363, 184, + 355, 186, + 355, 187, + 348, 188, + 341, 190, + 341, 191, + 337, 192, + 323, 194, + 323, 195, + 316, 196, + 308, 197, + 295, 198, + 281, 199, + 266, 199, + 251, 199, + 236, 199, + 233, 199, + 221, 199, + 206, 199, + 206, 198, + 195, 197, + 186, 196, + 177, 195, + 176, 193, + 171, 193, + 158, 191, + 158, 190, + 145, 187, + 144, 186, + 137, 184, + 137, 183, + 134, 183, + 131, 183, + 130, 188, + 128, 200, + End, + 134, 164, + 146, 164, + 150, 161, + 151, 154, + 150, 150, + 143, 144, + 140, 144, + 136, 144, + 135, 149, + 134, 164, + End, + 140, 114, + 140, 121, + 149, 124, + 149, 125, + 163, 128, + 163, 129, + 175, 131, + 179, 131, + 180, 133, + 189, 134, + 197, 135, + 209, 136, + 209, 137, + 224, 137, + 239, 137, + 254, 137, + 269, 137, + 284, 137, + 289, 136, + 300, 135, + 309, 134, + 315, 133, + 316, 132, + 330, 130, + 334, 129, + 335, 128, + 349, 125, + 349, 124, + 359, 121, + 363, 117, + 362, 104, + 361, 89, + 360, 86, + 360, 85, + 347, 88, + 343, 90, + 332, 92, + 331, 93, + 319, 95, + 313, 95, + 312, 97, + 305, 98, + 296, 99, + 286, 100, + 286, 101, + 271, 101, + 256, 101, + 241, 101, + 226, 101, + 211, 101, + 211, 100, + 197, 99, + 188, 98, + 182, 97, + 182, 96, + 169, 94, + 164, 93, + 164, 92, + 153, 90, + 150, 88, + 144, 88, + 143, 92, + 141, 106, + 140, 114, + End, + 233, 175, + 237, 180, + 242, 181, + 257, 181, + 263, 177, + 263, 168, + 259, 162, + 256, 162, + 254, 160, + 241, 160, + 234, 165, + 233, 175, + End, + 348, 157, + 352, 162, + 366, 163, + 366, 157, + 365, 143, + 357, 143, + 354, 145, + 349, 150, + 348, 157, + End, End +}; +short bking[] = /* V007 */ +{ + 24, 285, + 24, 315, + 25, 323, + 28, 335, + 34, 349, + 42, 362, + 53, 373, + 55, 375, + 68, 384, + 74, 386, + 76, 388, + 87, 391, + 87, 392, + 91, 393, + 100, 394, + 115, 394, + 130, 394, + 145, 392, + 145, 391, + 155, 389, + 161, 386, + 166, 385, + 168, 383, + 174, 381, + 176, 379, + 185, 376, + 185, 463, + 191, 464, + 206, 464, + 211, 464, + 221, 464, + 236, 464, + 251, 464, + 266, 464, + 281, 464, + 296, 464, + 311, 464, + 311, 460, + 312, 457, + 312, 397, + 313, 397, + 313, 382, + 319, 382, + 321, 384, + 327, 386, + 329, 388, + 336, 390, + 339, 392, + 350, 395, + 352, 396, + 356, 397, + 370, 398, + 385, 398, + 400, 398, + 412, 396, + 412, 395, + 423, 392, + 423, 390, + 427, 390, + 437, 384, + 451, 372, + 463, 357, + 469, 344, + 474, 329, + 475, 320, + 475, 290, + 474, 283, + 471, 271, + 466, 257, + 460, 246, + 452, 232, + 441, 218, + 428, 204, + 413, 191, + 406, 187, + 403, 184, + 400, 171, + 398, 160, + 396, 149, + 394, 139, + 392, 127, + 390, 116, + 388, 105, + 386, 93, + 384, 80, + 381, 69, + 373, 63, + 358, 54, + 352, 52, + 349, 50, + 339, 47, + 339, 46, + 327, 43, + 326, 42, + 323, 41, + 311, 39, + 310, 38, + 297, 36, + 287, 35, + 286, 33, + 280, 33, + 265, 33, + 250, 33, + 235, 33, + 220, 33, + 207, 34, + 206, 35, + 198, 36, + 185, 38, + 183, 39, + 169, 42, + 167, 43, + 156, 46, + 155, 47, + 148, 49, + 145, 52, + 142, 52, + 133, 57, + 120, 66, + 116, 73, + 113, 87, + 110, 101, + 107, 114, + 104, 127, + 103, 129, + 101, 140, + 100, 143, + 97, 157, + 94, 169, + 91, 183, + 80, 191, + 67, 203, + 54, 218, + 44, 232, + 41, 239, + 35, 248, + 33, 256, + 32, 256, + 29, 267, + 27, 272, + 24, 285, + End, + 53, 295, + 53, 310, + 54, 319, + 60, 334, + 72, 349, + 81, 355, + 85, 358, + 94, 362, + 99, 363, + 99, 364, + 114, 364, + 129, 364, + 141, 363, + 152, 360, + 152, 359, + 160, 356, + 172, 349, + 187, 336, + 200, 322, + 209, 308, + 216, 295, + 220, 281, + 222, 272, + 237, 272, + 252, 272, + 267, 272, + 274, 272, + 277, 283, + 280, 295, + 287, 310, + 296, 325, + 305, 335, + 308, 339, + 323, 352, + 337, 360, + 348, 365, + 356, 367, + 356, 368, + 362, 369, + 377, 369, + 392, 369, + 401, 368, + 401, 367, + 411, 364, + 413, 362, + 418, 360, + 431, 349, + 440, 335, + 444, 325, + 445, 319, + 445, 304, + 444, 289, + 442, 280, + 436, 265, + 427, 250, + 414, 235, + 401, 222, + 395, 218, + 395, 217, + 385, 218, + 380, 220, + 377, 222, + 370, 224, + 370, 225, + 358, 228, + 358, 229, + 344, 232, + 343, 233, + 340, 233, + 330, 235, + 324, 236, + 323, 237, + 315, 238, + 302, 239, + 287, 239, + 272, 239, + 257, 239, + 242, 239, + 227, 239, + 225, 239, + 212, 239, + 197, 239, + 197, 238, + 188, 237, + 188, 236, + 173, 234, + 168, 233, + 167, 232, + 156, 230, + 152, 229, + 151, 228, + 139, 225, + 135, 223, + 129, 221, + 128, 221, + 125, 219, + 122, 218, + 117, 215, + 114, 214, + 111, 212, + 103, 212, + 98, 218, + 86, 227, + 75, 242, + 67, 253, + 60, 268, + 56, 280, + 53, 295, + End, + 81, 293, + 81, 308, + 84, 318, + 91, 330, + 101, 337, + 109, 340, + 120, 341, + 135, 341, + 136, 340, + 144, 338, + 154, 333, + 168, 323, + 179, 310, + 185, 299, + 188, 294, + 191, 282, + 192, 267, + 190, 266, + 178, 265, + 177, 264, + 171, 263, + 158, 261, + 158, 260, + 144, 257, + 142, 256, + 131, 253, + 130, 252, + 120, 249, + 120, 247, + 116, 247, + 114, 245, + 106, 245, + 98, 254, + 88, 268, + 83, 282, + 81, 293, + End, + 129, 171, + 131, 171, + 146, 171, + 149, 169, + 154, 164, + 155, 156, + 153, 149, + 145, 142, + 143, 141, + 140, 140, + 140, 139, + 137, 139, + 135, 140, + 133, 148, + 130, 161, + 129, 171, + End, + 143, 107, + 143, 113, + 153, 116, + 153, 117, + 163, 119, + 168, 120, + 169, 121, + 182, 123, + 188, 124, + 188, 125, + 196, 126, + 205, 127, + 215, 128, + 215, 129, + 230, 129, + 245, 129, + 260, 129, + 275, 129, + 289, 128, + 302, 127, + 311, 126, + 317, 125, + 319, 124, + 331, 122, + 335, 121, + 336, 120, + 350, 117, + 350, 116, + 355, 114, + 354, 99, + 352, 88, + 351, 86, + 351, 85, + 337, 87, + 333, 87, + 332, 89, + 319, 91, + 313, 91, + 312, 93, + 302, 94, + 288, 95, + 273, 95, + 258, 95, + 243, 95, + 228, 95, + 213, 95, + 202, 94, + 194, 93, + 193, 92, + 179, 90, + 174, 89, + 173, 88, + 164, 86, + 162, 85, + 155, 83, + 149, 83, + 146, 92, + 144, 103, + 143, 107, + End, + 211, 373, + 214, 380, + 221, 385, + 228, 394, + 233, 399, + 232, 404, + 221, 413, + 211, 425, + 213, 431, + 219, 435, + 219, 436, + 229, 436, + 233, 430, + 247, 417, + 252, 417, + 257, 424, + 265, 431, + 270, 436, + 280, 436, + 287, 426, + 284, 420, + 269, 406, + 265, 400, + 273, 390, + 287, 376, + 287, 372, + 278, 364, + 278, 363, + 270, 364, + 257, 378, + 253, 381, + 244, 381, + 234, 369, + 232, 367, + 226, 362, + 220, 363, + 211, 373, + End, + 225, 167, + 225, 179, + 230, 185, + 236, 188, + 248, 189, + 263, 189, + 263, 188, + 268, 186, + 274, 179, + 274, 171, + 273, 167, + 265, 160, + 259, 158, + 259, 157, + 254, 157, + 239, 157, + 239, 158, + 235, 159, + 225, 167, + End, + 232, 331, + 233, 331, + 248, 331, + 263, 331, + 264, 330, + 260, 322, + 253, 308, + 250, 299, + 247, 299, + 245, 303, + 238, 318, + 235, 322, + 232, 331, + End, + 305, 279, + 308, 292, + 313, 305, + 322, 319, + 336, 333, + 342, 336, + 346, 339, + 354, 342, + 355, 344, + 360, 344, + 375, 344, + 390, 344, + 402, 337, + 412, 324, + 416, 311, + 416, 296, + 414, 285, + 409, 272, + 401, 258, + 391, 247, + 385, 247, + 378, 251, + 368, 254, + 368, 255, + 356, 258, + 355, 259, + 352, 260, + 340, 262, + 340, 263, + 326, 265, + 316, 266, + 316, 267, + 306, 268, + 305, 279, + End, + 340, 165, + 345, 172, + 352, 173, + 367, 173, + 367, 168, + 365, 157, + 362, 143, + 357, 143, + 355, 144, + 346, 149, + 341, 156, + 340, 165, + End, End +}; +short sempty[] = /* V009 */ +{ + 499, 4, + 499, 6, + 505, 14, + 512, 14, + 512, 6, + 511, 4, + 499, 4, + End, + 428, 2, + 428, 4, + 435, 12, + 449, 27, + 463, 42, + 476, 56, + 490, 70, + 504, 85, + 511, 86, + 511, 78, + 509, 74, + 495, 60, + 481, 45, + 467, 30, + 454, 16, + 440, 2, + 428, 2, + End, + 358, 4, + 367, 14, + 381, 29, + 394, 43, + 408, 58, + 422, 73, + 436, 87, + 449, 102, + 458, 110, + 472, 125, + 485, 139, + 493, 146, + 503, 158, + 510, 158, + 510, 149, + 504, 143, + 490, 128, + 476, 114, + 462, 99, + 448, 84, + 434, 70, + 421, 55, + 412, 47, + 399, 32, + 385, 17, + 372, 3, + 365, 2, + 365, 1, + 359, 1, + 359, 2, + 358, 4, + End, + 287, 1, + 290, 6, + 303, 19, + 316, 34, + 330, 49, + 344, 63, + 358, 78, + 372, 93, + 386, 108, + 400, 122, + 413, 137, + 427, 151, + 441, 165, + 455, 180, + 469, 194, + 483, 209, + 497, 222, + 502, 229, + 510, 229, + 509, 220, + 500, 211, + 486, 196, + 471, 182, + 457, 167, + 443, 152, + 429, 138, + 415, 123, + 401, 108, + 387, 93, + 373, 79, + 359, 64, + 346, 50, + 333, 35, + 328, 31, + 315, 16, + 301, 1, + 287, 1, + End, + 219, 3, + 227, 12, + 241, 27, + 254, 41, + 268, 56, + 281, 70, + 295, 84, + 308, 98, + 322, 113, + 336, 128, + 350, 143, + 363, 157, + 377, 171, + 391, 186, + 405, 200, + 419, 215, + 433, 229, + 447, 244, + 461, 258, + 474, 272, + 489, 286, + 502, 300, + 509, 300, + 509, 291, + 508, 291, + 494, 277, + 480, 263, + 466, 248, + 452, 234, + 448, 229, + 434, 216, + 420, 201, + 406, 187, + 392, 172, + 378, 157, + 364, 142, + 350, 127, + 336, 112, + 322, 98, + 308, 83, + 295, 69, + 282, 54, + 273, 46, + 260, 31, + 246, 16, + 233, 2, + 228, 1, + 228, 0, + 221, 0, + 219, 3, + End, + 150, 0, + 150, 2, + 155, 8, + 169, 23, + 182, 37, + 196, 52, + 209, 66, + 223, 80, + 237, 95, + 250, 109, + 264, 124, + 278, 139, + 292, 154, + 306, 168, + 316, 180, + 330, 193, + 343, 208, + 353, 217, + 366, 232, + 379, 244, + 393, 259, + 406, 273, + 419, 287, + 434, 301, + 448, 316, + 462, 330, + 476, 344, + 490, 358, + 504, 372, + 510, 372, + 509, 371, + 509, 363, + 495, 349, + 481, 334, + 466, 320, + 452, 305, + 438, 291, + 424, 277, + 411, 263, + 397, 249, + 383, 234, + 369, 219, + 355, 205, + 341, 190, + 327, 176, + 313, 161, + 299, 146, + 285, 131, + 272, 117, + 258, 102, + 244, 87, + 230, 72, + 216, 58, + 203, 43, + 189, 29, + 176, 14, + 162, 0, + 150, 0, + End, + 81, 0, + 82, 3, + 86, 8, + 100, 22, + 114, 37, + 128, 52, + 141, 66, + 155, 80, + 169, 95, + 182, 109, + 196, 124, + 210, 138, + 224, 153, + 238, 168, + 252, 183, + 266, 197, + 280, 212, + 294, 227, + 308, 242, + 322, 256, + 335, 271, + 349, 284, + 362, 299, + 376, 312, + 390, 327, + 397, 335, + 409, 346, + 423, 361, + 437, 375, + 451, 390, + 466, 404, + 480, 419, + 495, 433, + 504, 443, + 511, 443, + 510, 435, + 499, 423, + 485, 409, + 470, 395, + 456, 380, + 442, 366, + 428, 352, + 414, 337, + 400, 323, + 386, 309, + 372, 294, + 358, 280, + 344, 265, + 330, 250, + 316, 235, + 302, 221, + 288, 206, + 274, 191, + 260, 177, + 247, 162, + 233, 148, + 219, 133, + 205, 118, + 191, 103, + 177, 88, + 164, 74, + 150, 60, + 136, 45, + 122, 30, + 108, 15, + 94, 0, + 81, 0, + End, + 10, 427, + 10, 436, + 20, 447, + 34, 461, + 48, 476, + 62, 490, + 75, 505, + 88, 505, + 85, 501, + 71, 486, + 57, 472, + 43, 457, + 29, 442, + 15, 427, + 10, 427, + End, + 9, 499, + 9, 506, + 18, 505, + 14, 499, + 9, 499, + End, + 15, 286, + 16, 295, + 22, 303, + 37, 317, + 51, 332, + 65, 346, + 79, 361, + 93, 375, + 107, 390, + 121, 405, + 135, 419, + 149, 434, + 163, 449, + 177, 463, + 191, 478, + 205, 493, + 218, 507, + 231, 507, + 228, 504, + 215, 490, + 201, 475, + 187, 460, + 173, 446, + 159, 431, + 145, 416, + 132, 402, + 118, 388, + 104, 373, + 91, 359, + 77, 345, + 63, 330, + 49, 316, + 35, 301, + 21, 286, + 15, 286, + End, + 15, 356, + 15, 365, + 24, 375, + 38, 389, + 51, 403, + 65, 417, + 79, 432, + 93, 446, + 107, 461, + 121, 476, + 135, 491, + 149, 506, + 163, 507, + 159, 502, + 146, 489, + 132, 474, + 118, 459, + 104, 444, + 90, 430, + 76, 415, + 62, 400, + 48, 386, + 34, 371, + 20, 356, + 15, 356, + End, + 19, 213, + 19, 223, + 27, 232, + 41, 246, + 55, 260, + 69, 275, + 83, 289, + 97, 304, + 111, 318, + 125, 333, + 138, 347, + 152, 361, + 166, 376, + 180, 391, + 194, 405, + 208, 420, + 222, 435, + 236, 449, + 250, 464, + 264, 479, + 278, 493, + 291, 508, + 305, 508, + 302, 505, + 288, 490, + 274, 475, + 260, 461, + 246, 446, + 232, 431, + 218, 417, + 204, 402, + 190, 387, + 176, 372, + 162, 358, + 148, 343, + 134, 328, + 121, 314, + 107, 300, + 94, 286, + 80, 272, + 66, 257, + 52, 243, + 38, 228, + 24, 213, + 19, 213, + End, + 22, 69, + 22, 82, + 37, 96, + 51, 111, + 65, 125, + 78, 139, + 92, 153, + 106, 168, + 120, 182, + 134, 197, + 148, 212, + 162, 226, + 176, 241, + 190, 256, + 203, 270, + 208, 274, + 217, 285, + 226, 293, + 240, 308, + 254, 323, + 268, 338, + 282, 352, + 296, 367, + 309, 381, + 323, 395, + 336, 409, + 350, 423, + 364, 437, + 378, 452, + 392, 466, + 406, 481, + 420, 495, + 434, 509, + 448, 510, + 445, 506, + 430, 492, + 416, 477, + 402, 463, + 388, 448, + 374, 434, + 360, 419, + 346, 405, + 332, 390, + 318, 376, + 304, 361, + 290, 346, + 276, 332, + 262, 317, + 248, 302, + 234, 288, + 220, 273, + 206, 258, + 192, 243, + 178, 228, + 164, 214, + 150, 199, + 137, 185, + 123, 171, + 109, 156, + 96, 142, + 82, 128, + 68, 113, + 54, 99, + 40, 84, + 26, 69, + 22, 69, + End, + 21, 141, + 22, 153, + 36, 167, + 50, 181, + 63, 195, + 77, 209, + 90, 223, + 104, 237, + 117, 251, + 131, 265, + 145, 280, + 159, 295, + 173, 309, + 187, 324, + 201, 339, + 215, 353, + 229, 368, + 243, 383, + 256, 397, + 270, 411, + 284, 426, + 298, 440, + 308, 452, + 323, 466, + 337, 481, + 351, 495, + 363, 509, + 376, 509, + 376, 507, + 369, 501, + 359, 489, + 345, 476, + 331, 461, + 317, 446, + 303, 432, + 289, 417, + 275, 402, + 262, 389, + 248, 374, + 234, 359, + 220, 345, + 206, 330, + 192, 315, + 178, 300, + 164, 286, + 150, 271, + 136, 256, + 123, 242, + 109, 228, + 96, 214, + 82, 200, + 68, 185, + 54, 171, + 40, 156, + 26, 141, + 21, 141, + End, + 23, 0, + 23, 6, + 24, 10, + 37, 22, + 50, 37, + 64, 50, + 77, 65, + 91, 78, + 105, 93, + 119, 108, + 133, 122, + 147, 137, + 161, 152, + 175, 167, + 189, 181, + 203, 196, + 217, 211, + 231, 225, + 245, 240, + 259, 255, + 272, 269, + 286, 283, + 300, 298, + 313, 312, + 327, 326, + 340, 340, + 354, 354, + 367, 368, + 381, 382, + 395, 397, + 409, 411, + 423, 425, + 436, 439, + 451, 453, + 465, 468, + 480, 482, + 494, 497, + 508, 511, + 519, 512, + 517, 506, + 505, 493, + 490, 479, + 477, 465, + 462, 451, + 449, 437, + 434, 423, + 420, 408, + 406, 394, + 392, 379, + 378, 365, + 364, 350, + 350, 336, + 336, 321, + 322, 307, + 308, 292, + 294, 277, + 280, 262, + 266, 248, + 252, 233, + 238, 218, + 224, 203, + 210, 189, + 196, 174, + 182, 159, + 169, 145, + 155, 130, + 141, 116, + 127, 101, + 113, 86, + 99, 72, + 87, 58, + 73, 45, + 59, 30, + 45, 15, + 31, 0, + 23, 0, + End, End +}; +short wpawn[] = /* V010 */ +{ + 110, 36, + 110, 46, + 112, 54, + 115, 63, + 123, 76, + 137, 90, + 151, 100, + 156, 102, + 158, 105, + 161, 105, + 166, 108, + 172, 110, + 175, 112, + 185, 115, + 187, 116, + 201, 119, + 202, 121, + 197, 129, + 191, 142, + 188, 156, + 188, 186, + 191, 200, + 195, 213, + 200, 228, + 205, 241, + 210, 254, + 210, 269, + 209, 272, + 202, 274, + 188, 274, + 187, 274, + 172, 274, + 157, 274, + 142, 274, + 127, 274, + 126, 275, + 125, 287, + 127, 299, + 130, 309, + 138, 322, + 150, 336, + 165, 347, + 173, 351, + 175, 352, + 178, 354, + 184, 356, + 187, 358, + 197, 361, + 198, 362, + 202, 364, + 202, 391, + 203, 398, + 205, 403, + 211, 418, + 224, 431, + 231, 435, + 234, 437, + 238, 438, + 253, 438, + 268, 438, + 280, 431, + 291, 419, + 298, 406, + 301, 394, + 302, 391, + 302, 376, + 301, 364, + 305, 361, + 314, 359, + 317, 357, + 323, 355, + 327, 353, + 332, 351, + 346, 342, + 360, 329, + 370, 315, + 376, 300, + 377, 291, + 377, 276, + 369, 275, + 354, 275, + 354, 274, + 344, 273, + 329, 273, + 314, 273, + 299, 273, + 297, 269, + 296, 256, + 297, 251, + 301, 240, + 306, 227, + 309, 220, + 312, 213, + 318, 200, + 321, 188, + 322, 176, + 322, 161, + 320, 148, + 316, 135, + 312, 129, + 309, 121, + 312, 119, + 321, 117, + 325, 115, + 335, 112, + 336, 111, + 342, 109, + 346, 107, + 349, 106, + 356, 102, + 369, 94, + 382, 82, + 393, 67, + 399, 52, + 399, 37, + 391, 37, + 376, 37, + 361, 37, + 346, 37, + 346, 36, + 335, 36, + 320, 36, + 305, 36, + 290, 36, + 275, 36, + 260, 36, + 245, 36, + 230, 36, + 215, 36, + 200, 36, + 185, 36, + 170, 36, + 155, 36, + 140, 36, + 125, 36, + 110, 36, + End, + 166, 65, + 166, 69, + 176, 77, + 190, 85, + 198, 88, + 199, 89, + 211, 92, + 211, 93, + 222, 95, + 225, 97, + 229, 99, + 235, 107, + 236, 119, + 233, 126, + 222, 140, + 217, 154, + 215, 167, + 215, 182, + 216, 190, + 218, 199, + 222, 211, + 228, 225, + 236, 240, + 243, 255, + 244, 266, + 247, 266, + 262, 266, + 262, 253, + 264, 245, + 270, 234, + 275, 225, + 278, 220, + 286, 206, + 291, 193, + 292, 178, + 292, 163, + 291, 155, + 289, 147, + 285, 137, + 276, 125, + 275, 111, + 276, 107, + 278, 103, + 287, 96, + 290, 95, + 302, 93, + 303, 92, + 314, 89, + 315, 87, + 318, 87, + 328, 82, + 341, 74, + 345, 68, + 344, 67, + 336, 66, + 321, 66, + 306, 66, + 291, 66, + 276, 66, + 261, 66, + 246, 66, + 231, 66, + 231, 65, + 226, 65, + 211, 65, + 196, 65, + 181, 65, + 166, 65, + End, + 175, 308, + 187, 321, + 202, 331, + 205, 332, + 210, 335, + 221, 338, + 221, 339, + 225, 340, + 233, 341, + 238, 342, + 242, 348, + 243, 356, + 241, 363, + 235, 370, + 232, 379, + 231, 389, + 232, 395, + 238, 405, + 244, 409, + 259, 409, + 265, 405, + 266, 405, + 271, 396, + 272, 383, + 271, 377, + 265, 368, + 265, 354, + 269, 347, + 277, 341, + 285, 340, + 289, 338, + 296, 336, + 300, 334, + 305, 332, + 318, 323, + 331, 309, + 331, 304, + 324, 304, + 309, 304, + 296, 304, + 294, 304, + 279, 304, + 264, 304, + 249, 304, + 249, 303, + 236, 303, + 221, 303, + 215, 303, + 206, 303, + 191, 303, + 176, 303, + 176, 304, + 175, 308, + End, End +}; +short wknight[] = /* V011 */ +{ + 43, 211, + 44, 219, + 52, 234, + 63, 245, + 70, 249, + 76, 264, + 78, 267, + 81, 273, + 85, 283, + 92, 297, + 98, 311, + 104, 323, + 110, 337, + 117, 351, + 123, 365, + 129, 379, + 128, 392, + 125, 406, + 123, 417, + 120, 431, + 119, 435, + 119, 449, + 122, 451, + 135, 451, + 142, 443, + 154, 434, + 158, 434, + 161, 442, + 165, 457, + 167, 465, + 170, 471, + 184, 471, + 185, 469, + 191, 463, + 202, 454, + 207, 448, + 217, 439, + 230, 438, + 243, 437, + 243, 436, + 254, 435, + 265, 433, + 266, 432, + 279, 429, + 279, 428, + 291, 425, + 293, 423, + 299, 421, + 304, 418, + 307, 417, + 320, 410, + 333, 402, + 340, 396, + 348, 391, + 363, 377, + 377, 363, + 388, 349, + 399, 334, + 408, 319, + 415, 305, + 422, 291, + 428, 276, + 433, 263, + 438, 249, + 442, 235, + 445, 222, + 448, 210, + 451, 196, + 453, 185, + 455, 172, + 457, 158, + 458, 150, + 459, 138, + 460, 126, + 460, 111, + 461, 111, + 461, 51, + 460, 38, + 458, 37, + 443, 37, + 428, 37, + 413, 37, + 398, 37, + 383, 37, + 368, 37, + 353, 37, + 338, 37, + 323, 37, + 308, 37, + 293, 37, + 278, 37, + 263, 37, + 261, 35, + 246, 35, + 231, 35, + 216, 35, + 201, 35, + 186, 35, + 171, 35, + 156, 35, + 145, 35, + 143, 39, + 143, 69, + 146, 84, + 150, 98, + 156, 113, + 164, 127, + 175, 142, + 176, 143, + 188, 157, + 202, 169, + 216, 181, + 230, 193, + 231, 195, + 216, 195, + 201, 195, + 187, 185, + 174, 176, + 160, 166, + 154, 161, + 151, 154, + 144, 150, + 143, 149, + 138, 148, + 138, 147, + 125, 148, + 119, 148, + 110, 148, + 110, 147, + 101, 144, + 99, 143, + 94, 142, + 79, 142, + 76, 143, + 75, 144, + 69, 146, + 69, 147, + 62, 151, + 58, 165, + 54, 178, + 49, 193, + 44, 208, + 43, 211, + End, + 78, 208, + 79, 216, + 92, 226, + 100, 240, + 106, 254, + 113, 269, + 119, 283, + 126, 297, + 132, 311, + 139, 326, + 146, 341, + 152, 355, + 153, 357, + 159, 369, + 165, 382, + 168, 389, + 168, 390, + 183, 390, + 198, 390, + 201, 392, + 200, 396, + 186, 408, + 185, 410, + 200, 410, + 215, 410, + 230, 410, + 239, 409, + 252, 407, + 256, 406, + 260, 404, + 267, 403, + 269, 402, + 270, 401, + 278, 398, + 286, 394, + 299, 387, + 314, 377, + 329, 365, + 343, 352, + 356, 337, + 368, 323, + 377, 309, + 385, 295, + 392, 281, + 398, 268, + 403, 256, + 408, 241, + 412, 228, + 416, 214, + 419, 202, + 422, 190, + 424, 179, + 425, 170, + 426, 162, + 427, 150, + 428, 139, + 428, 124, + 429, 122, + 429, 107, + 430, 99, + 430, 70, + 415, 70, + 401, 69, + 400, 68, + 385, 68, + 370, 68, + 355, 68, + 340, 68, + 325, 68, + 310, 68, + 298, 67, + 283, 67, + 268, 67, + 253, 67, + 238, 67, + 223, 67, + 208, 67, + 193, 67, + 178, 67, + 176, 68, + 177, 78, + 182, 93, + 188, 106, + 197, 121, + 208, 135, + 222, 149, + 236, 161, + 251, 173, + 265, 185, + 274, 193, + 274, 238, + 272, 244, + 267, 248, + 252, 248, + 240, 236, + 238, 233, + 230, 229, + 226, 228, + 226, 227, + 211, 227, + 200, 230, + 193, 235, + 186, 235, + 185, 221, + 171, 211, + 158, 202, + 144, 193, + 132, 185, + 128, 183, + 113, 183, + 104, 182, + 99, 177, + 94, 176, + 88, 176, + 84, 189, + 80, 202, + 78, 208, + End, + 153, 282, + 154, 291, + 161, 305, + 166, 317, + 179, 317, + 194, 317, + 199, 317, + 209, 317, + 210, 309, + 208, 306, + 199, 304, + 200, 303, + 188, 291, + 178, 288, + 177, 286, + 167, 286, + 163, 280, + 156, 280, + 153, 282, + End, End +}; +short wbishop[] = /* V012 */ +{ + 33, 59, + 34, 74, + 40, 88, + 51, 101, + 56, 103, + 58, 105, + 63, 105, + 64, 106, + 79, 106, + 89, 106, + 90, 105, + 94, 104, + 95, 103, + 109, 101, + 118, 100, + 118, 99, + 130, 98, + 145, 98, + 156, 98, + 157, 101, + 157, 176, + 156, 185, + 144, 199, + 136, 213, + 131, 224, + 128, 236, + 127, 240, + 126, 249, + 126, 264, + 127, 277, + 129, 289, + 132, 301, + 137, 316, + 144, 330, + 152, 344, + 158, 354, + 161, 359, + 170, 373, + 179, 387, + 187, 400, + 194, 413, + 193, 419, + 189, 426, + 188, 431, + 188, 446, + 193, 458, + 201, 466, + 204, 467, + 207, 467, + 219, 467, + 228, 467, + 238, 458, + 240, 454, + 243, 448, + 244, 443, + 244, 428, + 242, 420, + 240, 418, + 240, 412, + 249, 407, + 252, 403, + 256, 401, + 263, 405, + 272, 415, + 269, 426, + 267, 431, + 267, 446, + 273, 461, + 280, 466, + 283, 469, + 286, 470, + 301, 470, + 307, 470, + 309, 467, + 316, 462, + 322, 450, + 323, 444, + 323, 429, + 316, 415, + 317, 410, + 329, 398, + 339, 383, + 349, 369, + 355, 357, + 356, 356, + 361, 343, + 365, 334, + 369, 319, + 372, 307, + 374, 296, + 376, 282, + 376, 237, + 375, 228, + 373, 214, + 370, 200, + 366, 186, + 362, 173, + 357, 160, + 355, 154, + 355, 109, + 356, 98, + 360, 97, + 370, 97, + 375, 97, + 390, 97, + 404, 98, + 413, 99, + 413, 100, + 428, 100, + 443, 100, + 453, 99, + 463, 94, + 472, 84, + 477, 74, + 479, 66, + 479, 51, + 478, 41, + 475, 31, + 470, 22, + 469, 21, + 469, 20, + 458, 23, + 458, 24, + 447, 26, + 442, 27, + 442, 28, + 433, 29, + 418, 29, + 403, 29, + 388, 29, + 373, 29, + 358, 29, + 346, 30, + 331, 30, + 328, 32, + 318, 33, + 307, 34, + 301, 35, + 300, 36, + 289, 39, + 289, 40, + 279, 43, + 277, 45, + 273, 46, + 267, 50, + 258, 56, + 249, 55, + 235, 46, + 230, 44, + 227, 42, + 220, 40, + 216, 38, + 205, 36, + 205, 35, + 196, 34, + 188, 34, + 181, 34, + 166, 34, + 151, 34, + 136, 34, + 126, 34, + 121, 34, + 106, 34, + 94, 33, + 84, 32, + 84, 31, + 69, 29, + 65, 28, + 65, 27, + 53, 24, + 53, 23, + 44, 23, + 38, 35, + 35, 47, + 34, 51, + 33, 59, + End, + 63, 61, + 63, 68, + 68, 75, + 79, 75, + 94, 75, + 104, 74, + 116, 73, + 116, 72, + 130, 71, + 137, 70, + 152, 70, + 150, 68, + 147, 67, + 140, 66, + 125, 65, + 110, 65, + 95, 65, + 80, 65, + 80, 64, + 70, 62, + 70, 61, + 63, 61, + End, + 158, 253, + 158, 268, + 160, 283, + 163, 297, + 168, 312, + 175, 327, + 183, 341, + 192, 355, + 201, 369, + 211, 384, + 215, 389, + 226, 389, + 229, 385, + 244, 373, + 258, 358, + 270, 344, + 281, 329, + 290, 314, + 297, 302, + 302, 289, + 307, 277, + 311, 263, + 314, 252, + 317, 238, + 318, 226, + 319, 218, + 319, 203, + 317, 202, + 317, 201, + 309, 202, + 295, 203, + 280, 203, + 265, 203, + 250, 203, + 235, 203, + 220, 203, + 205, 203, + 201, 202, + 201, 201, + 190, 200, + 188, 200, + 179, 200, + 170, 213, + 164, 226, + 160, 240, + 159, 244, + 159, 253, + 158, 253, + End, + 188, 136, + 188, 166, + 190, 168, + 194, 169, + 201, 170, + 201, 171, + 209, 172, + 221, 173, + 236, 173, + 237, 173, + 251, 173, + 266, 173, + 281, 173, + 296, 173, + 298, 172, + 307, 171, + 307, 170, + 317, 169, + 323, 168, + 325, 165, + 325, 131, + 312, 132, + 302, 133, + 293, 134, + 293, 135, + 278, 135, + 263, 135, + 248, 135, + 233, 135, + 218, 135, + 217, 134, + 205, 134, + 198, 133, + 189, 133, + 188, 136, + End, + 207, 443, + 209, 448, + 221, 449, + 225, 444, + 226, 431, + 221, 425, + 214, 425, + 208, 432, + 207, 443, + End, + 217, 94, + 217, 97, + 222, 99, + 222, 100, + 226, 101, + 236, 102, + 251, 102, + 266, 102, + 281, 102, + 292, 100, + 292, 99, + 296, 98, + 297, 95, + 293, 93, + 287, 92, + 287, 91, + 274, 89, + 274, 88, + 268, 88, + 253, 88, + 238, 88, + 238, 89, + 225, 91, + 225, 92, + 217, 94, + End, + 237, 159, + 239, 165, + 246, 169, + 261, 169, + 264, 168, + 270, 162, + 270, 153, + 268, 149, + 263, 146, + 261, 144, + 246, 144, + 238, 150, + 237, 159, + End, + 280, 377, + 280, 384, + 282, 384, + 287, 391, + 297, 391, + 302, 387, + 312, 372, + 322, 358, + 329, 343, + 335, 329, + 338, 319, + 342, 305, + 343, 298, + 345, 289, + 346, 281, + 347, 270, + 343, 270, + 341, 277, + 336, 291, + 331, 304, + 324, 318, + 316, 332, + 307, 346, + 296, 360, + 284, 375, + 280, 377, + End, + 286, 443, + 288, 449, + 301, 450, + 305, 446, + 305, 433, + 299, 426, + 294, 426, + 292, 427, + 287, 432, + 286, 443, + End, + 370, 61, + 370, 64, + 376, 64, + 391, 64, + 406, 65, + 406, 66, + 415, 67, + 430, 68, + 445, 68, + 448, 67, + 449, 59, + 434, 59, + 419, 59, + 404, 59, + 404, 58, + 402, 58, + 387, 58, + 386, 60, + 377, 60, + 370, 61, + End, End +}; +short wrook[] = /* V013 */ +{ + 93, 34, + 93, 97, + 94, 100, + 99, 105, + 110, 120, + 113, 132, + 117, 145, + 124, 151, + 126, 153, + 132, 160, + 146, 172, + 146, 319, + 145, 322, + 136, 332, + 123, 347, + 109, 360, + 107, 366, + 107, 441, + 115, 441, + 130, 441, + 137, 441, + 145, 441, + 160, 441, + 175, 441, + 175, 440, + 177, 433, + 181, 420, + 184, 414, + 196, 413, + 196, 414, + 198, 415, + 200, 422, + 205, 435, + 209, 448, + 217, 447, + 232, 447, + 247, 447, + 262, 447, + 277, 447, + 292, 447, + 294, 443, + 300, 428, + 307, 414, + 319, 414, + 322, 415, + 327, 428, + 333, 442, + 337, 442, + 352, 442, + 367, 442, + 382, 442, + 397, 442, + 397, 364, + 396, 360, + 395, 359, + 381, 344, + 375, 339, + 366, 328, + 362, 326, + 362, 223, + 363, 223, + 363, 178, + 366, 174, + 378, 160, + 391, 145, + 393, 137, + 399, 123, + 411, 109, + 421, 94, + 421, 79, + 422, 64, + 422, 34, + 408, 34, + 393, 34, + 378, 34, + 363, 34, + 348, 34, + 333, 34, + 318, 34, + 303, 34, + 288, 34, + 273, 34, + 258, 34, + 243, 34, + 228, 34, + 213, 34, + 198, 34, + 183, 34, + 168, 34, + 153, 34, + 138, 34, + 123, 34, + 108, 34, + 107, 34, + 93, 34, + End, + 124, 65, + 124, 84, + 127, 91, + 137, 104, + 140, 118, + 144, 130, + 155, 140, + 165, 147, + 166, 150, + 181, 150, + 196, 150, + 211, 150, + 226, 150, + 241, 150, + 256, 150, + 271, 150, + 286, 150, + 301, 150, + 316, 150, + 331, 150, + 346, 150, + 351, 143, + 366, 129, + 368, 122, + 370, 117, + 373, 106, + 375, 103, + 387, 88, + 388, 83, + 388, 68, + 385, 65, + 379, 65, + 364, 65, + 349, 65, + 334, 65, + 319, 65, + 304, 65, + 289, 65, + 274, 65, + 259, 65, + 244, 65, + 229, 65, + 214, 65, + 199, 65, + 184, 65, + 169, 65, + 154, 65, + 139, 65, + 124, 65, + End, + 137, 382, + 137, 412, + 138, 412, + 153, 412, + 155, 409, + 159, 394, + 163, 382, + 173, 382, + 188, 382, + 203, 382, + 218, 382, + 220, 389, + 225, 402, + 230, 416, + 242, 416, + 257, 416, + 272, 416, + 275, 411, + 281, 396, + 287, 383, + 298, 382, + 313, 382, + 328, 382, + 343, 382, + 346, 386, + 350, 400, + 354, 412, + 367, 412, + 367, 373, + 362, 368, + 361, 368, + 356, 361, + 350, 357, + 340, 345, + 326, 344, + 311, 344, + 311, 343, + 303, 343, + 288, 343, + 273, 343, + 258, 343, + 243, 343, + 228, 343, + 213, 343, + 198, 343, + 183, 343, + 176, 343, + 168, 343, + 164, 345, + 151, 359, + 138, 373, + 137, 382, + End, + 176, 193, + 176, 313, + 184, 313, + 199, 313, + 214, 313, + 229, 313, + 244, 313, + 259, 313, + 274, 313, + 289, 313, + 304, 313, + 319, 313, + 334, 313, + 334, 182, + 331, 182, + 331, 181, + 329, 181, + 314, 181, + 299, 181, + 284, 181, + 269, 181, + 254, 181, + 239, 181, + 224, 181, + 209, 181, + 194, 181, + 179, 181, + 177, 183, + 176, 193, + End, End +}; +short wqueen[] = /* V014 */ +{ + 28, 326, + 32, 338, + 42, 348, + 48, 348, + 49, 348, + 63, 348, + 69, 346, + 80, 338, + 88, 323, + 89, 315, + 89, 300, + 93, 299, + 96, 296, + 99, 296, + 104, 293, + 110, 291, + 113, 288, + 114, 288, + 119, 287, + 121, 285, + 127, 283, + 130, 281, + 136, 279, + 141, 276, + 150, 274, + 150, 275, + 153, 287, + 156, 301, + 158, 312, + 160, 322, + 163, 336, + 165, 347, + 168, 362, + 169, 372, + 158, 380, + 149, 395, + 147, 403, + 147, 418, + 148, 423, + 151, 434, + 159, 444, + 165, 447, + 167, 450, + 172, 450, + 178, 450, + 193, 450, + 200, 446, + 210, 436, + 217, 422, + 218, 415, + 218, 400, + 215, 389, + 211, 383, + 210, 378, + 212, 374, + 219, 360, + 227, 346, + 234, 332, + 242, 317, + 249, 304, + 254, 304, + 257, 309, + 260, 315, + 267, 328, + 273, 341, + 276, 345, + 283, 360, + 291, 374, + 293, 382, + 288, 394, + 287, 403, + 287, 418, + 288, 423, + 290, 429, + 298, 442, + 311, 451, + 320, 451, + 334, 451, + 335, 451, + 343, 447, + 351, 439, + 357, 427, + 358, 417, + 358, 402, + 354, 390, + 343, 376, + 335, 372, + 334, 367, + 335, 362, + 338, 350, + 341, 336, + 344, 323, + 347, 311, + 350, 299, + 353, 287, + 356, 275, + 360, 274, + 374, 283, + 387, 292, + 401, 301, + 416, 311, + 416, 323, + 420, 335, + 429, 346, + 437, 350, + 438, 351, + 444, 352, + 459, 352, + 463, 351, + 469, 347, + 476, 335, + 477, 320, + 475, 312, + 468, 300, + 459, 293, + 451, 290, + 450, 289, + 440, 288, + 438, 287, + 435, 280, + 430, 267, + 427, 256, + 422, 243, + 417, 228, + 412, 213, + 407, 198, + 403, 185, + 402, 176, + 401, 165, + 400, 150, + 399, 138, + 398, 124, + 397, 109, + 396, 94, + 395, 92, + 395, 77, + 394, 70, + 393, 68, + 378, 58, + 374, 57, + 372, 55, + 366, 53, + 362, 51, + 355, 49, + 351, 47, + 339, 44, + 338, 43, + 334, 42, + 322, 40, + 321, 38, + 314, 38, + 306, 37, + 293, 36, + 293, 35, + 287, 34, + 286, 34, + 271, 34, + 256, 34, + 241, 34, + 226, 34, + 226, 35, + 211, 35, + 211, 36, + 202, 37, + 195, 38, + 186, 39, + 186, 40, + 179, 41, + 169, 43, + 167, 44, + 154, 47, + 154, 48, + 147, 49, + 143, 51, + 142, 52, + 136, 54, + 133, 56, + 130, 57, + 123, 62, + 122, 65, + 120, 78, + 118, 91, + 117, 100, + 116, 105, + 115, 114, + 113, 125, + 112, 134, + 111, 141, + 109, 154, + 107, 169, + 106, 173, + 105, 181, + 104, 186, + 102, 192, + 97, 204, + 91, 219, + 85, 232, + 79, 247, + 72, 262, + 70, 265, + 65, 279, + 61, 284, + 58, 286, + 50, 288, + 47, 290, + 43, 292, + 34, 301, + 29, 313, + 28, 326, + End, + 49, 314, + 49, 325, + 64, 325, + 68, 320, + 68, 312, + 64, 307, + 58, 307, + 56, 308, + 49, 314, + End, + 113, 252, + 121, 252, + 121, 251, + 132, 246, + 140, 242, + 153, 235, + 165, 229, + 164, 226, + 156, 224, + 154, 223, + 143, 220, + 142, 219, + 138, 217, + 136, 217, + 136, 216, + 128, 216, + 124, 225, + 118, 238, + 113, 252, + End, + 138, 176, + 138, 183, + 145, 185, + 145, 186, + 157, 189, + 157, 190, + 168, 192, + 172, 193, + 173, 194, + 187, 196, + 194, 197, + 195, 198, + 206, 199, + 219, 200, + 231, 200, + 234, 200, + 249, 200, + 264, 200, + 279, 200, + 294, 200, + 309, 200, + 311, 199, + 320, 198, + 320, 197, + 335, 195, + 340, 195, + 341, 193, + 347, 191, + 352, 191, + 356, 190, + 356, 189, + 367, 186, + 373, 183, + 373, 175, + 369, 174, + 369, 173, + 359, 172, + 354, 170, + 347, 163, + 347, 148, + 356, 140, + 362, 138, + 362, 137, + 369, 135, + 369, 122, + 358, 125, + 354, 127, + 343, 129, + 343, 130, + 330, 132, + 324, 133, + 324, 134, + 315, 135, + 306, 136, + 297, 137, + 296, 138, + 281, 138, + 266, 138, + 251, 138, + 236, 138, + 221, 138, + 218, 137, + 204, 136, + 196, 135, + 189, 134, + 189, 133, + 176, 131, + 172, 130, + 171, 129, + 157, 126, + 157, 125, + 153, 124, + 148, 124, + 146, 124, + 145, 127, + 145, 135, + 151, 137, + 160, 143, + 164, 148, + 165, 152, + 164, 163, + 159, 168, + 154, 171, + 148, 172, + 145, 172, + 140, 173, + 138, 176, + End, + 148, 83, + 148, 85, + 151, 88, + 162, 91, + 162, 92, + 176, 95, + 178, 96, + 182, 97, + 196, 99, + 196, 100, + 204, 101, + 219, 102, + 234, 102, + 249, 102, + 264, 102, + 279, 102, + 294, 102, + 303, 101, + 312, 100, + 312, 99, + 319, 98, + 333, 96, + 333, 95, + 338, 94, + 349, 92, + 349, 91, + 359, 88, + 358, 85, + 356, 85, + 350, 82, + 344, 81, + 340, 79, + 327, 76, + 325, 75, + 313, 73, + 304, 72, + 303, 70, + 293, 70, + 278, 69, + 278, 68, + 277, 68, + 262, 68, + 247, 68, + 232, 68, + 217, 68, + 217, 69, + 205, 70, + 195, 71, + 194, 72, + 187, 73, + 174, 75, + 173, 76, + 159, 79, + 158, 80, + 148, 83, + End, + 172, 404, + 172, 419, + 174, 423, + 189, 423, + 193, 418, + 194, 406, + 193, 402, + 188, 397, + 180, 397, + 174, 402, + 172, 404, + End, + 174, 230, + 176, 239, + 179, 254, + 182, 267, + 185, 282, + 188, 295, + 191, 309, + 194, 323, + 195, 326, + 201, 326, + 202, 324, + 210, 310, + 218, 295, + 226, 280, + 234, 266, + 241, 252, + 248, 238, + 247, 236, + 233, 235, + 231, 234, + 216, 234, + 202, 233, + 201, 231, + 193, 231, + 184, 230, + 184, 229, + 176, 229, + 174, 230, + End, + 231, 164, + 231, 178, + 236, 185, + 242, 188, + 248, 189, + 263, 189, + 264, 187, + 268, 187, + 277, 179, + 277, 167, + 276, 163, + 267, 156, + 260, 154, + 260, 153, + 250, 153, + 248, 154, + 241, 156, + 231, 164, + End, + 257, 237, + 257, 240, + 262, 250, + 269, 264, + 277, 279, + 285, 294, + 292, 308, + 300, 323, + 304, 332, + 310, 332, + 313, 320, + 316, 307, + 319, 293, + 322, 280, + 325, 266, + 326, 264, + 328, 253, + 331, 241, + 332, 231, + 323, 231, + 323, 232, + 314, 233, + 300, 234, + 297, 236, + 282, 236, + 272, 237, + 257, 237, + End, + 311, 417, + 315, 424, + 329, 424, + 333, 422, + 333, 408, + 332, 405, + 326, 398, + 318, 398, + 312, 403, + 311, 417, + End, + 350, 226, + 350, 227, + 351, 229, + 355, 231, + 363, 238, + 371, 242, + 385, 252, + 394, 252, + 391, 245, + 386, 231, + 381, 217, + 373, 217, + 373, 218, + 366, 220, + 365, 221, + 354, 224, + 353, 225, + 350, 226, + End, + 437, 314, + 437, 325, + 442, 332, + 454, 332, + 457, 329, + 457, 319, + 450, 311, + 441, 311, + 437, 314, + End, End +}; +short wking[] = /* V015 */ +{ + 32, 291, + 32, 321, + 34, 331, + 38, 345, + 46, 359, + 57, 373, + 61, 375, + 64, 378, + 66, 381, + 76, 387, + 81, 389, + 84, 391, + 94, 394, + 94, 395, + 98, 396, + 108, 397, + 123, 397, + 138, 397, + 152, 395, + 153, 394, + 165, 391, + 166, 390, + 175, 387, + 176, 385, + 179, 385, + 185, 381, + 193, 379, + 193, 465, + 199, 465, + 214, 465, + 224, 465, + 229, 465, + 234, 465, + 244, 465, + 259, 465, + 274, 465, + 289, 465, + 304, 465, + 319, 465, + 319, 403, + 320, 403, + 320, 383, + 328, 385, + 330, 387, + 336, 389, + 339, 391, + 346, 393, + 350, 395, + 363, 398, + 364, 400, + 378, 400, + 393, 400, + 408, 400, + 415, 399, + 416, 398, + 428, 395, + 429, 394, + 440, 389, + 451, 381, + 465, 367, + 474, 353, + 479, 340, + 483, 325, + 483, 295, + 482, 289, + 479, 276, + 474, 262, + 467, 247, + 457, 232, + 445, 217, + 431, 203, + 424, 198, + 422, 195, + 413, 190, + 410, 187, + 408, 179, + 405, 164, + 403, 154, + 401, 143, + 399, 132, + 397, 122, + 395, 111, + 393, 100, + 391, 87, + 388, 75, + 386, 71, + 371, 61, + 366, 59, + 364, 57, + 358, 55, + 355, 53, + 345, 50, + 344, 49, + 332, 46, + 332, 45, + 328, 44, + 315, 42, + 315, 41, + 309, 40, + 300, 39, + 289, 38, + 289, 37, + 282, 36, + 267, 36, + 252, 36, + 237, 36, + 234, 37, + 219, 37, + 219, 38, + 208, 39, + 194, 41, + 193, 42, + 188, 43, + 177, 45, + 176, 46, + 164, 49, + 164, 50, + 154, 53, + 154, 54, + 150, 55, + 139, 61, + 124, 72, + 121, 82, + 119, 91, + 116, 105, + 113, 119, + 110, 131, + 108, 142, + 106, 149, + 103, 162, + 100, 176, + 97, 188, + 89, 194, + 75, 206, + 62, 221, + 52, 235, + 44, 250, + 38, 265, + 34, 279, + 32, 291, + End, + 61, 302, + 61, 317, + 62, 323, + 68, 336, + 78, 351, + 90, 360, + 105, 367, + 113, 368, + 128, 368, + 143, 368, + 153, 366, + 154, 365, + 161, 363, + 164, 361, + 171, 358, + 186, 348, + 199, 336, + 211, 321, + 220, 306, + 226, 291, + 229, 278, + 229, 248, + 228, 244, + 226, 244, + 212, 243, + 211, 242, + 203, 241, + 193, 240, + 185, 239, + 185, 238, + 179, 237, + 167, 235, + 166, 234, + 153, 231, + 151, 230, + 140, 227, + 139, 226, + 133, 224, + 132, 224, + 129, 221, + 126, 221, + 119, 217, + 117, 215, + 114, 215, + 107, 220, + 93, 232, + 81, 247, + 72, 262, + 66, 277, + 62, 292, + 61, 302, + End, + 133, 182, + 133, 187, + 138, 190, + 146, 192, + 149, 194, + 158, 196, + 158, 197, + 169, 199, + 174, 200, + 174, 201, + 188, 203, + 195, 204, + 195, 205, + 205, 206, + 213, 207, + 222, 207, + 228, 207, + 228, 209, + 243, 209, + 258, 209, + 273, 209, + 288, 209, + 297, 208, + 310, 207, + 321, 206, + 328, 206, + 329, 204, + 336, 203, + 344, 202, + 348, 201, + 349, 200, + 363, 197, + 363, 196, + 372, 194, + 376, 191, + 375, 182, + 373, 180, + 358, 180, + 349, 177, + 340, 171, + 336, 162, + 337, 148, + 344, 139, + 357, 131, + 364, 129, + 363, 118, + 363, 117, + 350, 119, + 346, 120, + 345, 121, + 333, 123, + 328, 124, + 328, 125, + 320, 126, + 312, 127, + 303, 127, + 302, 129, + 287, 129, + 272, 129, + 257, 129, + 242, 129, + 227, 129, + 215, 128, + 205, 127, + 191, 125, + 189, 124, + 177, 122, + 172, 121, + 171, 120, + 161, 118, + 161, 117, + 156, 116, + 149, 116, + 147, 120, + 147, 126, + 151, 128, + 164, 135, + 171, 145, + 172, 150, + 171, 163, + 166, 170, + 160, 174, + 150, 176, + 150, 177, + 147, 177, + 135, 177, + 133, 182, + End, + 161, 83, + 163, 85, + 166, 86, + 177, 88, + 177, 89, + 181, 90, + 196, 92, + 196, 93, + 203, 94, + 211, 95, + 223, 96, + 225, 97, + 240, 97, + 255, 97, + 270, 97, + 285, 97, + 300, 97, + 300, 96, + 311, 95, + 319, 94, + 327, 93, + 328, 91, + 332, 91, + 344, 89, + 344, 88, + 349, 87, + 353, 86, + 353, 83, + 347, 82, + 344, 80, + 340, 79, + 329, 77, + 329, 76, + 324, 75, + 309, 73, + 308, 71, + 297, 71, + 283, 70, + 283, 69, + 281, 69, + 266, 69, + 251, 69, + 236, 69, + 221, 69, + 221, 70, + 210, 71, + 199, 72, + 199, 73, + 193, 74, + 184, 75, + 179, 76, + 177, 77, + 163, 80, + 161, 83, + End, + 222, 171, + 225, 182, + 233, 189, + 240, 192, + 254, 193, + 269, 193, + 270, 192, + 273, 191, + 279, 187, + 287, 178, + 287, 164, + 286, 161, + 281, 154, + 274, 150, + 270, 147, + 264, 146, + 264, 145, + 261, 145, + 246, 145, + 246, 146, + 241, 147, + 231, 152, + 223, 163, + 222, 171, + End, + 224, 379, + 224, 422, + 228, 421, + 232, 418, + 246, 404, + 247, 399, + 242, 394, + 235, 386, + 228, 379, + 224, 379, + End, + 234, 436, + 238, 436, + 253, 436, + 268, 436, + 283, 436, + 274, 426, + 268, 419, + 260, 411, + 256, 411, + 250, 418, + 235, 432, + 234, 436, + End, + 235, 366, + 235, 370, + 238, 373, + 251, 388, + 261, 388, + 264, 386, + 278, 372, + 279, 367, + 271, 367, + 271, 366, + 265, 366, + 250, 366, + 239, 366, + 235, 366, + End, + 239, 333, + 240, 333, + 255, 333, + 270, 333, + 270, 331, + 263, 318, + 257, 303, + 252, 303, + 252, 304, + 247, 314, + 240, 328, + 239, 333, + End, + 268, 399, + 268, 403, + 270, 406, + 283, 420, + 290, 420, + 290, 382, + 285, 382, + 280, 387, + 275, 393, + 268, 399, + End, + 280, 249, + 280, 264, + 281, 271, + 283, 280, + 286, 293, + 290, 305, + 295, 313, + 300, 323, + 309, 334, + 322, 348, + 337, 359, + 346, 363, + 352, 366, + 362, 369, + 362, 371, + 376, 371, + 391, 371, + 406, 371, + 410, 370, + 412, 369, + 421, 366, + 421, 365, + 426, 363, + 440, 351, + 449, 336, + 454, 322, + 454, 307, + 453, 296, + 451, 287, + 447, 274, + 440, 261, + 429, 246, + 416, 232, + 401, 219, + 395, 219, + 388, 223, + 382, 225, + 379, 227, + 368, 230, + 368, 231, + 355, 234, + 354, 235, + 350, 236, + 336, 238, + 336, 239, + 330, 240, + 321, 241, + 309, 242, + 308, 243, + 296, 244, + 281, 245, + 280, 249, + End, End +}; +short spawn[] = /* V017 */ +{ + 499, 4, + 499, 6, + 504, 13, + 512, 13, + 511, 6, + 510, 4, + 499, 4, + End, + 286, 1, + 286, 3, + 296, 14, + 311, 14, + 309, 12, + 299, 1, + 286, 1, + End, + 218, 0, + 218, 3, + 227, 14, + 242, 14, + 241, 12, + 232, 2, + 228, 1, + 228, 0, + 218, 0, + End, + 359, 3, + 360, 4, + 369, 15, + 384, 15, + 383, 13, + 374, 3, + 367, 2, + 367, 1, + 362, 1, + 359, 3, + End, + 150, 0, + 151, 3, + 162, 15, + 176, 16, + 176, 14, + 163, 0, + 150, 0, + End, + 80, 0, + 81, 3, + 93, 15, + 107, 16, + 107, 14, + 94, 0, + 80, 0, + End, + 435, 4, + 441, 11, + 455, 26, + 469, 41, + 483, 55, + 497, 70, + 510, 84, + 517, 84, + 517, 78, + 515, 75, + 501, 60, + 487, 45, + 473, 30, + 460, 16, + 446, 2, + 436, 2, + 435, 4, + End, + 425, 67, + 427, 70, + 441, 84, + 455, 99, + 469, 113, + 483, 128, + 497, 142, + 510, 156, + 517, 156, + 517, 150, + 513, 144, + 499, 130, + 485, 116, + 471, 101, + 458, 87, + 444, 73, + 431, 58, + 427, 58, + 426, 60, + 425, 67, + End, + 19, 0, + 19, 7, + 30, 18, + 44, 33, + 58, 47, + 72, 62, + 86, 76, + 100, 91, + 114, 105, + 128, 120, + 141, 134, + 155, 148, + 169, 163, + 183, 178, + 189, 179, + 188, 170, + 186, 166, + 172, 151, + 158, 137, + 144, 122, + 131, 108, + 117, 94, + 107, 82, + 93, 69, + 80, 54, + 70, 45, + 56, 30, + 42, 15, + 28, 0, + 19, 0, + End, + 397, 104, + 397, 108, + 408, 119, + 422, 134, + 435, 148, + 449, 162, + 462, 176, + 476, 190, + 490, 205, + 505, 219, + 511, 227, + 519, 227, + 518, 220, + 515, 216, + 501, 202, + 488, 188, + 474, 175, + 460, 160, + 446, 145, + 433, 131, + 419, 117, + 406, 102, + 400, 102, + 397, 104, + End, + 22, 68, + 22, 79, + 24, 82, + 38, 97, + 53, 111, + 67, 126, + 81, 140, + 94, 154, + 108, 168, + 121, 182, + 135, 196, + 149, 211, + 162, 225, + 176, 239, + 189, 254, + 204, 254, + 190, 240, + 176, 225, + 162, 210, + 148, 195, + 134, 181, + 120, 166, + 106, 151, + 100, 146, + 88, 132, + 77, 122, + 67, 110, + 54, 98, + 40, 83, + 26, 68, + 22, 68, + End, + 331, 247, + 331, 256, + 334, 260, + 348, 260, + 348, 259, + 337, 247, + 331, 247, + End, + 25, 141, + 25, 151, + 34, 161, + 48, 175, + 62, 190, + 76, 204, + 89, 218, + 102, 230, + 116, 245, + 129, 259, + 143, 259, + 142, 258, + 128, 243, + 114, 229, + 100, 214, + 86, 199, + 72, 185, + 58, 171, + 44, 156, + 30, 141, + 25, 141, + End, + 355, 129, + 355, 131, + 363, 140, + 377, 155, + 390, 169, + 404, 183, + 417, 197, + 431, 211, + 444, 225, + 458, 239, + 471, 253, + 485, 267, + 498, 281, + 506, 288, + 516, 300, + 524, 300, + 523, 291, + 520, 289, + 506, 274, + 492, 260, + 477, 245, + 463, 230, + 449, 216, + 435, 201, + 421, 187, + 407, 172, + 393, 157, + 379, 142, + 365, 127, + 360, 127, + 360, 128, + 355, 129, + End, + 356, 203, + 364, 212, + 378, 226, + 392, 241, + 406, 256, + 420, 270, + 434, 285, + 448, 299, + 462, 313, + 476, 328, + 490, 342, + 504, 356, + 518, 370, + 524, 371, + 524, 365, + 522, 360, + 507, 346, + 493, 332, + 479, 317, + 470, 309, + 457, 294, + 443, 281, + 434, 270, + 419, 256, + 405, 241, + 391, 226, + 377, 211, + 363, 196, + 358, 196, + 356, 203, + End, + 27, 212, + 28, 223, + 31, 226, + 45, 241, + 59, 255, + 72, 269, + 86, 283, + 99, 297, + 113, 311, + 127, 325, + 141, 340, + 155, 355, + 169, 369, + 183, 384, + 197, 399, + 210, 413, + 217, 413, + 215, 405, + 213, 402, + 200, 388, + 187, 373, + 178, 365, + 164, 350, + 150, 335, + 136, 321, + 122, 306, + 108, 291, + 101, 285, + 88, 270, + 74, 256, + 60, 242, + 46, 227, + 32, 212, + 27, 212, + End, + 409, 324, + 409, 329, + 422, 342, + 435, 356, + 449, 370, + 463, 384, + 477, 399, + 491, 412, + 505, 427, + 519, 441, + 526, 442, + 526, 435, + 515, 423, + 500, 409, + 486, 394, + 472, 380, + 458, 366, + 444, 352, + 430, 337, + 416, 322, + 411, 322, + 409, 324, + End, + 24, 499, + 24, 504, + 34, 504, + 30, 499, + 24, 499, + End, + 28, 427, + 28, 437, + 40, 448, + 54, 463, + 67, 477, + 81, 491, + 94, 505, + 107, 505, + 106, 504, + 99, 497, + 85, 482, + 72, 468, + 58, 454, + 44, 439, + 33, 427, + 28, 427, + End, + 31, 284, + 32, 294, + 45, 307, + 59, 321, + 65, 329, + 72, 334, + 81, 345, + 95, 358, + 109, 373, + 123, 388, + 137, 403, + 151, 417, + 165, 432, + 179, 446, + 193, 461, + 207, 476, + 221, 491, + 235, 506, + 248, 507, + 247, 506, + 241, 499, + 228, 485, + 214, 471, + 200, 456, + 186, 441, + 172, 426, + 159, 412, + 145, 398, + 131, 383, + 118, 369, + 104, 355, + 90, 340, + 77, 326, + 64, 314, + 50, 299, + 36, 284, + 31, 284, + End, + 31, 355, + 32, 364, + 33, 366, + 47, 380, + 61, 395, + 75, 409, + 89, 424, + 103, 438, + 117, 452, + 131, 467, + 145, 482, + 160, 497, + 168, 507, + 180, 507, + 180, 506, + 174, 500, + 160, 485, + 147, 471, + 133, 457, + 119, 442, + 106, 428, + 92, 414, + 78, 399, + 64, 385, + 50, 370, + 36, 355, + 31, 355, + End, + 260, 454, + 261, 456, + 270, 466, + 283, 480, + 297, 494, + 309, 508, + 322, 508, + 322, 507, + 321, 507, + 312, 497, + 298, 483, + 285, 468, + 270, 454, + 260, 454, + End, + 379, 360, + 380, 362, + 386, 369, + 400, 383, + 414, 398, + 428, 412, + 442, 427, + 456, 441, + 470, 455, + 484, 469, + 497, 483, + 512, 497, + 524, 510, + 534, 510, + 534, 507, + 528, 501, + 514, 487, + 500, 472, + 485, 458, + 477, 448, + 467, 440, + 456, 427, + 441, 413, + 427, 398, + 414, 384, + 401, 372, + 389, 358, + 382, 358, + 379, 360, + End, + 349, 403, + 354, 407, + 368, 422, + 382, 436, + 396, 451, + 411, 466, + 425, 481, + 440, 495, + 454, 510, + 466, 510, + 466, 508, + 459, 503, + 454, 496, + 439, 482, + 425, 467, + 411, 453, + 397, 438, + 383, 424, + 369, 409, + 355, 394, + 351, 394, + 351, 395, + 349, 403, + End, + 325, 444, + 325, 447, + 330, 453, + 343, 467, + 357, 481, + 370, 495, + 384, 509, + 396, 510, + 396, 508, + 389, 501, + 375, 487, + 361, 472, + 347, 457, + 333, 442, + 328, 442, + 325, 444, + End, End +}; +short sknight[] = /* V018 */ +{ + 494, 2, + 494, 3, + 500, 10, + 508, 10, + 507, 1, + 503, 1, + 503, 0, + 497, 0, + 494, 2, + End, + 423, 0, + 423, 2, + 434, 14, + 449, 14, + 448, 12, + 436, 0, + 423, 0, + End, + 353, 0, + 353, 1, + 364, 14, + 379, 14, + 378, 12, + 367, 0, + 353, 0, + End, + 283, 0, + 286, 5, + 296, 14, + 311, 14, + 309, 12, + 298, 0, + 283, 0, + End, + 214, 0, + 215, 3, + 226, 14, + 241, 14, + 228, 0, + 214, 0, + End, + 146, 0, + 146, 2, + 158, 15, + 173, 16, + 172, 13, + 159, 0, + 146, 0, + End, + 77, 0, + 77, 3, + 86, 13, + 96, 22, + 105, 33, + 119, 46, + 132, 61, + 138, 61, + 138, 51, + 131, 43, + 117, 28, + 104, 14, + 89, 0, + 77, 0, + End, + 484, 48, + 485, 59, + 493, 68, + 506, 82, + 513, 82, + 513, 73, + 512, 70, + 502, 62, + 489, 48, + 484, 48, + End, + 14, 69, + 14, 80, + 15, 83, + 30, 97, + 44, 112, + 59, 126, + 61, 130, + 74, 130, + 74, 126, + 73, 126, + 60, 111, + 47, 99, + 33, 84, + 19, 69, + 14, 69, + End, + 14, 0, + 14, 8, + 23, 18, + 37, 32, + 51, 47, + 66, 61, + 80, 76, + 94, 90, + 108, 105, + 122, 119, + 135, 133, + 150, 133, + 147, 129, + 133, 115, + 120, 101, + 106, 87, + 92, 72, + 79, 58, + 65, 44, + 52, 30, + 38, 16, + 25, 2, + 23, 2, + 21, 0, + 14, 0, + End, + 485, 118, + 486, 129, + 495, 139, + 509, 153, + 516, 154, + 515, 144, + 505, 133, + 491, 118, + 485, 118, + End, + 17, 143, + 18, 153, + 19, 156, + 26, 161, + 31, 168, + 38, 173, + 43, 180, + 52, 180, + 52, 174, + 51, 173, + 37, 158, + 23, 143, + 17, 143, + End, + 482, 185, + 482, 196, + 496, 210, + 510, 224, + 517, 225, + 517, 217, + 515, 214, + 501, 200, + 487, 185, + 482, 185, + End, + 21, 215, + 21, 225, + 33, 237, + 47, 252, + 53, 252, + 51, 248, + 48, 239, + 40, 230, + 26, 215, + 21, 215, + End, + 470, 244, + 470, 253, + 481, 265, + 490, 273, + 496, 281, + 503, 286, + 512, 297, + 519, 297, + 519, 291, + 517, 287, + 503, 272, + 488, 258, + 476, 244, + 470, 244, + End, + 454, 299, + 454, 307, + 457, 311, + 471, 325, + 485, 339, + 499, 353, + 513, 368, + 520, 368, + 519, 360, + 517, 357, + 503, 343, + 489, 329, + 475, 314, + 461, 299, + 454, 299, + End, + 23, 286, + 24, 297, + 28, 300, + 42, 315, + 56, 328, + 70, 343, + 85, 357, + 99, 371, + 113, 385, + 126, 399, + 133, 399, + 134, 393, + 127, 384, + 113, 371, + 99, 356, + 85, 342, + 70, 328, + 58, 315, + 43, 301, + 29, 286, + 23, 286, + End, + 430, 346, + 430, 351, + 444, 365, + 458, 380, + 472, 394, + 486, 409, + 500, 423, + 513, 437, + 521, 437, + 521, 433, + 520, 430, + 507, 416, + 493, 402, + 479, 387, + 465, 373, + 451, 359, + 438, 344, + 433, 344, + 430, 346, + End, + 27, 355, + 27, 365, + 30, 369, + 44, 383, + 58, 397, + 70, 408, + 84, 423, + 98, 437, + 111, 452, + 120, 460, + 134, 475, + 148, 490, + 162, 505, + 176, 506, + 170, 499, + 156, 485, + 142, 470, + 128, 455, + 114, 441, + 101, 427, + 87, 413, + 73, 398, + 59, 384, + 45, 370, + 31, 355, + 27, 355, + End, + 28, 427, + 28, 437, + 39, 448, + 53, 463, + 66, 477, + 80, 491, + 92, 505, + 106, 505, + 101, 500, + 87, 485, + 73, 470, + 60, 456, + 46, 442, + 32, 427, + 28, 427, + End, + 26, 499, + 26, 506, + 36, 505, + 31, 499, + 26, 499, + End, + 316, 442, + 317, 444, + 320, 448, + 334, 463, + 347, 477, + 361, 491, + 375, 506, + 389, 507, + 387, 505, + 381, 498, + 367, 483, + 353, 469, + 340, 454, + 326, 439, + 322, 439, + 321, 440, + 316, 442, + End, + 259, 452, + 259, 456, + 271, 469, + 284, 483, + 298, 497, + 306, 507, + 321, 507, + 320, 506, + 307, 492, + 294, 478, + 281, 464, + 267, 449, + 264, 449, + 259, 452, + End, + 220, 487, + 228, 495, + 238, 507, + 252, 507, + 251, 505, + 243, 496, + 229, 481, + 224, 481, + 221, 483, + 220, 487, + End, + 406, 389, + 419, 403, + 433, 417, + 447, 432, + 461, 446, + 474, 460, + 488, 474, + 501, 488, + 514, 500, + 520, 508, + 529, 508, + 529, 504, + 523, 498, + 509, 484, + 495, 469, + 481, 454, + 468, 440, + 454, 426, + 441, 412, + 427, 398, + 414, 383, + 409, 383, + 407, 384, + 406, 389, + End, + 369, 423, + 382, 436, + 396, 451, + 410, 465, + 423, 479, + 437, 493, + 451, 508, + 464, 509, + 461, 505, + 448, 491, + 434, 477, + 420, 462, + 406, 447, + 392, 432, + 378, 417, + 373, 417, + 370, 419, + 369, 423, + End, End +}; +short sbishop[] = /* V019 */ +{ + 498, 2, + 498, 4, + 503, 11, + 510, 11, + 510, 5, + 508, 2, + 498, 2, + End, + 77, 0, + 77, 2, + 87, 14, + 102, 14, + 101, 12, + 89, 0, + 77, 0, + End, + 429, 2, + 430, 3, + 439, 15, + 452, 15, + 452, 13, + 451, 11, + 443, 2, + 429, 2, + End, + 150, 0, + 151, 3, + 162, 15, + 176, 15, + 162, 0, + 150, 0, + End, + 362, 1, + 362, 3, + 374, 16, + 388, 16, + 374, 1, + 362, 1, + End, + 292, 1, + 297, 7, + 307, 19, + 322, 19, + 320, 16, + 306, 1, + 292, 1, + End, + 18, 0, + 18, 8, + 32, 23, + 41, 23, + 42, 18, + 39, 14, + 25, 0, + 18, 0, + End, + 226, 0, + 226, 2, + 227, 5, + 232, 9, + 245, 24, + 259, 39, + 268, 40, + 270, 38, + 270, 35, + 267, 31, + 253, 17, + 240, 2, + 238, 2, + 236, 0, + 226, 0, + End, + 510, 79, + 513, 83, + 520, 83, + 520, 76, + 515, 69, + 511, 69, + 511, 70, + 510, 79, + End, + 131, 116, + 132, 118, + 139, 126, + 152, 140, + 159, 140, + 158, 132, + 156, 129, + 142, 114, + 134, 114, + 134, 115, + 131, 116, + End, + 481, 116, + 481, 119, + 484, 122, + 497, 136, + 511, 150, + 514, 155, + 522, 155, + 522, 148, + 519, 144, + 505, 129, + 491, 114, + 485, 114, + 484, 116, + 481, 116, + End, + 26, 69, + 26, 80, + 39, 94, + 54, 108, + 68, 123, + 82, 137, + 96, 152, + 111, 166, + 125, 181, + 138, 195, + 145, 195, + 148, 191, + 142, 184, + 128, 170, + 114, 155, + 100, 141, + 86, 127, + 72, 112, + 58, 98, + 44, 84, + 30, 69, + 26, 69, + End, + 413, 116, + 413, 118, + 418, 125, + 432, 138, + 446, 153, + 460, 168, + 474, 183, + 489, 197, + 503, 212, + 517, 227, + 523, 228, + 523, 218, + 522, 217, + 508, 202, + 494, 189, + 481, 174, + 467, 161, + 454, 146, + 440, 133, + 427, 118, + 420, 117, + 420, 116, + 413, 116, + End, + 28, 141, + 28, 151, + 38, 161, + 52, 175, + 66, 190, + 81, 204, + 95, 219, + 109, 233, + 123, 248, + 130, 249, + 129, 240, + 117, 227, + 103, 213, + 89, 199, + 75, 184, + 61, 170, + 47, 156, + 33, 141, + 28, 141, + End, + 390, 153, + 390, 163, + 398, 171, + 411, 186, + 426, 200, + 438, 214, + 453, 228, + 467, 243, + 481, 257, + 494, 271, + 508, 285, + 519, 297, + 527, 297, + 526, 290, + 525, 288, + 521, 285, + 516, 278, + 501, 264, + 487, 249, + 479, 242, + 470, 231, + 456, 218, + 443, 203, + 429, 190, + 416, 175, + 407, 167, + 395, 153, + 390, 153, + End, + 30, 213, + 31, 222, + 37, 229, + 51, 243, + 65, 257, + 79, 271, + 93, 286, + 107, 300, + 120, 314, + 133, 326, + 144, 339, + 151, 339, + 148, 335, + 145, 326, + 135, 315, + 121, 301, + 107, 287, + 93, 272, + 79, 257, + 64, 243, + 50, 228, + 36, 213, + 30, 213, + End, + 416, 251, + 417, 260, + 418, 262, + 432, 276, + 446, 291, + 460, 306, + 475, 320, + 489, 335, + 503, 349, + 511, 356, + 522, 369, + 529, 369, + 529, 362, + 520, 352, + 506, 338, + 492, 324, + 478, 310, + 464, 295, + 450, 281, + 436, 266, + 422, 251, + 416, 251, + End, + 414, 319, + 414, 328, + 424, 339, + 438, 353, + 452, 368, + 466, 382, + 480, 396, + 494, 410, + 507, 424, + 514, 429, + 523, 440, + 530, 440, + 529, 433, + 525, 428, + 511, 414, + 497, 399, + 482, 385, + 468, 370, + 454, 356, + 440, 341, + 431, 333, + 419, 319, + 414, 319, + End, + 34, 283, + 34, 294, + 47, 308, + 62, 322, + 76, 337, + 90, 351, + 103, 365, + 108, 369, + 121, 384, + 135, 397, + 148, 412, + 161, 424, + 170, 435, + 183, 447, + 193, 459, + 200, 459, + 200, 457, + 198, 450, + 189, 441, + 176, 427, + 162, 413, + 149, 399, + 135, 385, + 121, 370, + 107, 355, + 93, 341, + 79, 326, + 65, 312, + 51, 298, + 37, 283, + 34, 283, + End, + 32, 364, + 42, 374, + 56, 388, + 70, 403, + 84, 417, + 98, 431, + 112, 446, + 126, 460, + 140, 475, + 154, 490, + 167, 504, + 180, 504, + 178, 503, + 173, 496, + 164, 488, + 150, 473, + 136, 458, + 122, 443, + 108, 429, + 94, 414, + 80, 399, + 65, 385, + 51, 370, + 37, 355, + 33, 355, + 32, 364, + End, + 31, 426, + 31, 435, + 43, 448, + 57, 462, + 70, 476, + 84, 490, + 97, 504, + 109, 504, + 109, 503, + 103, 497, + 89, 483, + 76, 468, + 62, 455, + 48, 440, + 35, 426, + 31, 426, + End, + 30, 499, + 30, 504, + 39, 504, + 35, 499, + 30, 499, + End, + 283, 474, + 288, 480, + 302, 494, + 312, 506, + 325, 506, + 324, 505, + 318, 498, + 304, 484, + 291, 469, + 285, 469, + 283, 474, + End, + 230, 487, + 230, 488, + 232, 491, + 244, 505, + 256, 505, + 256, 504, + 255, 504, + 250, 497, + 240, 489, + 234, 488, + 234, 487, + 230, 487, + End, + 360, 479, + 367, 487, + 381, 501, + 385, 507, + 399, 507, + 396, 504, + 382, 489, + 368, 474, + 361, 474, + 361, 475, + 360, 479, + End, + 404, 379, + 411, 385, + 420, 396, + 435, 410, + 449, 425, + 463, 439, + 477, 454, + 492, 468, + 505, 482, + 520, 496, + 530, 508, + 540, 508, + 540, 504, + 531, 495, + 517, 480, + 508, 472, + 494, 457, + 480, 443, + 466, 429, + 452, 414, + 438, 400, + 424, 386, + 411, 371, + 407, 371, + 405, 373, + 404, 379, + End, + 375, 419, + 376, 421, + 390, 435, + 404, 450, + 418, 464, + 432, 479, + 447, 494, + 460, 508, + 473, 508, + 467, 502, + 453, 487, + 439, 473, + 425, 458, + 411, 444, + 397, 429, + 383, 414, + 376, 414, + 376, 415, + 375, 419, + End, End +}; +short srook[] = /* V020 */ +{ + 497, 1, + 497, 3, + 502, 10, + 510, 10, + 509, 3, + 508, 1, + 497, 1, + End, + 213, 0, + 213, 2, + 226, 17, + 241, 17, + 240, 15, + 226, 0, + 213, 0, + End, + 356, 2, + 357, 4, + 370, 18, + 385, 18, + 382, 14, + 368, 0, + 357, 0, + 356, 2, + End, + 286, 0, + 288, 4, + 300, 18, + 315, 18, + 313, 15, + 299, 0, + 286, 0, + End, + 146, 0, + 149, 5, + 163, 20, + 178, 20, + 174, 15, + 160, 0, + 146, 0, + End, + 78, 0, + 78, 2, + 80, 4, + 94, 19, + 109, 19, + 105, 15, + 91, 0, + 78, 0, + End, + 13, 2, + 13, 7, + 14, 10, + 28, 24, + 42, 38, + 56, 53, + 62, 58, + 75, 73, + 82, 73, + 80, 62, + 76, 57, + 62, 42, + 48, 28, + 34, 14, + 20, 0, + 15, 0, + 13, 2, + End, + 433, 1, + 433, 2, + 440, 10, + 454, 25, + 468, 39, + 482, 54, + 496, 68, + 509, 82, + 518, 82, + 517, 73, + 504, 59, + 490, 45, + 476, 31, + 462, 16, + 448, 1, + 433, 1, + End, + 445, 78, + 445, 87, + 446, 90, + 454, 97, + 468, 112, + 482, 126, + 496, 140, + 510, 155, + 517, 155, + 516, 145, + 508, 137, + 494, 122, + 479, 108, + 465, 93, + 451, 78, + 445, 78, + End, + 17, 69, + 18, 80, + 22, 86, + 36, 99, + 50, 114, + 64, 128, + 78, 142, + 92, 157, + 106, 171, + 120, 185, + 133, 199, + 139, 200, + 138, 189, + 134, 183, + 120, 169, + 106, 155, + 92, 141, + 78, 127, + 64, 112, + 50, 98, + 36, 84, + 22, 69, + 17, 69, + End, + 425, 137, + 428, 141, + 442, 156, + 456, 170, + 470, 184, + 484, 198, + 498, 212, + 512, 226, + 519, 227, + 519, 220, + 518, 217, + 505, 204, + 491, 189, + 476, 175, + 462, 161, + 448, 146, + 434, 131, + 429, 131, + 426, 134, + 425, 137, + End, + 21, 143, + 21, 153, + 28, 161, + 42, 175, + 56, 190, + 71, 204, + 85, 219, + 99, 233, + 113, 248, + 127, 262, + 131, 265, + 134, 271, + 143, 271, + 142, 263, + 137, 256, + 123, 242, + 109, 228, + 95, 213, + 81, 200, + 67, 185, + 53, 171, + 39, 157, + 26, 143, + 21, 143, + End, + 399, 179, + 401, 183, + 416, 197, + 430, 212, + 444, 226, + 458, 240, + 472, 254, + 486, 268, + 500, 282, + 514, 296, + 522, 297, + 521, 288, + 507, 273, + 492, 259, + 478, 245, + 464, 231, + 450, 217, + 436, 203, + 422, 188, + 408, 173, + 403, 173, + 399, 179, + End, + 23, 213, + 23, 223, + 25, 227, + 40, 241, + 54, 256, + 69, 270, + 83, 285, + 97, 299, + 111, 314, + 125, 328, + 134, 329, + 135, 323, + 128, 316, + 114, 301, + 99, 287, + 85, 272, + 71, 257, + 56, 243, + 42, 228, + 28, 213, + 23, 213, + End, + 397, 236, + 397, 246, + 403, 254, + 418, 268, + 432, 283, + 447, 297, + 461, 312, + 475, 326, + 490, 340, + 504, 354, + 518, 368, + 525, 368, + 524, 361, + 523, 358, + 514, 349, + 500, 336, + 486, 321, + 471, 307, + 457, 293, + 443, 279, + 429, 264, + 414, 250, + 402, 236, + 397, 236, + End, + 24, 284, + 25, 295, + 33, 304, + 46, 318, + 61, 332, + 75, 346, + 89, 361, + 101, 374, + 108, 374, + 108, 366, + 99, 356, + 85, 342, + 71, 327, + 57, 313, + 43, 299, + 29, 284, + 24, 284, + End, + 400, 308, + 400, 317, + 401, 320, + 408, 326, + 422, 341, + 436, 354, + 450, 369, + 464, 382, + 478, 397, + 492, 410, + 506, 424, + 520, 438, + 528, 439, + 527, 431, + 521, 424, + 514, 418, + 503, 406, + 489, 393, + 475, 379, + 461, 365, + 447, 351, + 433, 337, + 419, 323, + 405, 308, + 400, 308, + End, + 27, 355, + 27, 366, + 35, 375, + 49, 389, + 63, 403, + 77, 417, + 91, 432, + 105, 446, + 112, 447, + 111, 438, + 101, 427, + 87, 413, + 73, 398, + 59, 384, + 45, 370, + 31, 355, + 27, 355, + End, + 25, 499, + 25, 506, + 34, 505, + 30, 499, + 25, 499, + End, + 439, 417, + 440, 426, + 442, 430, + 457, 444, + 471, 458, + 485, 472, + 499, 486, + 514, 500, + 520, 507, + 531, 507, + 531, 503, + 530, 501, + 516, 487, + 502, 474, + 488, 460, + 474, 446, + 459, 432, + 445, 417, + 439, 417, + End, + 274, 470, + 274, 471, + 280, 479, + 294, 493, + 307, 507, + 322, 507, + 321, 506, + 314, 499, + 300, 485, + 286, 470, + 274, 470, + End, + 199, 462, + 199, 465, + 211, 478, + 225, 493, + 238, 507, + 253, 507, + 251, 504, + 237, 491, + 224, 476, + 209, 462, + 199, 462, + End, + 129, 462, + 131, 466, + 145, 481, + 159, 495, + 169, 507, + 184, 507, + 182, 505, + 168, 490, + 155, 476, + 141, 462, + 129, 462, + End, + 33, 429, + 33, 437, + 36, 442, + 50, 455, + 64, 470, + 78, 484, + 92, 498, + 99, 507, + 114, 507, + 110, 502, + 96, 488, + 82, 473, + 67, 459, + 53, 444, + 39, 429, + 33, 429, + End, + 411, 461, + 413, 465, + 427, 479, + 441, 494, + 456, 508, + 471, 509, + 467, 504, + 453, 490, + 438, 476, + 424, 461, + 411, 461, + End, + 338, 451, + 338, 460, + 351, 472, + 365, 487, + 379, 501, + 384, 508, + 399, 508, + 397, 505, + 388, 495, + 373, 481, + 359, 466, + 345, 451, + 338, 451, + End, End +}; +short squeen[] = /* V021 */ +{ + 492, 1, + 498, 10, + 506, 10, + 505, 2, + 504, 0, + 494, 0, + 492, 1, + End, + 209, 0, + 211, 3, + 224, 18, + 239, 18, + 237, 15, + 223, 0, + 209, 0, + End, + 280, 0, + 286, 7, + 299, 21, + 314, 21, + 309, 15, + 295, 0, + 280, 0, + End, + 141, 0, + 144, 5, + 154, 14, + 163, 25, + 177, 25, + 176, 22, + 169, 15, + 155, 0, + 141, 0, + End, + 73, 0, + 73, 2, + 82, 13, + 97, 27, + 110, 42, + 123, 42, + 123, 41, + 122, 39, + 113, 29, + 99, 14, + 85, 0, + 73, 0, + End, + 427, 0, + 427, 2, + 440, 17, + 450, 26, + 463, 41, + 477, 55, + 491, 69, + 505, 83, + 511, 84, + 511, 76, + 510, 73, + 496, 58, + 482, 44, + 468, 30, + 454, 15, + 440, 0, + 427, 0, + End, + 10, 1, + 11, 8, + 15, 14, + 22, 19, + 33, 32, + 48, 46, + 62, 61, + 76, 75, + 90, 89, + 93, 94, + 102, 94, + 102, 87, + 88, 73, + 74, 58, + 60, 44, + 47, 30, + 33, 16, + 19, 1, + 10, 1, + End, + 358, 0, + 358, 1, + 365, 9, + 379, 24, + 393, 39, + 407, 53, + 421, 68, + 435, 83, + 450, 97, + 464, 112, + 478, 126, + 492, 140, + 505, 154, + 513, 155, + 512, 145, + 502, 136, + 489, 121, + 474, 107, + 460, 92, + 452, 85, + 443, 74, + 428, 60, + 414, 45, + 400, 30, + 386, 15, + 372, 0, + 358, 0, + End, + 14, 70, + 14, 79, + 15, 82, + 27, 94, + 41, 108, + 55, 122, + 69, 137, + 84, 151, + 90, 159, + 98, 159, + 97, 151, + 89, 142, + 75, 128, + 61, 113, + 47, 99, + 33, 85, + 19, 70, + 14, 70, + End, + 15, 143, + 16, 154, + 19, 157, + 33, 172, + 47, 186, + 61, 200, + 75, 214, + 84, 215, + 84, 208, + 76, 201, + 62, 186, + 48, 172, + 34, 158, + 20, 143, + 15, 143, + End, + 421, 125, + 421, 127, + 422, 136, + 426, 141, + 440, 155, + 454, 170, + 468, 184, + 483, 198, + 489, 206, + 496, 211, + 510, 226, + 516, 226, + 516, 217, + 510, 211, + 496, 197, + 482, 183, + 468, 169, + 454, 155, + 440, 140, + 426, 125, + 421, 125, + End, + 19, 215, + 20, 225, + 22, 228, + 32, 237, + 41, 248, + 52, 257, + 57, 264, + 65, 264, + 65, 257, + 52, 244, + 38, 230, + 24, 215, + 19, 215, + End, + 437, 211, + 437, 213, + 440, 225, + 453, 237, + 467, 252, + 481, 265, + 495, 280, + 506, 289, + 512, 297, + 520, 297, + 520, 290, + 513, 283, + 499, 268, + 484, 254, + 470, 240, + 456, 226, + 442, 211, + 437, 211, + End, + 21, 287, + 22, 296, + 24, 300, + 32, 300, + 33, 294, + 27, 287, + 21, 287, + End, + 117, 318, + 119, 321, + 133, 336, + 147, 350, + 160, 364, + 170, 364, + 170, 361, + 169, 359, + 155, 345, + 141, 330, + 127, 315, + 121, 315, + 119, 316, + 117, 318, + End, + 503, 355, + 510, 360, + 515, 367, + 523, 367, + 523, 360, + 510, 346, + 504, 346, + 504, 347, + 503, 355, + End, + 248, 374, + 248, 379, + 258, 390, + 272, 404, + 286, 419, + 293, 420, + 293, 412, + 283, 402, + 269, 387, + 255, 372, + 251, 372, + 248, 374, + End, + 98, 365, + 98, 367, + 111, 381, + 120, 389, + 129, 400, + 144, 414, + 148, 420, + 157, 420, + 157, 414, + 150, 407, + 136, 393, + 122, 378, + 108, 363, + 102, 363, + 102, 364, + 98, 365, + End, + 387, 296, + 387, 304, + 394, 312, + 406, 325, + 421, 339, + 435, 353, + 449, 367, + 463, 381, + 477, 394, + 491, 409, + 506, 423, + 521, 438, + 528, 439, + 527, 431, + 520, 423, + 506, 409, + 491, 395, + 477, 381, + 463, 367, + 449, 353, + 435, 339, + 421, 325, + 407, 311, + 393, 296, + 387, 296, + End, + 376, 363, + 390, 378, + 404, 392, + 418, 406, + 432, 420, + 446, 433, + 460, 448, + 475, 462, + 490, 476, + 504, 491, + 519, 505, + 530, 506, + 529, 502, + 523, 496, + 509, 482, + 495, 468, + 480, 454, + 466, 440, + 452, 426, + 438, 412, + 424, 398, + 410, 384, + 396, 370, + 382, 355, + 378, 355, + 377, 357, + 376, 363, + End, + 202, 467, + 202, 469, + 211, 479, + 225, 493, + 235, 505, + 249, 505, + 241, 497, + 227, 482, + 213, 467, + 202, 467, + End, + 32, 356, + 32, 366, + 43, 377, + 57, 392, + 71, 406, + 85, 420, + 99, 434, + 113, 449, + 127, 463, + 140, 477, + 154, 491, + 167, 505, + 180, 505, + 177, 502, + 163, 487, + 149, 473, + 135, 458, + 121, 444, + 107, 429, + 93, 415, + 79, 400, + 64, 386, + 50, 371, + 36, 356, + 32, 356, + End, + 32, 429, + 32, 438, + 38, 444, + 52, 458, + 66, 473, + 80, 487, + 94, 501, + 97, 506, + 111, 506, + 108, 503, + 94, 488, + 80, 473, + 65, 459, + 51, 444, + 37, 429, + 32, 429, + End, + 32, 501, + 32, 506, + 41, 506, + 37, 501, + 32, 501, + End, + 397, 449, + 411, 463, + 425, 477, + 439, 492, + 454, 506, + 468, 507, + 462, 500, + 447, 486, + 434, 472, + 419, 458, + 405, 443, + 399, 443, + 399, 444, + 397, 449, + End, + 347, 467, + 348, 469, + 357, 479, + 369, 492, + 384, 506, + 396, 507, + 396, 505, + 387, 496, + 373, 482, + 359, 467, + 347, 467, + End, + 255, 446, + 259, 451, + 273, 465, + 286, 479, + 300, 493, + 313, 507, + 326, 507, + 326, 506, + 319, 499, + 313, 494, + 304, 483, + 291, 471, + 277, 456, + 263, 441, + 258, 441, + 255, 446, + End, End +}; +short sking[] = /* V022 */ +{ + 140, 0, + 140, 2, + 150, 12, + 163, 26, + 176, 26, + 176, 25, + 175, 23, + 168, 15, + 154, 0, + 140, 0, + End, + 72, 0, + 73, 2, + 86, 16, + 100, 31, + 108, 38, + 117, 49, + 126, 49, + 128, 45, + 123, 38, + 114, 30, + 100, 15, + 86, 0, + 72, 0, + End, + 7, 0, + 7, 6, + 8, 9, + 19, 20, + 33, 34, + 47, 49, + 61, 63, + 74, 77, + 88, 90, + 93, 97, + 100, 97, + 101, 90, + 99, 87, + 85, 72, + 71, 58, + 57, 43, + 43, 29, + 29, 15, + 15, 0, + 7, 0, + End, + 8, 68, + 8, 80, + 10, 83, + 24, 97, + 38, 112, + 52, 126, + 66, 140, + 80, 155, + 88, 156, + 88, 146, + 83, 142, + 69, 127, + 55, 112, + 40, 98, + 26, 83, + 12, 68, + 8, 68, + End, + 9, 141, + 9, 150, + 13, 155, + 27, 170, + 42, 184, + 51, 195, + 59, 195, + 63, 192, + 56, 184, + 42, 170, + 28, 156, + 14, 141, + 9, 141, + End, + 10, 212, + 11, 222, + 24, 235, + 33, 236, + 33, 230, + 29, 227, + 15, 212, + 10, 212, + End, + 11, 282, + 11, 293, + 18, 294, + 18, 287, + 15, 282, + 11, 282, + End, + 136, 417, + 138, 420, + 151, 435, + 161, 444, + 171, 456, + 179, 456, + 178, 449, + 175, 445, + 161, 430, + 147, 415, + 139, 415, + 136, 417, + End, + 12, 352, + 13, 362, + 17, 365, + 31, 380, + 45, 394, + 59, 409, + 74, 423, + 87, 438, + 102, 452, + 116, 467, + 129, 481, + 142, 493, + 152, 505, + 165, 505, + 157, 497, + 143, 482, + 129, 468, + 115, 453, + 101, 439, + 87, 424, + 73, 410, + 59, 395, + 45, 381, + 31, 367, + 17, 352, + 12, 352, + End, + 12, 425, + 13, 432, + 18, 436, + 32, 451, + 46, 465, + 60, 480, + 75, 494, + 85, 506, + 96, 506, + 95, 505, + 89, 499, + 75, 484, + 61, 469, + 46, 455, + 32, 440, + 18, 425, + 12, 425, + End, + 12, 495, + 12, 506, + 25, 505, + 17, 495, + 12, 495, + End, + 221, 0, + 223, 2, + 236, 17, + 250, 17, + 250, 15, + 236, 0, + 221, 0, + End, + 212, 487, + 212, 491, + 226, 506, + 240, 507, + 237, 503, + 224, 489, + 220, 488, + 220, 487, + 212, 487, + End, + 291, 0, + 298, 8, + 311, 22, + 326, 22, + 320, 15, + 306, 0, + 291, 0, + End, + 284, 489, + 286, 492, + 299, 507, + 311, 507, + 311, 506, + 308, 504, + 294, 489, + 284, 489, + End, + 355, 482, + 355, 492, + 363, 499, + 369, 507, + 382, 507, + 382, 506, + 373, 497, + 359, 482, + 355, 482, + End, + 352, 414, + 352, 417, + 356, 421, + 370, 436, + 384, 450, + 398, 465, + 413, 479, + 427, 494, + 441, 508, + 456, 508, + 448, 500, + 434, 486, + 420, 472, + 406, 457, + 392, 443, + 378, 429, + 364, 414, + 352, 414, + End, + 367, 0, + 367, 1, + 379, 15, + 393, 29, + 407, 44, + 421, 59, + 435, 73, + 449, 88, + 463, 103, + 477, 117, + 491, 132, + 505, 146, + 518, 160, + 526, 160, + 526, 153, + 519, 146, + 505, 132, + 491, 117, + 477, 103, + 463, 88, + 449, 74, + 435, 59, + 421, 44, + 408, 30, + 394, 15, + 380, 0, + 367, 0, + End, + 438, 0, + 439, 3, + 443, 8, + 457, 22, + 471, 37, + 485, 52, + 499, 67, + 514, 81, + 520, 89, + 527, 89, + 527, 80, + 520, 73, + 506, 58, + 492, 43, + 478, 29, + 464, 14, + 450, 0, + 438, 0, + End, + 438, 137, + 441, 149, + 449, 158, + 463, 172, + 477, 187, + 491, 201, + 505, 215, + 519, 230, + 526, 230, + 526, 222, + 514, 210, + 500, 195, + 486, 181, + 472, 167, + 458, 152, + 444, 137, + 438, 137, + End, + 515, 283, + 517, 294, + 519, 298, + 526, 299, + 526, 290, + 520, 283, + 515, 283, + End, + 515, 362, + 520, 369, + 528, 369, + 528, 364, + 522, 355, + 516, 355, + 516, 356, + 515, 362, + End, + 483, 399, + 488, 405, + 502, 419, + 507, 423, + 520, 437, + 528, 438, + 528, 431, + 521, 423, + 506, 409, + 492, 394, + 487, 394, + 485, 395, + 483, 399, + End, + 437, 423, + 438, 426, + 449, 437, + 462, 451, + 477, 465, + 491, 479, + 505, 492, + 519, 507, + 530, 507, + 528, 502, + 518, 492, + 504, 478, + 489, 464, + 476, 450, + 461, 436, + 447, 421, + 440, 421, + 437, 423, + End, + 517, 1, + 517, 2, + 527, 15, + 535, 15, + 535, 1, + 532, 1, + 517, 1, + End, End +}; + +short* pieces[] = +{ + bpawn, + bknight, + bbishop, + brook, + bqueen, + bking, + + wpawn, + wknight, + wbishop, + wrook, + wqueen, + wking, + + sempty, + spawn, + sknight, + sbishop, + srook, + squeen, + sking, + 0 +}; diff -r b1478befa184 -r eab69ba077aa sys/src/cmd/chdb/cdb/fs-1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/cmd/chdb/cdb/fs-1 Mon Apr 12 21:24:07 2021 -0400 @@ -0,0 +1,55 @@ +file: fs:1 +white: Fischer +black: Spassky +event: Sveti Stefan (1) 1992 +opening: C95/17 15 ♗g5 +result: 1-0 + 1. e4 e5 + 2. Nf3 Nc6 + 3. Bb5 a6 + 4. Ba4 Nf6 + 5. O-O Be7 + 6. Re1 b5 + 7. Bb3 d6 + 8. c3 O-O + 9. h3 Nb8 +10. d4 Nbd7 +11. Nbd2 Bb7 +12. Bc2 Re8 +13. Nf1 Bf8 +14. Ng3 g6 +15. Bg5 h6 +16. Bd2 Bg7 +17. a4 c5 +18. d5 c4 +19. b4 Nh7 +20. Be3 h5 +21. Qd2 Rf8 +22. Ra3 Ndf6 +23. Rea1 Qd7 +24. R1a2 Rfc8 +25. Qc1 Bf8 +26. Qa1 Qe8 +27. Nf1 Be7 +28. N1d2 Kg7 +29. Nb1 N:e4 +30. B:e4 f5 +31. Bc2 B:d5 +32. a:b5 a:b5 +33. Ra7 Kf6 +34. Nbd2 R:a7 +35. R:a7 Ra8 +36. g4 h:g4 +37. h:g4 R:a7 +38. Q:a7 f4 +39. B:f4 e:f4 +40. Nh4 Bf7 +41. Qd4+ Ke6 +42. Nf5 Bf8 +43. Q:f4 Kd7 +44. Nd4 Qe1+ +45. Kg2 Bd5+ +46. Be4 B:e4+ +47. N:e4 Be7 +48. N:b5 Nf8 +49. Nb:d6 Ne6 diff -r b1478befa184 -r eab69ba077aa sys/src/cmd/chdb/cdb/fs-2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/cmd/chdb/cdb/fs-2 Mon Apr 12 21:24:07 2021 -0400 @@ -0,0 +1,65 @@ +file: fs:2 +white: Spassky +black: Fischer +event: Sveti Stefan (2) 1992 +opening: E80/01 9 ♘ge2 +result: +-+ + 1. d4 Nf6 + 2. c4 g6 + 3. Nc3 Bg7 + 4. e4 d6 + 5. f3 c5 + 6. d:c5 d:c5 + 7. Q:d8+ K:d8 + 8. Be3 Nfd7 + 9. Nge2 b6 +10. O-O-O Na6 +11. g3 Nc7 +12. f4 e6 +13. Bh3 Ke7 +14. Rhf1 h6 +15. e5 Bb7 +16. g4 Rad8 +17. Ng3 f6 +18. Nce4 f:e5 +19. f5 B:e4 +20. N:e4 g:f5 +21. g:f5 Nf6 +22. Rg1 R:d1+ +23. K:d1 Bf8 +24. N:f6 K:f6 +25. Rf1 e:f5 +26. R:f5+ Kg7 +27. R:e5 Bd6 +28. Re4 B:h2 +29. Ke2 h5 +30. Re7+ Kf6 +31. Rd7 Be5 +32. b3 h4 +33. Kf3 Rg8 +34. Bg4 h3 +35. Rh7 h2 +36. Bf4 Rf8 +37. B:e5+ Kg6+ +38. Ke4 K:h7 +39. B:h2 Re8+ +40. Kf5 Ne6 +41. Kf6 Nd4 +42. Bd6 Re4 +43. Bd7 Re2 +44. a4 Rb2 +45. Bb8 a5 +46. Ba7 R:b3 +47. Ke5 Nf3+ +48. Kd6 Nd2 +49. Be6 Rb4 +50. Kc6 Nb3 +51. Bd5 R:a4 +52. B:b6 Ra1 +53. B:c5 a4 +54. Bb4 a3 +55. c5 Nd4+ +56. Kd7 Rd1 +57. B:a3 Nc2 +58. c6 R:d5+ +59. Bd6 diff -r b1478befa184 -r eab69ba077aa sys/src/cmd/chdb/cdb/fs-3 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/cmd/chdb/cdb/fs-3 Mon Apr 12 21:24:07 2021 -0400 @@ -0,0 +1,45 @@ +file: fs:3 +white: Fischer +black: Spassky +event: Sveti Stefan (3) 1992 +opening: C95/17 15 ♗g5 +result: +-+ + 1. e4 e5 + 2. Nf3 Nc6 + 3. Bb5 a6 + 4. Ba4 Nf6 + 5. O-O Be7 + 6. Re1 b5 + 7. Bb3 d6 + 8. c3 O-O + 9. h3 Nb8 +10. d4 Nbd7 +11. Nbd2 Bb7 +12. Bc2 Re8 +13. Nf1 Bf8 +14. Ng3 g6 +15. Bg5 h6 +16. Bd2 e:d4 +17. c:d4 c5 +18. Bf4 c:d4 +19. N:d4 Ne5 +20. b3 d5 +21. Qd2 d:e4 +22. N:e4 Nd5 +23. Bg3 Rc8 +24. Re2 f5 +25. B:e5 R:e5 +26. Ng3 R:e2 +27. Ng:e2 Nb4 +28. Rd1 N:c2 +29. N:c2 Q:d2 +30. R:d2 Rc7 +31. Ne3 Kf7 +32. h4 Bc8 +33. Nf4 g5 +34. h:g5 h:g5 +35. Nd3 Bg7 +36. Nd5 Rc6 +37. N5b4 Rc7 +38. Nd5 Rc6 +39. N5b4 Rc7 diff -r b1478befa184 -r eab69ba077aa sys/src/cmd/chdb/cdb/fs-4 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/cmd/chdb/cdb/fs-4 Mon Apr 12 21:24:07 2021 -0400 @@ -0,0 +1,56 @@ +file: fs:4 +white: Spassky +black: Fischer +event: Sveti Stefan (4) 1992 +opening: D27/02 9 b3 +result: 1-0 + 1. d4 d5 + 2. c4 d:c4 + 3. Nf3 Nf6 + 4. e3 e6 + 5. B:c4 c5 + 6. O-O a6 + 7. d:c5 Q:d1 + 8. R:d1 B:c5 + 9. b3 Nbd7 +10. Bb2 b6 +11. Nc3 Bb7 +12. Rac1 Be7 +13. Nd4 Rc8 +14. f3 b5 +15. Be2 Bc5 +16. Kf1 Ke7 +17. e4 g5 +18. Nb1 g4 +19. Ba3 b4 +20. R:c5 N:c5 +21. B:b4 Rhd8 +22. Na3 g:f3 +23. g:f3 Nfd7 +24. Nc4 Ba8 +25. Kf2 Rg8 +26. h4 Rc7 +27. Nc2 Rb8 +28. Ba3 h5 +29. Rg1 Kf6 +30. Ke3 a5 +31. Rg5 a4 +32. b4 Nb7 +33. b5 Nbc5 +34. Nd4 e5 +35. N:e5 N:e5 +36. Rf5+ Kg7 +37. R:e5 N:e4 +38. Bd3 Rc3 +39. Bb4 R:d3+ +40. K:d3 Nf6 +41. Bd6 Rc8 +42. Rg5+ Kh7 +43. Be5 Ne8 +44. R:h5+ Kg6 +45. Rg5+ Kh7 +46. Bf4 f6 +47. Rf5 Kg6 +48. b6 Rd8 +49. Ra5 B:f3 +50. h5+ diff -r b1478befa184 -r eab69ba077aa sys/src/cmd/chdb/cdb/fs-5 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/cmd/chdb/cdb/fs-5 Mon Apr 12 21:24:07 2021 -0400 @@ -0,0 +1,51 @@ +file: fs:5 +white: Fischer +black: Spassky +event: Sveti Stefan (5) 1992 +opening: C95/17 15 ♗g5 +result: 0-1 + 1. e4 e5 + 2. Nf3 Nc6 + 3. Bb5 a6 + 4. Ba4 Nf6 + 5. O-O Be7 + 6. Re1 b5 + 7. Bb3 d6 + 8. c3 O-O + 9. h3 Nb8 +10. d4 Nbd7 +11. Nbd2 Bb7 +12. Bc2 Re8 +13. Nf1 Bf8 +14. Ng3 g6 +15. Bg5 h6 +16. Bd2 e:d4 +17. c:d4 c5 +18. d5 Nb6 +19. Ba5 Nfd7 +20. b3 Bg7 +21. Rc1 Qf6 +22. Rb1 b4 +23. Ne2 Qe7 +24. a3 b:a3 +25. Bc3 f5 +26. B:g7 Q:g7 +27. Nf4 f:e4 +28. Nh4 g5 +29. Ne6 Qf6 +30. Qg4 N:d5 +31. N:g5 h:g5 +32. Q:d7 Nb4 +33. Q:b7 N:c2 +34. R:e4 a2 +35. Rf1 Nb4 +36. Rg4 a1Q +37. R:a1 Q:a1+ +38. Kh2 Qg7 +39. Qf3 Qe5+ +40. g3 Rf8 +41. Qg2 Qf6 +42. f4 Ra7 +43. R:g5+ Rg7 +44. Rh5 Qe6 +45. g4 R:f4 diff -r b1478befa184 -r eab69ba077aa sys/src/cmd/chdb/cdb/fs-6 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/cmd/chdb/cdb/fs-6 Mon Apr 12 21:24:07 2021 -0400 @@ -0,0 +1,67 @@ +file: fs:6 +white: Spassky +black: Fischer +event: Sveti Stefan (6) 1992 +opening: D27/02 9 b3 +result: +-+ + 1. d4 d5 + 2. c4 d:c4 + 3. Nf3 Nf6 + 4. e3 e6 + 5. B:c4 c5 + 6. O-O a6 + 7. d:c5 Q:d1 + 8. R:d1 B:c5 + 9. b3 Nbd7 +10. Bb2 b5 +11. Be2 Bb7 +12. Nbd2 Ke7 +13. a4 b:a4 +14. R:a4 Rhb8 +15. Rc1 Bd5 +16. Ne5 Bd6 +17. N:d7 N:d7 +18. R:a6 R:a6 +19. B:a6 f6 +20. Bc4 B:c4 +21. R:c4 Nc5 +22. Rc3 f5 +23. Ba3 Ne4 +24. Rc7+ Kd8 +25. B:d6 N:d2 +26. R:g7 R:b3 +27. h4 h5 +28. Bf4 Ke8 +29. Kh2 Rb2 +30. Kh3 Ne4 +31. f3 Nf2+ +32. Kg3 Nd3 +33. Bg5 e5 +34. Kh3 Nf2+ +35. Kh2 Nd3 +36. Bh6 Ne1 +37. Kg1 Nd3 +38. Bg5 Rb1+ +39. Kh2 Rb2 +40. Re7+ Kf8 +41. Re6 Kg7 +42. Kh3 Re2 +43. Rd6 Ne1 +44. Bf6+ Kg8 +45. B:e5 R:e3 +46. Bf4 Re2 +47. Rg6+ Kf7 +48. Rg5 Ke6 +49. Bc7 Ra2 +50. Bb6 Nd3 +51. Kh2 Ne1 +52. Kh3 Nd3 +53. Bc7 Rc2 +54. Bb6 Ra2 +55. Kg3 Ne1 +56. R:h5 R:g2+ +57. Kf4 Nd3+ +58. Ke3 Ne5 +59. Rh6+ Kd5 +60. Bc7 Rg7 +61. B:e5 K:e5 diff -r b1478befa184 -r eab69ba077aa sys/src/cmd/chdb/cdb/mkfile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/cmd/chdb/cdb/mkfile Mon Apr 12 21:24:07 2021 -0400 @@ -0,0 +1,32 @@ +BUILTINS= + +#include +#include "gen.h" + +void +ginit(Posn *posn) +{ + int i, p; + + if(posn->bd[4] == (INIT|BKING) && + posn->bd[60] == (INIT|WKING)) { + memmove(board, posn->bd, 64); + bkpos = 4; + wkpos = 60; + } else + for(i=0; i<64; i++) { + p = posn->bd[i]; + board[i] = p; + p &= 017; + if(p == WKING) + wkpos = i; + if(p == BKING) + bkpos = i; + } + eppos = posn->epp; + moveno = posn->mvno; + mvno = 0; + mvlist[0] = 0; + amp = ambuf; + *amp++ = 0; + for(i=0; p=posn->mv[i]; i++) + cmove(p); +} + +void +gstore(Posn *posn) +{ + + memmove(posn->mv, mvlist, mvno*sizeof(*mvlist)); + posn->mv[mvno] = 0; + while(mvno) + rmove(); + memmove(posn->bd, board, 64); + + posn->epp = eppos; + posn->mvno = moveno; + ginit(posn); +} + +void +getamv(short *mv) +{ + + lmp = mv; + if(moveno & 1) + bgen(); + else + wgen(); + if(lmp-mv >= MAXMG) { + fprint(2, "MAXMG (%d) too small\n", MAXMG); + exits("maxmg"); + } + *lmp = 0; +} + +void +getmv(short *mv) +{ + int i, f; + + lmp = mv; + if(moveno & 1) + bgen(); + else + wgen(); + if(lmp-mv >= MAXMG) { + fprint(2, "MAXMG (%d) too small\n", MAXMG); + exits("maxmg"); + } + *lmp = 0; + lmp = mv; + for(i=0; mv[i]; i++) { + if(moveno & 1) { + bmove(mv[i]); + f = wattack(bkpos); + bremove(); + } else { + wmove(mv[i]); + f = battack(wkpos); + wremove(); + } + if(f) + *lmp++ = mv[i]; + } + *lmp = 0; +} + +void +cmove(int mv) +{ + + if(moveno & 1) + bmove(mv); + else + wmove(mv); + moveno++; + mvlist[mvno++] = mv; +} + +void +qmove(int mov) +{ + int from, to, typ, p; + + from = (mov>>6) & 077; + to = (mov>>0) & 077; + typ = (mov>>12) & 017; + + p = board[from] & 017; + board[to] = p; + board[from] = 0; + + switch(typ) { + + case TNPRO: + board[to] = WKNIGHT | (p&BLACK); + break; + + case TBPRO: + board[to] = WBISHOP | (p&BLACK); + break; + + case TRPRO: + board[to] = WROOK | (p&BLACK); + break; + + case TQPRO: + board[to] = WQUEEN | (p&BLACK); + break; + + case TOO: + from = to+1; + to--; + goto mv; + + case TOOO: + from = to-2; + to++; + + mv: + board[to] = board[from] & 017; + board[from] = 0; + break; + + case TENPAS: + if(p & BLACK) + to -= 8; + else + to += 8; + board[to] = 0; + break; + } + moveno++; +} + +int +rmove(void) +{ + + if(mvno <= 0) + return 0; + moveno--; + if(moveno & 1) + bremove(); + else + wremove(); + return mvlist[--mvno]; +} + +int +retract(int m) +{ + int p; + + if(m == 0) + return 1; + p = board[(m>>6) & 077] & 7; + if(p == WPAWN) + return 1; + if(p == WKING) { + p = (m>>12) & 017; + if(p == TOO || p == TOOO) + return 1; + } + p = board[m & 077] & 7; + if(p != 0) + return 1; + return 0; +} + +int +check(void) +{ + + if(moveno & 1) + return !wattack(bkpos); + return !battack(wkpos); +} + +void +wgen(void) +{ + schar *p; + int i, j, k, d, p0, p1; + + for(i=0; i<64; i++) + if(board[i]) + switch(board[i]) { + + case INIT|WPAWN: + case WPAWN: + d = dir[i]; + if((d&ULEFT) == 0) { + if(color[board[i-9]] < 0) + if((d&RANK7) != 0) { + wcheck(i, i-9, TNPRO); + wcheck(i, i-9, TBPRO); + wcheck(i, i-9, TRPRO); + wcheck(i, i-9, TQPRO); + } else + wcheck(i, i-9, TNORM); + if(eppos == i-1) + wcheck(i, i-9, TENPAS); + } + if((d&URIGHT) == 0) { + if(color[board[i-7]] < 0) + if((d&RANK7) != 0) { + wcheck(i, i-7, TNPRO); + wcheck(i, i-7, TBPRO); + wcheck(i, i-7, TRPRO); + wcheck(i, i-7, TQPRO); + } else + wcheck(i, i-7, TNORM); + if(eppos == i+1) + wcheck(i, i-7, TENPAS); + } + if(board[i-8] == 0) { + if((d&RANK7) != 0) { + wcheck(i, i-8, TNPRO); + wcheck(i, i-8, TBPRO); + wcheck(i, i-8, TRPRO); + wcheck(i, i-8, TQPRO); + } else + wcheck(i, i-8, TNORM); + if(d & RANK2) + if(board[i-16] == 0) + wcheck(i, i-16, TEPENAB); + } + continue; + + case INIT|WKNIGHT: + case WKNIGHT: + p = attab; + goto jump; + + case INIT|WKING: + if(board[56] == (INIT|WROOK)) + if(board[57] == 0) + if(board[58] == 0) + if(board[59] == 0) + if(battack(58)) + if(battack(59)) + if(battack(60)) + if(i == 60) + wcheck(60, 58, TOOO); + if(board[63] == (INIT|WROOK)) + if(board[62] == 0) + if(board[61] == 0) + if(battack(62)) + if(battack(61)) + if(battack(60)) + if(i == 60) + wcheck(60, 62, TOO); + + case WKING: + p = attab+16; + + jump: + d = dir[i]; + for(j=8; j--; p+=2) + if((d&p[0]) == 0) + wcheck(i, i+p[1], TNORM); + continue; + + case INIT|WBISHOP: + case WBISHOP: + p = attab+16; + j = 4; + goto slide; + + case INIT|WROOK: + case WROOK: + p = attab+24; + j = 4; + goto slide; + + case INIT|WQUEEN: + case WQUEEN: + p = attab+16; + j = 8; + + slide: + while(j--) { + p0 = *p++; + p1 = *p++; + k = i; + while((dir[k]&p0) == 0) { + k += p1; + if(wcheck(i, k, TNORM)) + break; + } + } + continue; + } +} + +int +wcheck(int from, int to, int typ) +{ + int b; + + b = board[to]; + if(color[b] > 0) + return 1; + *lmp++ = (typ<<12) | (from<<6) | to; + return b; +} + +void +wmove(int mov) +{ + int i, from, to; + + from = (mov>>6) & 077; + to = (mov>>0) & 077; + eppos = 0; + *amp++ = AMARK | (from<<5) | board[from]; + if(from == 0 && to == 0) + return; + *amp++ = (to<<5) | board[to]; + i = board[from] & 017; + board[to] = i; + if(i == WKING) + wkpos = to; + board[from] = 0; + switch((mov>>12)&017) { + + case TNPRO: + board[to] = WKNIGHT; + break; + + case TBPRO: + board[to] = WBISHOP; + break; + + case TRPRO: + board[to] = WROOK; + break; + + case TQPRO: + board[to] = WQUEEN; + break; + + case TOO: + from = to+1; + to--; + goto mv; + + case TOOO: + from = to-2; + to++; + + mv: + *amp++ = (from<<5) | board[from]; + *amp++ = (to<<5) | board[to]; + board[to] = board[from] & 017; + board[from] = 0; + break; + + case TENPAS: + to += 8; + *amp++ = (to<<5) | board[to]; + board[to] = 0; + break; + + case TEPENAB: + amp[-1] |= EPMARK; + eppos = to; + break; + } +} + +void +wremove(void) +{ + int i, pi; + + do { + amp--; + i = (*amp>>5) & 077; + pi = *amp & 037; + board[i] = pi; + if((pi&017) == WKING) + wkpos = i; + } while((*amp&AMARK) == 0); + eppos = 0; + if(amp[-1] & EPMARK) + eppos = (amp[-1]>>5) & 077; +} + +int +battack(int pos) +{ + schar *p; + int i, j, p0, p1, b, d; + + p = attab; + d = dir[pos]; + + /* attack by knight */ + for(i=8; i--; p+=2) { + if((d & p[0]) == 0) + if((board[pos+p[1]]&017) == BKNIGHT) + return 0; + } + + /* attack along diagonal */ + for(i=4; i--;) { + p0 = *p++; + p1 = *p++; + j = pos; + while((dir[j]&p0) == 0) { + j += p1; + b = board[j] & 017; + if(b) + if(b == BQUEEN || b == BBISHOP) + return 0; + else + break; + } + } + + /* attack at right angles */ + for(i=4; i--;) { + p0 = *p++; + p1 = *p++; + j = pos; + while((dir[j]&p0) == 0) { + j += p1; + b = board[j] & 017; + if(b) + if(b == BQUEEN || b == BROOK) + return 0; + else + break; + } + } + + /* attack by king */ + p -= 16; + for(i=8; i--; p+=2) + if((d & p[0]) == 0) + if((board[pos+p[1]]&017) == BKING) + return 0; + + /* attack by pawns */ + if((d & ULEFT) == 0) + if((board[pos-9]&017) == BPAWN) + return 0; + if((d & URIGHT) == 0) + if((board[pos-7]&017) == BPAWN) + return 0; + + return 1; +} + +void +bgen(void) +{ + schar *p; + int i, j, k, d, p0, p1; + + for(i=0; i<64; i++) + if(board[i]) + switch(board[i]) { + + case INIT|BPAWN: + case BPAWN: + d = dir[i]; + if((d&DLEFT) == 0) { + if(color[board[i+7]] > 0) + if((d&RANK2) != 0) { + bcheck(i, i+7, TNPRO); + bcheck(i, i+7, TBPRO); + bcheck(i, i+7, TRPRO); + bcheck(i, i+7, TQPRO); + } else + bcheck(i, i+7, TNORM); + if(eppos == i-1) + bcheck(i, i+7, TENPAS); + } + if((d&DRIGHT) == 0) { + if(color[board[i+9]] > 0) + if((d&RANK2) != 0) { + bcheck(i, i+9, TNPRO); + bcheck(i, i+9, TBPRO); + bcheck(i, i+9, TRPRO); + bcheck(i, i+9, TQPRO); + } else + bcheck(i, i+9, TNORM); + if(eppos == i+1) + bcheck(i, i+9, TENPAS); + } + if(board[i+8] == 0) { + if((d&RANK2) != 0) { + bcheck(i, i+8, TNPRO); + bcheck(i, i+8, TBPRO); + bcheck(i, i+8, TRPRO); + bcheck(i, i+8, TQPRO); + } else + bcheck(i, i+8, TNORM); + if(d & RANK7) + if(board[i+16] == 0) + bcheck(i, i+16, TEPENAB); + } + continue; + + case INIT|BKNIGHT: + case BKNIGHT: + p = attab; + goto jump; + + case INIT|BKING: + if(board[0] == (INIT|BROOK)) + if(board[1] == 0) + if(board[2] == 0) + if(board[3] == 0) + if(wattack(2)) + if(wattack(3)) + if(wattack(4)) + if(i == 4) + bcheck(4, 2, TOOO); + if(board[7] == (INIT|BROOK)) + if(board[6] == 0) + if(board[5] == 0) + if(wattack(6)) + if(wattack(5)) + if(wattack(4)) + if(i == 4) + bcheck(4, 6, TOO); + + case BKING: + p = attab+16; + + jump: + d = dir[i]; + for(j=8; j--; p+=2) + if((d&p[0]) == 0) + bcheck(i, i+p[1], TNORM); + continue; + + case INIT|BBISHOP: + case BBISHOP: + p = attab+16; + j = 4; + goto slide; + + case INIT|BROOK: + case BROOK: + p = attab+24; + j = 4; + goto slide; + + case INIT|BQUEEN: + case BQUEEN: + p = attab+16; + j = 8; + + slide: + while(j--) { + p0 = *p++; + p1 = *p++; + k = i; + while((dir[k]&p0) == 0) { + k += p1; + if(bcheck(i, k, TNORM)) + break; + } + } + continue; + } +} + +int +bcheck(int from, int to, int typ) +{ + int b; + + b = board[to]; + if(color[b] < 0) + return 1; + *lmp++ = (typ<<12) | (from<<6) | to; + return b; +} + +void +bmove(int mov) +{ + int i, from, to; + + from = (mov>>6) & 077; + to = (mov>>0) & 077; + eppos = 0; + *amp++ = AMARK | (from<<5) | board[from]; + if(from == 0 && to == 0) + return; + *amp++ = (to<<5) | board[to]; + i = board[from] & 017; + board[to] = i; + if(i == BKING) + bkpos = to; + board[from] = 0; + switch((mov>>12)&017) { + + case TNPRO: + board[to] = BKNIGHT; + break; + + case TBPRO: + board[to] = BBISHOP; + break; + + case TRPRO: + board[to] = BROOK; + break; + + case TQPRO: + board[to] = BQUEEN; + break; + + case TOO: + from = to+1; + to--; + goto mv; + + case TOOO: + from = to-2; + to++; + + mv: + *amp++ = (from<<5) | board[from]; + *amp++ = (to<<5) | board[to]; + board[to] = board[from] & 017; + board[from] = 0; + break; + + case TENPAS: + to -= 8; + *amp++ = (to<<5) | board[to]; + board[to] = 0; + break; + + case TEPENAB: + amp[-1] |= EPMARK; + eppos = to; + break; + } +} + +void +bremove(void) +{ + int i, pi; + + do { + amp--; + i = (*amp>>5) & 077; + pi = *amp & 037; + board[i] = pi; + if((pi&017) == BKING) + bkpos = i; + } while((*amp&AMARK) == 0); + eppos = 0; + if(amp[-1] & EPMARK) + eppos = (amp[-1]>>5) & 077; +} + +wattack(int pos) +{ + schar *p; + int i, j, p0, p1, b, d; + + p = attab; + d = dir[pos]; + + /* attack by knight */ + for(i=8; i--; p+=2) + if((d & p[0]) == 0) + if((board[pos+p[1]]&017) == WKNIGHT) + return 0; + + /* attack along diagonal */ + i = 4; + while(i--) { + p0 = *p++; + p1 = *p++; + j = pos; + while((dir[j]&p0) == 0) { + j += p1; + b = board[j]&017; + if(b) + if(b == WQUEEN || b == WBISHOP) + return 0; + else + break; + } + } + + /* attack at right angles */ + i = 4; + while(i--) { + p0 = *p++; + p1 = *p++; + j = pos; + while((dir[j]&p0) == 0) { + j += p1; + b = board[j]&017; + if(b) + if(b == WQUEEN || b == WROOK) + return 0; + else + break; + } + } + + /* attack by king */ + p -= 16; + for(i=8; i--; p+=2) + if((d & p[0]) == 0) + if((board[pos+p[1]]&017) == WKING) + return 0; + + /* attack by pawns */ + if((d & DLEFT) == 0) + if((board[pos+7]&017) == WPAWN) + return 0; + if((d & DRIGHT) == 0) + if((board[pos+9]&017) == WPAWN) + return 0; + return 1; +} diff -r b1478befa184 -r eab69ba077aa sys/src/cmd/chdb/ci.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/cmd/chdb/ci.c Mon Apr 12 21:24:07 2021 -0400 @@ -0,0 +1,746 @@ +#include +#include +#include "gen.h" + +static int fmtmode; +static int fmtformat; +static int fmtchar; + +void +chessinit(int chr, int mode, int fmt) +{ + + fmtmode = mode; + fmtformat = fmt; + if(chr != fmtchar) + fmtinstall(chr, chessfmt); +} + +#pragma varargck type "G" int +int +chessfmt(Fmt* fp) +{ + int o; + char str1[50], str2[50], *p1, *p2; + Rune r; + int c; + + o = va_arg(fp->args, int); + + ((fmtformat&1)? dscout: algout)(o, str1, fmtmode); + if(fmtformat&2) { + p2 = str2; + for(p1=str1; c=*p1; p1++) + switch(c) { + default: + fprint(2, "dont now %c\n", c); + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + + case 'O': + case '+': + case '-': + case '/': + *p2++ = c; + break; + case 'x': + case ':': + r = L'×'; + goto putr; + case 'P': + r = L'♙'; + goto putr; + case 'N': + r = L'♘'; + goto putr; + case 'B': + r = L'♗'; + goto putr; + case 'R': + r = L'♖'; + goto putr; + case 'Q': + r = L'♕'; + goto putr; + case 'K': + r = L'♔'; + goto putr; + putr: + p2 += runetochar(p2, &r); + break; + } + *p2 = 0; + /* changed strconv(str2, fp); */ + dofmt(fp, str2); + return sizeof(int); + } + /* changed strconv(str1, fp); */ + dofmt(fp, str1); + return sizeof(int); +} + +int +chessin(char *str) +{ + int m; + short mv[MAXMG]; + + getamv(mv); + m = xalgin(mv, str); + if(m == 0) + m = xdscin(mv, str); + return m; +} + +int +xalgin(short *mv, char *str) +{ + int p, t, fx, fy, tx, ty, x, m, i; + Rune c; + + str += chartorune(&c, str); + t = -1; + p = -1; + + if(c == '*' && str[0] == '*' && str[1] == '*' && str[2] == 0) + return TNULL << 12; + for(i=0; c=='o'||c=='O'||c=='0'; i++) { + str += chartorune(&c, str); + while(c == '-') + str += chartorune(&c, str); + if(i > 0) { + p = WKING; + t = TOO; + if(i > 1) + t = TOOO; + } + } + + i = 0; + switch(c) { + case 'P': + case L'♙': + i = 1; + break; + case 'N': + case 'n': + case L'♘': + i = 2; + break; + case 'B': + case 'p': + case L'♗': + i = 3; + break; + case 'R': + case 'r': + case L'♖': + i = 4; + break; + case 'Q': + case 'q': + case L'♕': + i = 5; + break; + case 'K': + case 'k': + case L'♔': + i = 6; + break; + } + if(i != 0) { + str += chartorune(&c, str); + p = i; + } + + fx = -1; + fy = -1; + +loop: + tx = -1; + ty = -1; + if(c >= 'a' && c <= 'h') { + tx = c-'a'; + str += chartorune(&c, str); + } + if(c >= '1' && c <= '8') { + ty = '8'-c; + str += chartorune(&c, str); + } + if(c == ':' || c == L'×') + str += chartorune(&c, str); + if((c >= 'a' && c <= 'h') || + (c >= '1' && c <= '8')) { + fx = tx; + fy = ty; + goto loop; + } + if(c == '(' || c == '=') + str += chartorune(&c, str); + + i = 0; + switch(c) { + case 'N': + case 'n': + case L'♘': + i = TNPRO; + break; + case 'B': + case 'p': + case L'♗': + i = TBPRO; + break; + case 'R': + case 'r': + case L'♖': + i = TRPRO; + break; + case 'Q': + case 'q': + case L'♕': + i = TQPRO; + break; + } + if(i != 0) { + str += chartorune(&c, str); + t = i; + } + + if(c == ')') + str += chartorune(&c, str); + while(c == '+') + str += chartorune(&c, str); + if(c != 0) + return 0; + + if(p == -1) { + p = WPAWN; + if(fx >= 0 && fy >= 0) + p = board[fy*8+fx] & 07; + } + c = 0; + for(i=0; m=mv[i]; i++) { + if(p == (board[(m>>6)&077]&7)) + if(match(m, p, t, fx, fy, -1, tx, ty)) { + if(moveno & 1) { + bmove(m); + x = wattack(bkpos); + bremove(); + } else { + wmove(m); + x = battack(wkpos); + wremove(); + } + if(!x) + continue; + if(c) + return 0; /* ambiguous */ + c = m; + } + } + return c; +} + +int +xdscin(short *mv, char *str) +{ + int pf, pt, t, fx, fy, tx, ty, x, i, c; + char *s; + + t = -1; + pf = -1; + pt = 0; + fx = fy = -1; + tx = ty = -1; + + str = getpie(&pf, &fx, str); + c = *str++; + if(c == '/') { + str = getpla(&fx, &fy, str); + c = *str++; + } + if(c == 'x' || c == '*') { + str = getpie(&pt, &tx, str); + c = *str++; + if(c == '/') { + str = getpla(&tx, &ty, str); + c = *str++; + } + } else + if(c == '-') { + str = getpla(&tx, &ty, str); + c = *str++; + } + if(c == '(' || c == '=') { + c = *str++; + t = -1; + for(s = "N0n0B1b1R2r2Q3q3"; s[0]; s+=2) + if(c == s[0]) + t = TNPRO + s[1]-'0'; + if(t < 0) + return 0; + c = *str++; + if(c == ')') + c = *str++; + } + if(c == 'e' || c == 'E') + if(*str == 'p' || *str == 'P') { + str++; + c = *str++; + t = TENPAS; + pt = -1; + } + while(c == '+') + c = *str++; + if(c != 0) + return 0; + + c = 0; + for(i=0; mv[i]; i++) { + if(match(mv[i], pf, t, fx, fy, pt, tx, ty)) { + if(moveno & 1) { + bmove(mv[i]); + x = wattack(bkpos); + bremove(); + } else { + wmove(mv[i]); + x = battack(wkpos); + wremove(); + } + if(!x) + continue; + if(c) { + return 0; + } + c = mv[i]; + } + } + return c; +} + +char* +getpie(int *p, int *x, char *str) +{ + char *s; + int kq, rbn, pwn, c; + + kq = 0; + rbn = 0; + pwn = 0; + c = *str++; + for(s = "Q5q5K6k6"; s[0]; s+=2) + if(c == s[0]) { + kq = s[1] - '0'; + c = *str++; + break; + } + for(s = "N2n2B3b3R4r4"; s[0]; s+=2) + if(c == s[0]) { + rbn = s[1] - '0'; + c = *str++; + break; + } + for(s = "P1p1"; s[0]; s+=2) + if(c == s[0]) { + pwn = s[1] - '0'; + str++; + break; + } + str--; + if(pwn) { + *p = pwn; + if(rbn) { + rbn--; + if(rbn == 3) + rbn = 0; + if(kq == 5) + *x = rbn; + else + if(kq == 6) + *x = 7-rbn; + else + *x = 8+rbn; + } else + if(kq) + *x = kq-2; + return str; + } + if(rbn) { + *p = rbn; + if(kq == 5) + *x = 16; + else + if(kq == 6) + *x = 17; + return str; + } + if(kq) + *p = kq; + return str; +} + +char* +getpla(int *x, int *y, char *str) +{ + char *s; + int c; + + c = *str++; + for(s = "Q3q3K4k4"; s[0]; s+=2) + if(c == s[0]) { + *x = s[1] - '0'; + c = *str++; + break; + } + for(s = "R0r0N1n1B2b2"; s[0]; s+=2) + if(c == s[0]) { + if(*x == 3) + *x = s[1]-'0'; + else + if(*x == 4) + *x = 7 - (s[1]-'0'); + else + *x = 8 + (s[1]-'0'); + c = *str++; + break; + } + if(c >= '1' && c <= '8') { + if(moveno & 1) + *y = c-'1'; + else + *y = '8'-c; + return str; + } + str--; + return str; +} + +void +algout(int m, char *str, int f) +{ + short mv[MAXMG]; + + getamv(mv); + xalgout(mv, m, str, f); +} + +void +xalgout(short *mv, int m, char *str, int f) +{ + int p, c, t, fx, fy, tx, ty, i, j, n; + + t = (m>>12) & 017; + c = 0; + if(t == TENPAS || board[m&077]) + c++; + if(t == TOO || t == TOOO) { + *str++ = 'O'; + *str++ = '-'; + *str++ = 'O'; + if(t == TOOO) { + *str++ = '-'; + *str++ = 'O'; + } + goto chk; + } + p = board[(m>>6) & 077] & 7; + tx = (m>>0) & 7; + ty = (m>>3) & 7; + if(t < TNPRO || t > TQPRO) + t = -1; + for(i=0; i<4; i++) { + if(f) + i = 3; + fx = -1; + if((i & 1) || (c && p == 1)) + fx = (m>>6) & 7; + fy = -1; + if((i & 2)) + fy = (m>>9) & 7; + n = 0; + for(j=0; mv[j]; j++) + if(match(mv[j], p, t, fx, fy, -1, tx, ty)) + n++; + + if(n == 1) { + if(f || (p != WPAWN)) + *str++ = "XPNBRQKY"[p]; + if(fx >= 0) + *str++ = 'a'+fx; + if(fy >= 0) + *str++ = '8'-fy; + if(c) + *str++ = ':'; + *str++ = 'a'+tx; + *str++ = '8'-ty; + goto chk; + } + } + *str++ = '?'; + *str++ = '?'; + *str++ = '?'; + *str++ = '?'; + *str = 0; + return; + +chk: + if(t >= TNPRO && t <= TQPRO) + *str++ = "NBRQ"[t-TNPRO]; + cmove(m); + if(check()) { + *str++ = '+'; + if(mate()) + *str++ = '+'; + } + rmove(); + *str = 0; +} + +void +dscout(int m, char *str, int f) +{ + short mv[MAXMG]; + + getamv(mv); + xdscout(mv, m, str, f); +} + +void +xdscout(short *mv, int m, char *str, int f) +{ + int pf, pt, t, fx, fy, tx, ty, i, j, n; + + t = (m>>12) & 017; + if(t == TOO || t == TOOO) { + *str++ = 'O'; + *str++ = '-'; + *str++ = 'O'; + if(t == TOOO) { + *str++ = '-'; + *str++ = 'O'; + } + goto chk; + } + pf = board[(m>>6) & 077] & 7; + pt = board[m&077] & 07; + if(t < TNPRO || t > TQPRO) + t = -1; + for(i=0; i<10; i++) { + if(f) + i = 9; + if(pt) { + /* + * RxR + * RxR/B + * R/NxR + * R/1xR + * RxR/2 + * R/N1xR + * RxR/B2 + * R/QN1xR + * RxR/QB2 + * R/QN1xR/QB2 + */ + setxy("0012030404"[i], m>>6, &fx, &fy); + setxy("0100203044"[i], m>>0, &tx, &ty); + } else { + /* + * R-N5 + * R-QN5 + * R/1-N5 + * R/N-N5 + * R/N1-N5 + * R/1-QN5 + * R/N-QN5 + * R/N1-QN5 + * R/QN1-N5 + * R/QN1-QN5 + */ + setxy("0021321344"[i], m>>6, &fx, &fy); + setxy("3433344434"[i], m>>0, &tx, &ty); + } + n = 0; + for(j=0; mv[j]; j++) + if(match(mv[j], pf, t, fx, fy, pt, tx, ty)) + n++; + + if(n == 1) { + str = putpie(pf, fx, fy, str); + if(pt) { + *str++ = 'x'; + str = putpie(pt, tx, ty, str); + } else { + *str++ = '-'; + str = putpla(tx, ty, str); + } + goto chk; + } + } + *str++ = '?'; + *str++ = '?'; + *str++ = '?'; + *str++ = '?'; + *str = 0; + return; + +chk: + if(t >= TNPRO && t <= TQPRO) { + *str++ = '('; + *str++ = "NBRQ"[t-TNPRO]; + *str++ = ')'; + } + cmove(m); + if(check()) { + *str++ = '+'; + if(mate()) + *str++ = '+'; + } + rmove(); + *str = 0; +} + +void +setxy(int f, int xy, int *x, int *y) +{ + *x = -1; + *y = -1; + xy &= 077; + switch(f) { + case '2': + *y = xy>>3; + break; + + case '3': + *y = xy>>3; + + case '1': + *x = xy & 7; + if(*x >= 5) + *x = 15-*x; + else + if(*x <= 2) + *x = 8+*x; + break; + + case '4': + *x = xy&7; + *y = xy>>3; + break; + } +} + +char* +putpie(int p, int x, int y, char *str) +{ + + if(p == WPAWN && x >= 0 && y < 0) { + str = putpla(x, y, str); + x = -1; + } + *str++ = "XPNBRQKY"[p]; + if(x >= 0 || y >= 0) + *str++ = '/'; + str = putpla(x, y, str); + return str; +} + +char* +putpla(int x, int y, char *str) +{ + + if(x >= 0) { + if(x < 8) { + if(x < 3) + *str++ = 'Q'; + if(x >= 5) + *str++ = 'K'; + *str++ = "RNBQKBNR"[x]; + } else + *str++ = "RNBQK"[x-8]; + } + if(y >= 0) + if(moveno&1) + *str++ = '1'+y; else + *str++ = '8'-y; + return str; +} + +int +mate(void) +{ + short mv[MAXMG]; + + getmv(mv); + return mv[0] == 0; +} + +int +match(int m, int pf, int t, int fx, int fy, int pt, int tx, int ty) +{ + + if(pf >= 0) + if(!mat(pf, board[(m>>6)&077]&7)) + return 0; + if(pt >= 0) + if(!mat(pt, board[m&077]&7)) + return 0; + if(t >= 0) + if(((m>>12)&017) != t) + return 0; + if(fx >= 0) + if(!mat(fx, (m>>6)&7)) + return 0; + if(fy >= 0) + if(!mat(fy, (m>>9)&7)) + return 0; + if(tx >= 0) + if(!mat(tx, (m>>0)&7)) + return 0; + if(ty >= 0) + if(!mat(ty, (m>>3)&7)) + return 0; + return 1; +} + +int +mat(int a, int b) +{ + + if(a < 0) + return 1; + if(a >= 8) { + if(a == 16) { + if(b < 4) + return 1; + return 0; + } + if(a == 17) { + if(b >= 4) + return 1; + return 0; + } + if(a-8 == b) + return 1; + if(15-a == b) + return 1; + return 0; + } + if(a == b) + return 1; + return 0; +} diff -r b1478befa184 -r eab69ba077aa sys/src/cmd/chdb/cmd.y --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/cmd/chdb/cmd.y Mon Apr 12 21:24:07 2021 -0400 @@ -0,0 +1,352 @@ +%{ +#include "ddb.h" +%} +%union { + long lval; + Node* node; + String str; +} + +%token NUMB +%token STRING + +%type pattern p1 p2 p3 p4 +%type expr gexpr wtype pexpr pgexpr fields field mark + +%left '+' '-' + +%% +prog: + command +| prog command + +command: + ';' +| 'd' 'd' ';' + { + tgames -= ngames-1; + lastgame = 0; + memmove(str+1, str+ngames, (tgames-1)*sizeof(Str)); + ngames = tgames; + sortit(0); + sprint(chars, " %ld games", ngames-1); + prline(8); + } +| 'f' 'f' ';' + { + dodupl(); + } +| 'f' NUMB NUMB ';' + { + cinitf1 = $2; + cinitf2 = $3; + chessinit('G', cinitf1, cinitf2); + forcegame(gameno); + } +| 'g' gexpr ';' + { + setgame($2); + } +| 'k' mark ';' + { + if(genmark($2) == 0) + yyerror("illegal mark"); + setmark($2); + } +| 'p' pexpr ';' + { + setposn($2); + } +| pattern ';' + { + if(!yysyntax) { + setmark(0); + search($1, 1, tgames, 1, 0); + sortit(0); + if(!yysyntax) { + sprint(chars, " %ld games", ngames-1); + prline(8); + } + } + } +| 'w' wtype { yystring = -1; } STRING ';' + { + dowrite($2, &cmd[$4.beg]); + } + +wtype: + 'a' + { + $$ = 'a'; + } +| 'f' + { + $$ = 'f'; + } +| 'm' + { + $$ = 'm'; + } +| 'n' + { + $$ = 'n'; + } +| 'r' + { + $$ = 'r'; + } + +gexpr: + expr +| pgexpr + { + $$ = gameno+$1; + } +| '.' + { + $$ = rellast(); + } + +pexpr: + expr + { + $$ = $1*2 - 1; + } +| expr '.' + { + $$ = $1*2 - 0; + } +| pgexpr + { + $$ = curgame.position+$1; + } + +pgexpr: + { + $$ = 1; + } +| '+' + { + $$ = 1; + } +| '-' + { + $$ = -1; + } +| '+' expr + { + $$ = $2; + } +| '-' expr + { + $$ = -$2; + } + +expr: + NUMB +| '(' expr ')' + { + $$ = $2; + } +| expr '+' expr + { + $$ = $1 + $3; + } +| expr '-' expr + { + $$ = $1 - $3; + } + +pattern: + p1 +| '&' p1 + { + $$ = new(Nand); + $$->left = new(Nnull); + $$->right = $2; + } +| '-' p1 + { + $$ = new(Nsub); + $$->left = new(Nnull); + $$->right = $2; + } +| '|' p1 + { + $$ = new(Nor); + $$->left = new(Nnull); + $$->right = $2; + } +| '+' p1 + { + $$ = new(Nor); + $$->left = new(Nnull); + $$->right = $2; + } + +p1: + p2 +| p1 '&' p2 + { + $$ = new(Nand); + $$->left = $1; + $$->right = $3; + } +| p1 p2 + { + $$ = new(Nand); + $$->left = $1; + $$->right = $2; + } + +p2: + p3 +| p2 '|' p3 + { + $$ = new(Nor); + $$->left = $1; + $$->right = $3; + } +| p2 '+' p3 + { + $$ = new(Nor); + $$->left = $1; + $$->right = $3; + } + +p3: + p4 +| p3 '-' p4 + { + $$ = new(Nsub); + $$->left = $1; + $$->right = $3; + } + +p4: + '/' { yystring = '/'; } STRING fields + { + int c; + + c = cmd[$3.end]; + cmd[$3.end] = 0; + $$ = new(Nrex); + $$->rex = regcomp(&cmd[$3.beg]); + $$->field = $4; + cmd[$3.end] = c; + } +| '\'' mark + { + $$ = new(Nmark); + $$->mark = $2; + if(genmark($2) == 0) + yyerror("illegal mark"); + } +| '.' + { + $$ = new(Ngame); + $$->gp = str[gameno].gp; + } +| '*' + { + $$ = new(Nall); + $$->gp = str[gameno].gp; + } +| '[' ']' + { + $$ = new(Nposit); + $$->xor = xorset(0); + } +| '[' expr ']' + { + $$ = new(Nposit); + $$->xor = xorset($2); + } +| '!' p4 + { + $$ = new(Nnot); + $$->left = $2; + } +| '(' p1 ')' + { + $$ = $2; + } + +fields: + { + $$ = 0; + } +| field fields + { + $$ = $1 | $2; + } + +field: + 'f' /* file */ + { + $$ = 1<r); + sortit(1); + + cmdi = 0; + for(;;) { + etype = eread(Emouse|Ekeyboard, &ev); + if(etype & Emouse) { + ogameno = gameno; + str[gameno].position = curgame.position; + if(button(1)) { + if(ptinrect(ev.mouse.xy, d.vbar)) { + i = scroll(&d.vbar, 1, SIZEV, funvu, 1); + if(i < 0) + setgame(ogameno); + } else + if(ptinrect(ev.mouse.xy, d.hbar)) { + i = scroll(&d.hbar, 1, SIZEH, funhu, 0); + if(i < 0) + setgame(ogameno); + } else + if(ptinrect(ev.mouse.xy, d.board)) { + moveselect(1); + } + } else + if(button(2)) { + if(ptinrect(ev.mouse.xy, d.vbar)) { + ogameno = gameno; + i = scroll(&d.vbar, 2, ngames, funv, 1); + if(i < 0) + setgame(ogameno); + } else + if(ptinrect(ev.mouse.xy, d.hbar)) { + i = scroll(&d.hbar, 2, curgame.nmoves+1, funh, 0); + if(i < 0) + setgame(ogameno); + } + } else + if(button(3)) { + if(ptinrect(ev.mouse.xy, d.vbar)) { + ogameno = gameno; + i = scroll(&d.vbar, 3, SIZEV, funvd, 1); + if(i < 0) + setgame(ogameno); + } else + if(ptinrect(ev.mouse.xy, d.hbar)) { + i = scroll(&d.hbar, 3, SIZEH, funhd, 0); + if(i < 0) + setgame(ogameno); + } else { + i = emenuhit(3, &ev.mouse, &men3); + if(i >= 0) { + sortby = i; + sortit(1); + } + } + } + } + if(etype & Ekeyboard) { + r = ev.kbdc; + switch(r) { + default: + if(cmdi < sizeof(cmd)) + cmdi += runetochar(&cmd[cmdi], &r); + break; + + case '\n': + strcpy(chars, ""); + prline(8); + str[gameno].position = curgame.position; + strcpy(chars, cmd); + prline(7); + cmdi = 0; + nodi = 0; + esetcursor(&thinking); + yysyntax = 0; + yyterminal = 0; + yystring = 0; + yyparse(); + freenodes(); + esetcursor(0); + cmdi = 0; + continue; + + case 0x4: + draw(screen, d.screen, screen, nil, d.screen.min); + exits(0); + + case '\b': + if(cmdi > 0) + cmdi--; + break; + } + cmd[cmdi] = 0; + strcpy(chars, cmd); + prline(7); + } + } +} + +void +funv(long n) +{ + setgame(n); +} + +void +funvu(long n) +{ + setgame(ogameno-n-1); +} + +void +funvd(long n) +{ + setgame(ogameno+n+1); +} + +void +funh(long n) +{ + setposn(n); +} + +void +funhu(long n) +{ + setposn(str[gameno].position-n-1); +} + +void +funhd(long n) +{ + setposn(str[gameno].position+n+1); +} + +int +sortorder(Str *a, Str *b) +{ + char *p1, *p2; + + p1 = (char*)a->gp; + p2 = (char*)b->gp; + if(p1 > p2) + return 1; + return -1; +} + +int +sortfile(Str *a, Str *b) +{ + int n; + char *p1, *p2; + + p1 = (char*)a->gp; + p2 = (char*)b->gp; + n = numcmp(p1+Fileoffset, p2+Fileoffset); + if(n) + return n; + n = strcmp(p1+a->whiteoffset, p2+b->whiteoffset); + if(n) + return n; + n = strcmp(p1+a->blackoffset, p2+b->blackoffset); + if(n) + return n; + n = strcmp(p1+a->eventoffset, p2+b->eventoffset); + if(n) + return n; + n = strcmp(p1+a->dateoffset, p2+b->dateoffset); + return n; +} + +int +sortwhite(Str *a, Str *b) +{ + int n; + char *p1, *p2; + + p1 = (char*)a->gp; + p2 = (char*)b->gp; + n = strcmp(p1+a->whiteoffset, p2+b->whiteoffset); + if(n) + return n; + n = strcmp(p1+a->blackoffset, p2+b->blackoffset); + if(n) + return n; + n = strcmp(p1+a->eventoffset, p2+b->eventoffset); + if(n) + return n; + n = strcmp(p1+a->dateoffset, p2+b->dateoffset); + return n; +} + +int +sortblack(Str *a, Str *b) +{ + int n; + char *p1, *p2; + + p1 = (char*)a->gp; + p2 = (char*)b->gp; + n = strcmp(p1+a->blackoffset, p2+b->blackoffset); + if(n) + return n; + n = strcmp(p1+a->whiteoffset, p2+b->whiteoffset); + if(n) + return n; + n = strcmp(p1+a->eventoffset, p2+b->eventoffset); + if(n) + return n; + n = strcmp(p1+a->dateoffset, p2+b->dateoffset); + return n; +} + +int +sortopening(Str *a, Str *b) +{ + int n; + char *p1, *p2; + + p1 = (char*)a->gp; + p2 = (char*)b->gp; + n = strcmp(p1+a->openingoffset, p2+b->openingoffset); + if(n) + return n; + n = strcmp(p1+a->whiteoffset, p2+b->whiteoffset); + if(n) + return n; + n = strcmp(p1+a->blackoffset, p2+b->blackoffset); + if(n) + return n; + n = strcmp(p1+a->eventoffset, p2+b->eventoffset); + if(n) + return n; + n = strcmp(p1+a->dateoffset, p2+b->dateoffset); + return n; +} + +int +sortevent(Str *a, Str *b) +{ + int n; + char *p1, *p2; + + p1 = (char*)a->gp; + p2 = (char*)b->gp; + n = strcmp(p1+a->eventoffset, p2+b->eventoffset); + if(n) + return n; + n = strcmp(p1+a->dateoffset, p2+b->dateoffset); + if(n) + return n; + n = strcmp(p1+a->whiteoffset, p2+b->whiteoffset); + if(n) + return n; + n = strcmp(p1+a->blackoffset, p2+b->blackoffset); + return n; +} + +int +sortdate(Str *a, Str *b) +{ + int n; + char *p1, *p2; + + p1 = (char*)a->gp; + p2 = (char*)b->gp; + n = strcmp(p1+a->dateoffset, p2+b->dateoffset); + if(n) + return n; + n = strcmp(p1+a->eventoffset, p2+b->eventoffset); + if(n) + return n; + n = strcmp(p1+a->whiteoffset, p2+b->whiteoffset); + if(n) + return n; + n = strcmp(p1+a->blackoffset, p2+b->blackoffset); + return n; +} + +void +ereshaped(Box r) +{ + int i, w, h, oside; + + /* + * build screen layout + */ + d.screen = insetrect(r, INSET); + w = (d.screen.max.x - d.screen.min.x) - + (BAR+INSET) - (0); + h = (d.screen.max.y - d.screen.min.y) - + (0) - (INSET+BAR+INSET+NLINE*CHT+0); + i = h; + if(i > w) + i = w; + + /* + * set up d.board + * i is width of board + */ + oside = d.side; + d.side = i/8; + i = d.side*8; + + d.board.min.x = d.screen.min.x + (BAR+INSET); + d.board.max.x = d.board.min.x + i; + d.board.min.y = d.screen.min.y; + d.board.max.y = d.board.min.y + i; + + /* + * set up d.hbar + */ + d.hbar.min.x = d.board.min.x; + d.hbar.max.x = d.board.max.x; + d.hbar.min.y = d.board.max.y + INSET; + d.hbar.max.y = d.hbar.min.y + BAR; + + /* + * set up d.header + */ + d.header.min.x = d.board.min.x; + d.header.max.x = d.screen.max.x - INSET; + d.header.min.y = d.hbar.max.y + INSET; + d.header.max.y = d.header.min.y + NLINE*CHT; + + /* + * set up d.vbar + */ + d.vbar.min.x = d.screen.min.x; + d.vbar.max.x = d.vbar.min.x + BAR; + d.vbar.min.y = d.board.min.y; + d.vbar.max.y = d.board.max.y; + + if(oside != d.side) + for(i=0; piece[i]; i++) { + if(bitpiece[i]) + freeimage(bitpiece[i]); + bitpiece[i] = cdraw(piece[i], d.side); + + } + + draw(screen, d.screen, screen, 0, d.screen.min); + + hdrsize = (d.header.max.x - d.header.min.x) / CHW - 2; + doutline(d.header); + + memset(lastbd, -1, sizeof(lastbd)); + forcegame(gameno); +} + +void +eresized(int new) +{ + if(new) + getwindow(display, new); + ereshaped(screen->r); +} + +void +prline(int line) +{ + Image* bgp; + int l, y; + + y = d.header.min.y + line*CHT - CHT/2; + l = strlen(chars); + if(l < hdrsize) + memset(chars+l, ' ', hdrsize-l); + chars[hdrsize] = 0; + stringbg(screen, + Pt(d.header.min.x + 10, y), display->black, Pt(d.header.min.x + 10, y), + font, chars, display->white, Pt(0,0)); + if(line == 7) + flushimage(display, 1); + +} + +void +forcegame(int gn) +{ + + gameno = -1; + setgame(gn); +} + +void +forceposn(int pn) +{ + + ginit(&initp); + curgame.position = 0; + setposn(pn); +} + +void +setgame(long gn) +{ + + if(gn >= ngames) + gn = ngames-1; + if(gn < 0) + gn = 0; + if(gn == gameno) { + setposn(curgame.position); + return; + } + gameno = gn; + decode(&curgame, &str[gameno]); + setscroll(1); + + forceposn(curgame.position); + + sprint(chars, "file: %s %ld/%ld", curgame.file, gameno, ngames-1); + prline(1); + sprint(chars, "white: %s", curgame.white); + prline(2); + sprint(chars, "black: %s", curgame.black); + prline(3); + sprint(chars, "event: %s %s", curgame.event, curgame.date); + prline(4); + sprint(chars, "result: %s %s", curgame.result, curgame.opening); + prline(5); +} + +void +setposn(int pn) +{ + int i, j, p; + Point pt; + Rectangle r; + Image *pc, *old; + + if(pn > curgame.nmoves) + pn = curgame.nmoves; + if(pn < 0) + pn = 0; + getposn(pn); + + for(i=0; i<8; i++) { + for(j=0; j<8; j++) { + p = board[i*8+j] & 017; + if(p == lastbd[i*8+j]) + continue; + lastbd[i*8+j] = p; + pt = Pt(d.board.min.x+j*d.side, d.board.min.y+i*d.side); + r = Rect(d.board.min.x+j*d.side, d.board.min.y+i*d.side, + d.board.min.x+j*d.side+d.side, + d.board.min.y+i*d.side+d.side); + + pc = bitpiece[12]; /* empty */ + if(p & 7) { /* body */ + pc = bitpiece[(p&7) + 6-1]; + if(p & 010) + pc = bitpiece[(p&7) + 0-1]; + } + /* bitblt(D, pt, pc, pc->r, S); */ + drawop(screen, r, pc, nil, pc->r.min, S); + + old = pc; + + if((i^j) & 1) { /* black square shading */ + pc = bitpiece[(p&7) + 14-1]; + /*bitblt(D, pt, pc, pc->r, DoverS);*/ + drawop(screen, r, pc, old, pc->r.min, SoverD); + } + } + } + doutline(d.board); + +out: + setscroll(0); +} + +void +getposn(int pn) +{ + int i; + + if(pn <= 0 || pn > curgame.nmoves) { + ginit(&initp); + curgame.position = 0; + sprint(chars, "after: init"); + goto out; + } + if(pn < curgame.position-pn) { + ginit(&initp); + curgame.position = 0; + } + pn--; + for(i=curgame.position; i>pn; i--) + rmove(); + for(; i= 5 && strcmp(file+l-5, "m.out") == 0) { + sprint(chars, "%s", file); + fi = open(chars, OREAD); + if(fi < 0) { + sprint(chars, "/lib/chess/%s", file); + fi = open(chars, OREAD); + } + } else { + sprint(chars, "%s.m.out", file); + fi = open(chars, OREAD); + if(fi < 0) { + sprint(chars, "/lib/chess/%s.m.out", file); + fi = open(chars, OREAD); + } + } + if(fi < 0) { + print("cant open %s\n", file); + return -1; + } + return fi; +} + +void +readit(char *file) +{ + long n, m; + int fi; + + fi = openfile(file); + print("reading %s\n", chars); + n = seek(fi, 0, 2); + seek(fi, 0, 0); + if(gsize+n > tgsize) { + if(tgsize == 0) + games = malloc(n); + else + games = realloc(games, gsize+n); + if(games == 0) { + fprint(2, "out of memory\n"); + exits("mem"); + } + tgsize = gsize+n; + } + m = read(fi, &games[gsize/sizeof(short)], n); + if(m != n) { + fprint(2, "short read %ld %ld\n", m, n); + exits("read"); + } + close(fi); + gsize += m; +} + +/* + * go through the games structure + * count the games and byte-swap + */ +long +countgames(void) +{ + uchar *cp; + ushort *sp, *ep; + int n, endianok; + short s; + long ng; + + endianok = 0; + s = (0x01<<8) | 0x02; + cp = (uchar*)&s; + if(cp[0] == 0x01 && cp[1] == 0x02) + endianok = 1; + + sp = &games[0]; + ep = &games[gsize/sizeof(*games)]; + + ng = 0; + while(sp < ep) { + ng++; + cp = (uchar*)sp; + n = (cp[0]<<8) | cp[1]; + *sp++ = n; + sp += n; + if(sp >= ep) + break; + cp = (uchar*)sp; + n = (cp[0]<<8) | cp[1]; + *sp++ = n; + + if(endianok) { + sp += n; + continue; + } + + while(n >= 5) { + n -= 5; + cp = (uchar*)sp; + sp[0] = (cp[0]<<8) | cp[1]; + sp[1] = (cp[2]<<8) | cp[3]; + sp[2] = (cp[4]<<8) | cp[5]; + sp[3] = (cp[6]<<8) | cp[7]; + sp[4] = (cp[8]<<8) | cp[9]; + sp += 5; + } + + while(n > 0) { + n--; + cp = (uchar*)sp; + *sp++ = (cp[0]<<8) | cp[1]; + } + } + return ng; +} + +char fanalys[] = "game0"; +char wanalys[] = "Analysis,W"; +char banalys[] = "Analysis,B"; +char eanalys[] = "Analysis"; +char ranalys[] = "none"; +char oanalys[] = "A00/00 *"; +char danalys[] = "1991"; + +void +buildgames(void) +{ + Str *s; + char *cp; + ushort *p, *ep, *gep; + int n, ch; + ulong b; + + s = str; + ngames = 0; + + /* + * hand-craft game 0 + */ + ngames++; + cp = (char*)g0; + + strcpy(cp + Fileoffset, fanalys); + s->whiteoffset = Fileoffset + + strlen(cp + Fileoffset) + 1; + strcpy(cp + s->whiteoffset, wanalys); + s->blackoffset = s->whiteoffset + + strlen(cp + s->whiteoffset) + 1; + strcpy(cp + s->blackoffset, banalys); + s->eventoffset = s->blackoffset + + strlen(cp + s->blackoffset) + 1; + strcpy(cp + s->eventoffset, eanalys); + s->resultoffset = s->eventoffset + + strlen(cp + s->eventoffset) + 1; + strcpy(cp + s->resultoffset, ranalys); + s->openingoffset = s->resultoffset + + strlen(cp + s->resultoffset) + 1; + strcpy(cp + s->openingoffset, oanalys); + s->dateoffset = s->openingoffset + + strlen(cp + s->openingoffset) + 1; + strcpy(cp + s->dateoffset, danalys); + + n = s->dateoffset + strlen(cp + s->dateoffset) - 1; + if(n & 1) + n++; + g0[0] = n/2; /* shorts worth of strings */ + g0[n+1] = 0; /* shorts worth of moves */ + + s->gp = g0; + s->mark = 0; + s->position = 0; + s++; + + ch = 0; + b = genmark(ch+'a'); + gep = &games[gsizelist[ch]/sizeof(*games)]; + + p = games; + ep = &games[gsize/sizeof(*games)]; + while(p < ep) { + if(p >= gep) { + ch++; + b = genmark(ch+'a'); + gep = &games[gsizelist[ch]/sizeof(*games)]; + if(gsizelist[ch] == 0) + gep = ep; + } + ngames++; + + cp = (char*)p; + + s->gp = p; + s->mark = b; + s->whiteoffset = (strchr(cp + Fileoffset, 0) - cp) + 1; + s->blackoffset = (strchr(cp + s->whiteoffset, 0) - cp) + 1; + s->eventoffset = (strchr(cp + s->blackoffset, 0) - cp) + 1; + s->resultoffset = (strchr(cp + s->eventoffset, 0) - cp) + 1; + s->openingoffset = (strchr(cp + s->resultoffset, 0) - cp) + 1; + s->dateoffset = (strchr(cp + s->openingoffset, 0) - cp) + 1; + s->position = 0; + + s++; + + n = *p; + p += n + 1; + if(p >= ep) + break; + n = *p; + p += n + 1; + } +} + +void +decode(Game *g, Str *s) +{ + ushort *p; + char *cp; + int n; + + p = s->gp; + cp = (char*)p; + + g->file = cp + Fileoffset; + g->white = cp + s->whiteoffset; + g->black = cp + s->blackoffset; + g->event = cp + s->eventoffset; + g->result = cp + s->resultoffset; + g->opening = cp + s->openingoffset; + g->date = cp + s->dateoffset; + g->position = s->position; + + n = *p; + p += n + 1; + n = *p; + g->moves = (short*)(p + 1); + g->nmoves = n; +} + +void +doutline(Box x) +{ +/* segment(D, Pt(x.min.x, x.min.y), + Pt(x.max.x, x.min.y), ~0, DoverS); + segment(D, Pt(x.max.x, x.min.y), + Pt(x.max.x, x.max.y), ~0, DoverS); + segment(D, Pt(x.max.x, x.max.y), + Pt(x.min.x, x.max.y), ~0, DoverS); + segment(D, Pt(x.min.x, x.max.y), + Pt(x.min.x, x.min.y), ~0, DoverS); +*/ + lineop(screen,Pt(x.min.x, x.min.y), + Pt(x.max.x, x.min.y), + Endsquare, Endsquare, 0, + display->black, Pt(x.min.x, x.min.y), S); + lineop(screen,Pt(x.max.x, x.min.y), + Pt(x.max.x, x.max.y), + Endsquare, Endsquare, 0, + display->black, Pt(x.max.x, x.min.y), S); + lineop(screen,Pt(x.max.x, x.max.y), + Pt(x.min.x, x.max.y), + Endsquare, Endsquare, 0, + display->black, Pt(x.max.x, x.max.y), S); + lineop(screen,Pt(x.min.x, x.max.y), + Pt(x.min.x, x.min.y), + Endsquare, Endsquare, 0, + display->black, Pt(x.min.x, x.max.y), S); +} + +int +button(int n) +{ + + return ev.mouse.buttons & (1<<(n-1)); +} + +void +setscroll(int vert) +{ + Box s; + int xy1, xy2, xy3; + long pos1, pos2, tot; + + if(vert) + goto dovert; + +dohoriz: + s = d.hbar; + /* bitblt(D, s.min, D, s, 0xf); */ + drawop(screen, s, display->black, 0, s.min, S); + pos1 = curgame.position; + pos2 = pos1 + 1; + tot = curgame.nmoves+1-1 + 1; + if(tot <= 0) + tot = 1; + xy1 = d.hbar.max.x - d.hbar.min.x; + + xy2 = (pos1 * xy1) / tot; + if(xy2 < 0) + xy2 = 0; + if(xy2 > xy1) + xy2 = xy1; + s.min.x = d.hbar.min.x + xy2; + + xy3 = (pos2 * xy1) / tot; + if(xy3 <= xy2) + xy3 = xy2+1; + if(xy3 < 0) + xy3 = s.min.x; + if(xy3 > xy1) + xy3 = xy1; + s.max.x = d.hbar.min.x + xy3; + goto out; + +dovert: + s = d.vbar; + /* bitblt(D, s.min, D, s, 0xf); */ + drawop(screen, s, display->black, 0, s.min, S); + pos1 = gameno; + pos2 = pos1 + SIZEV; + tot = ngames-1 + SIZEV; + if(tot <= 0) + tot = 1; + xy1 = d.vbar.max.y - d.vbar.min.y; + + xy2 = (pos1 * xy1) / tot; + if(xy2 < 0) + xy2 = 0; + if(xy2 > xy1) + xy2 = xy1; + s.min.y = d.vbar.min.y + xy2; + + xy3 = (pos2 * xy1) / tot; + if(xy3 <= xy2) + xy3 = xy2+1; + if(xy3 < 0) + xy3 = 0; + if(xy3 > xy1) + xy3 = xy1; + s.max.y = d.vbar.min.y + xy3; + goto out; + +out: + /* bitblt(D, s.min, D, s, 0x0); */ + drawop(screen, s, display->white, 0, s.min, S); + return; +} + +long +scroll(Box *bar, int but, long tot, void (*fun)(long), int vert) +{ + Box s; + int in, x, y, oxy; + long pos, opos; + + pos = -1; + oxy = -1; + opos = -1; + s = insetrect(*bar, 1); + if(vert) + goto dovert; + +dohoriz: + y = bar->min.y + BAR/2; + do { + in = abs(ev.mouse.xy.y-y) <= BAR/2; + while(in) { + x = ev.mouse.xy.x; + if(x < s.min.x) + x = s.min.x; + if(x >= s.max.x) + x = s.max.x; + if(!eqpt(ev.mouse.xy, Pt(x, y))) + emoveto(Pt(x, y)); + if(x == oxy) + break; + oxy = x; + pos = (tot * (x - bar->min.x)) / (bar->max.x - bar->min.x); + if(pos == opos) + break; + opos = pos; + (*fun)(pos); + break; + } + eread(Emouse, &ev); + } while(button(but)); + if(!in) + pos = -1; + return pos; + +dovert: + x = bar->min.x + BAR/2; + do { + in = abs(ev.mouse.xy.x-x) <= BAR/2; + while(in) { + y = ev.mouse.xy.y; + if(y < s.min.y) + y = s.min.y; + if(y >= s.max.y) + y = s.max.y; + if(!eqpt(ev.mouse.xy, Pt(x, y))) + emoveto(Pt(x, y)); + if(y == oxy) + break; + oxy = y; + pos = (tot * (y - bar->min.y)) / (bar->max.y - bar->min.y); + if(pos == opos) + break; + opos = pos; + (*fun)(pos); + break; + } + eread(Emouse, &ev); + } while(button(but)); + if(!in) + pos = -1; + return pos; +} + +void +sortit(int think) +{ + + if(think) + esetcursor(&thinking); + qsort(str+1, ngames-1, sizeof(Str), + (sortby==Byorder)? sortorder: + (sortby==Byfile)? sortfile: + (sortby==Bywhite)? sortwhite: + (sortby==Byblack)? sortblack: + (sortby==Byevent)? sortevent: + (sortby==Byopening)? sortopening: + (sortby==Bydate)? sortdate: + 0); + forcegame(1); + if(think) + esetcursor(0); +} + +int +numcmp(char *a, char *b) +{ + char c1, c2; + int n; + + for(;;) { + c1 = *a++; + c2 = *b++; + n = c1 - c2; + if(n) + break; + if(c1 == 0) + return 0; + } + for(;;) { + if(!isdigit(c1)) { + if(isdigit(c2)) + return -1; + return n; + } + if(!isdigit(c2)) + return 1; + c1 = *a++; + c2 = *b++; + } + return 0; +} + +void +light(int loc) +{ + Box r; + + r.min.x = d.board.min.x + (loc&7)*d.side; + r.min.y = d.board.min.y + ((loc>>3)&7)*d.side; + r.max.x = r.min.x + d.side - 1; + r.max.y = r.min.y + d.side - 1; + doutline(r); + r = insetrect(r, 1); + doutline(r); + lastbd[loc] = -1; +} + +int +mvcmp(short *a, short *b) +{ + int f1, f2; + + f1 = FROM(*a); + f2 = FROM(*b); + return (board[f1]&7) - (board[f2]&7); +} + +void +moveselect(int but) +{ + int to, fr, m, i, j; + short mv[MAXMG]; + + i = (ev.mouse.xy.x - d.board.min.x) / d.side; + j = (ev.mouse.xy.y - d.board.min.y) / d.side; + to = j*8 + i; + + getmv(mv); + j = board[to]; + if(j & 7) + if(curgame.position & 1) { + if(j & BLACK) + goto searchfrom; + } else + if(!(j & BLACK)) + goto searchfrom; + j = 0; + for(i=0; m=mv[i]; i++) + if(to == TO(m)) + mv[j++] = m; + mv[j] = 0; + qsort(mv, j, sizeof(short), mvcmp); + if(m = mv[0]) { + light(TO(m)); + light(FROM(m)); + } + + do { + eread(Emouse, &ev); + } while(button(but)); + + i = (ev.mouse.xy.x - d.board.min.x) / d.side; + j = (ev.mouse.xy.y - d.board.min.y) / d.side; + fr = j*8 + i; + if(fr == to) + fr = FROM(mv[0]); + + m = 0; + for(i=0; j=mv[i]; i++) + if(fr == FROM(j)) + m = j; + goto mkmove; + +searchfrom: + fr = to; + j = 0; + for(i=0; m=mv[i]; i++) + if(fr == FROM(m)) + mv[j++] = m; + mv[j] = 0; + + do { + eread(Emouse, &ev); + } while(button(but)); + + i = (ev.mouse.xy.x - d.board.min.x) / d.side; + j = (ev.mouse.xy.y - d.board.min.y) / d.side; + to = j*8 + i; + + m = 0; + for(i=0; j=mv[i]; i++) + if(to == TO(j)) + m = j; + goto mkmove; + +mkmove: + if(m == 0) { + setgame(gameno); + return; + } + if(gameno != 0) { + memmove(&g0[g0[0]+2], curgame.moves, curgame.position*sizeof(ushort)); + str->position = curgame.position; + lastgame = str[gameno].gp; + } + g0[g0[0]+str->position+2] = m; + str->position++; + g0[g0[0]+1] = str->position; + forcegame(0); +} diff -r b1478befa184 -r eab69ba077aa sys/src/cmd/chdb/ddb.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/cmd/chdb/ddb.h Mon Apr 12 21:24:07 2021 -0400 @@ -0,0 +1,237 @@ +/* + * wish list: + * snarf and text select + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "gen.h" + +enum +{ + NLINE = 9, /* number of print lines in header box */ + INSET = 5, /* pixel width of 'tween' space */ + BAR = 12, /* pixel width of scroll bar */ + CHT = 18, /* pixel height of char */ + CHW = 9, /* pixel width of char */ + SIZEV = 8, /* button 1,3 max width, vert */ + SIZEH = 8, /* button 1,3 max width, horiz */ + STRSIZE = 200, /* size of string manipulation buf */ + CMDSIZE = 200, /* size of command buf */ + NODESIZE = 100, /* size of node freelist */ + + End = -1000, + Fileoffset = 2, + + Byorder = 0, + Byfile, + Bywhite, + Byblack, + Byevent, + Byopening, + Bydate, + Blast, + Byresult, + + Nnull = 0, + Nrex, + Nmark, + Nand, + Nor, + Nsub, + Nnot, + Ngame, + Nposit, + Nall, +}; + +#define coffsetof(t,x) ((ulong)&((t*)0)->x) +/* define D (&screen) */ +#define FROM(x) (((x)>>6)&077) +#define TO(x) (((x)>>0)&077) + +typedef struct Game Game; +typedef struct String String; +typedef struct Str Str; +typedef struct Node Node; +typedef struct Xor Xor; +typedef Rectangle Box; + +struct String +{ + int beg; + int end; +}; +struct Game +{ + char* file; + char* white; + char* black; + char* event; + char* result; + char* opening; + char* date; + short* moves; + short nmoves; + short position; +}; +struct Str +{ + ushort* gp; + ulong mark; + + short position; + char whiteoffset; + char blackoffset; + + char eventoffset; + char resultoffset; + char openingoffset; + char dateoffset; + +}; +struct Node +{ + int op; + union + { + struct + { + /* op = Nrex */ + Reprog* rex; + long field; + }; + struct + { + /* op = Nmark */ + int mark; + }; + struct + { + /* op = N */ + Node* left; + Node* right; + }; + struct + { + /* op = Ngame */ + ushort* gp; + }; + struct + { + /* op = Nposit */ + Xor* xor; + }; + }; +}; +struct Xor +{ + long cursize; + long maxsize; + long mask; + ulong words[10]; +}; + +struct +{ + Box screen; + Box board; + Box vbar; + Box hbar; + Box header; + int side; +} d; + +Image* bitpiece[20]; +char chars[STRSIZE]; +char cmd[CMDSIZE]; +int cmdi; +long gsizelist[30]; +Game curgame; +Event ev; +long gameno; +ushort* games; +long gsize; +long tgsize; +int hdrsize; +char lastbd[64]; +char mklist[8]; +Menu men3; +char* men3l[]; +long ngames; +Node nodes[NODESIZE]; +int nodi; +int numcmp(char*, char*); +int ogameno; +short* piece[]; +int pipefid[2]; +int printcol; +int sortby; +Str* str; +ushort* lastgame; +long tgames; +Cursor thinking; +char word[CMDSIZE]; +ulong xora[16*64]; +ulong xorb[16*64]; +ulong initpxora; +ulong initpxorb; +ulong btmxora; +ulong btmxorb; +char xbd[64]; +char xpc[32]; +ulong xposxor; /* side effect of calling posxor[wb] */ +ushort g0[1000]; +int yystring; /* looking for a string delim */ +int yyterminal; /* flag between ';' and $eof */ +int yysyntax; /* syntax has happened */ +int cinitf1; /* chessinit arg 1 */ +int cinitf2; /* chessinit arg 2 */ + +void buildgames(void); +int button(int); +long countgames(void); +void decode(Game*, Str*); +void dodupl(void); +void doutline(Box); +void dowrite(int, char*); +Image* cdraw(short*, int); +void ereshaped(Box); +void forcegame(int); +void freenodes(void); +void funh(long); +void funhd(long); +void funhu(long); +void funv(long); +void funvd(long); +void funvu(long); +ulong genmark(int); +void getposn(int); +long getshort(void); +Node* new(int); +int openfile(char*); +ulong posxorb(void); +ulong posxorw(void); +void prline(int); +void readit(char*); +long scroll(Box*, int, long, void (*)(long), int); +void search(Node*, long, long, long, int); +void setgame(long); +void setmark(int); +void setposn(int); +void setscroll(int); +void sortit(int); +void xorinit(void); +Xor* xorset(int); +void yyerror(char*, ...); +int yylex(void); +int yyparse(void); +void moveselect(int); +long rellast(void); diff -r b1478befa184 -r eab69ba077aa sys/src/cmd/chdb/draw.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/cmd/chdb/draw.c Mon Apr 12 21:24:07 2021 -0400 @@ -0,0 +1,287 @@ +#include "ddb.h" + +static +struct +{ + char* sq1; + char* sq2; + long sidesq; + int side; +} w; + + +void doline(char*, int, int, int, int); +void doflood(char*); +void dofill(char*, int, int); +Image* dobitmap(char*, char*); +void dopict(char*); + +Image* +cdraw(short *vec, int side) +{ + int i, j; + int x1, x2, y1, y2; + char *p, *q; + + /* + * allocate + */ + if(w.side != side) { + w.side = side; + w.sidesq = side*side; + if(w.sq1 == 0) { + w.sq1 = malloc(w.sidesq); + w.sq2 = malloc(w.sidesq); + } else { + w.sq1 = realloc(w.sq1, w.sidesq); + w.sq2 = realloc(w.sq2, w.sidesq); + } + if(!w.sq1 || !w.sq2) { + fprint(2, "malloc of square failed\n"); + exits("malloc"); + } + } + memset(w.sq1, 0, w.sidesq); + + for(i=0; vec[i]!=End; i=j+1) { + /* + * scale the vector + * draw the outline in sq2 (value=1) + */ + memset(w.sq2, 0, w.sidesq); + + x1 = vec[i+0]; + x1 = (x1*w.side + 256) / 512; + y1 = 511-vec[i+1]; + y1 = (y1*w.side + 256) / 512; + + for(j=i+2; vec[j]!=End; j+=2) { + x2 = vec[j+0]; + x2 = (x2*w.side + 256) / 512; + y2 = 511-vec[j+1]; + y2 = (y2*w.side + 256) / 512; + doline(w.sq2, x1, y1, x2, y2); + x1 = x2; + y1 = y2; + } + + /* + * fill outside outline in sq2 (value=2) + */ + doflood(w.sq2); + + /* + * xor the boxes together to make piece + */ + p = w.sq1; + q = w.sq2; + for(i=0; i= side) a1 = side-1; + a2 = y; if(a2 < 0) a2 = 0; if(a2 >= side) a2 = side-1; + sq[a2*side + a1] = 1; + + if(x == x2 && y == y2) + break; + a1 = dy * (x2-x-ix) - dx * (y2-y); + if(a1 < 0) + a1 = -a1; + a2 = dy * (x2-x) - dx * (y2-y-iy); + if(a2 < 0) + a2 = -a2; + a3 = dy * (x2-x-ix) - dx * (y2-y-iy); + if(a3 < 0) + a3 = -a3; + if(a1 < a2) { + x += ix; + if(a3 <= a1) + y += iy; + } else { + y += iy; + if(a3 <= a2) + x += ix; + } + } +} + +void +doflood(char *sq) +{ + char *p, *q; + int j, side; + + /* + * gross fill + */ + side = w.side; + p = sq; + for(j=0; j 0) + if(sq[v-1] == 0) + dofill(sq, x-1, y); + if(x < side-1) + if(sq[v+1] == 0) + dofill(sq, x+1, y); + if(y > 0) + if(sq[v-side] == 0) + dofill(sq, x, y-1); + if(y < side-1) + if(sq[v+side] == 0) + dofill(sq, x, y+1); +} + +void +dopict(char *sq) +{ + int i, j; + char x[500]; + + for(i=0; i 0 && x[j-1] == ' ') + j--; + x[j] = 0; + print("%s\n", x); + } + print("\n"); +} + +Image* +dobitmap(char *p, char *t) +{ + Image *b; + Rectangle r; + char *q; + int i, j, b1, b0; + + r.min.x = 0; + r.min.y = 0; + r.max.x = w.side; + r.max.y = w.side; + b = allocimage(display, r, GREY1, 0, DTransparent); + if(b == 0) { + fprint(2, "allocimage failed\n"); + exits("allocimage"); + } + + q = t; + for(i=0; i>= 1; + if(b1 == 0) { + *q++ = ~b0; + b0 = 0; + b1 = 1<<7; + } + p++; + } + if(b1 != (1<<7)) + *q++ = ~b0; + } + if(loadimage(b, r, (uchar*)t, w.sidesq)<1) + perror("chdb: dobitmap"); + return b; +} diff -r b1478befa184 -r eab69ba077aa sys/src/cmd/chdb/gen.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/cmd/chdb/gen.h Mon Apr 12 21:24:07 2021 -0400 @@ -0,0 +1,130 @@ +#ifndef MAXMV +#define MAXMV 500 +#endif +#ifndef MAXMG +#define MAXMG 150 +#endif + +enum +{ + WPAWN = 1, + WKNIGHT, + WBISHOP, + WROOK, + WQUEEN, + WKING, + + BPAWN = 9, + BKNIGHT, + BBISHOP, + BROOK, + BQUEEN, + BKING, + + BLACK = 8, + INIT = 16, + AMARK = 040000, + EPMARK = 020000, + + TMARK = 0, + TNORM, + TEPENAB, + TOOO, + TOO, + TNPRO, + TBPRO, + TRPRO, + TQPRO, + TENPAS, + TNULL = 15, + + U1 = 0x01, + U2 = 0x02, + L1 = 0x04, + L2 = 0x08, + D1 = 0x10, + D2 = 0x20, + R1 = 0x40, + R2 = ~0x80+1, + + ULEFT = U1|L1, + URIGHT = U1|R1, + DLEFT = D1|L1, + DRIGHT = D1|R1, + LEFT = L1, + RIGHT = R1, + UP = U1, + DOWN = D1, + U2R1 = U1|U2|R1, + U1R2 = U1|R1|R2, + D1R2 = D1|R1|R2, + D2R1 = D1|D2|R1, + D2L1 = D1|D2|L1, + D1L2 = D1|L1|L2, + U1L2 = U1|L1|L2, + U2L1 = U1|U2|L1, + RANK2 = D2, + RANK7 = U2, +}; + +short* lmp; +short* amp; +short ambuf[MAXMV*2 + 10]; +int moveno; +int eppos; +int bkpos; +int wkpos; +char board[64]; +short mvlist[MAXMV]; +int mvno; +extern schar dir[]; +extern schar attab[]; +extern schar color[]; + +typedef +struct +{ + char bd[64]; + short epp; + short mvno; + short mv[1]; +} Posn; +Posn initp; + +extern void ginit(Posn*); +extern void gstore(Posn*); +extern void getamv(short*); +extern void getmv(short*); +extern void cmove(int); +extern void qmove(int); +extern int rmove(void); +extern int retract(int); +extern int check(void); +extern void wgen(void); +extern int wcheck(int, int, int); +extern void wmove(int); +extern void wremove(void); +extern int battack(int); +extern void bgen(void); +extern int bcheck(int, int, int); +extern void bmove(int); +extern void bremove(void); +extern int wattack(int); + +extern void chessinit(int, int, int); +extern int chessfmt(Fmt*); +extern int chessin(char*); +extern int xalgin(short*, char*); +extern int xdscin(short*, char*); +extern char* getpie(int*, int*, char*); +extern char* getpla(int*, int*, char*); +extern void algout(int, char*, int); +extern void xalgout(short*, int, char*, int); +extern void dscout(int, char*, int); +extern void xdscout(short*, int, char*, int); +extern void setxy(int, int, int*, int*); +extern char* putpie(int, int, int, char*); +extern char* putpla(int, int, char*); +extern int mate(void); +extern int match(int, int, int, int, int, int, int, int); +extern int mat(int, int); diff -r b1478befa184 -r eab69ba077aa sys/src/cmd/chdb/lex.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/cmd/chdb/lex.c Mon Apr 12 21:24:07 2021 -0400 @@ -0,0 +1,98 @@ +#include "ddb.h" +#include "y.tab.h" + +int +yylex(void) +{ + int c, e; + Rune r; + long n; + + if(yysyntax || yyterminal) + return -1; + + if(yystring) { + yylval.str.beg = cmdi; + n = 0; /* inside [] */ + e = 0; /* escape */ + for(;;) { + c = chartorune(&r, &cmd[cmdi]); + if(e == 0 && n == 0 && r == '[') + n = 1; + if(e == 0 && n == 1 && r == ']') + n = 0; + if(e == 0 && n == 0 && r == yystring) { + yylval.str.end = cmdi; + cmdi += c; + break; + } + if(e == 0 && r == '\\') + e = 1; + else + e = 0; + if(r == 0) { + yylval.str.end = cmdi; + break; + } + cmdi += c; + } + yystring = 0; + return STRING; + } + +loop: + cmdi += chartorune(&r, &cmd[cmdi]); + c = r; + yylval.lval = c; + + switch(c) { + case 0: + yyterminal = 1; + return ';'; + + case ' ': + case '\t': + goto loop; + + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + n = c - '0'; + for(;;) { + c = cmd[cmdi]; + if(c >= '0' && c <= '9') { + cmdi++; + n = n*10 + c-'0'; + continue; + } + yylval.lval = n; + return NUMB; + } + } + return c; +} + +void +yyerror(char *fmt, ...) +{ + char *p1, *p2; + + if(yysyntax) + return; + yysyntax = 1; + strcpy(chars, cmd); + p1 = chars+cmdi; + p2 = strchr(p1, 0)+1; + memmove(p1+1, p1, p2-p1); + *p1 = '\\'; + prline(7); + seprint(chars, chars+sizeof(chars), fmt, &fmt+1); + prline(8); +} diff -r b1478befa184 -r eab69ba077aa sys/src/cmd/chdb/mkfile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/cmd/chdb/mkfile Mon Apr 12 21:24:07 2021 -0400 @@ -0,0 +1,26 @@ +cursize; k+=2) + if(xp->words[k+0] == initpxora) + if(xp->words[k+1] == initpxorb) + init++; + mw = &xp->words[xp->cursize]; + mask = xp->mask; + ngames = ng; + s = &str[lb]; + for(i=lb; iposition = 0; + f = 1; + } + decode(&g, s); + ginit(&initp); + gp = g.moves; + xa = initpxora; + xb = initpxorb; + for(j=0; j>6) & 077; + to = (mov>>0) & 077; + + p = board[to] & 017; + xa ^= xora[(p<<6) | to]; /* old to */ + xb ^= xorb[(p<<6) | to]; + + p = board[from] & 017; + xa ^= xora[(p<<6) | from]; /* old from */ + xb ^= xorb[(p<<6) | from]; + + xa ^= xora[(p<<6) | to]; /* new to */ + xb ^= xorb[(p<<6) | to]; + xa ^= xora[from]; /* new from */ + xb ^= xorb[from]; + + board[to] = p; + board[from] = 0; + + typ = (mov>>12) & 017; + switch(typ) { + case TNPRO: + xa ^= xora[(p<<6) | to]; /* old to */ + xb ^= xorb[(p<<6) | to]; + p = WKNIGHT | (p&BLACK); + xa ^= xora[(p<<6) | to]; /* new to */ + xb ^= xorb[(p<<6) | to]; + board[to] = p; + break; + case TBPRO: + xa ^= xora[(p<<6) | to]; /* old to */ + xb ^= xorb[(p<<6) | to]; + p = WBISHOP | (p&BLACK); + xa ^= xora[(p<<6) | to]; /* new to */ + xb ^= xorb[(p<<6) | to]; + board[to] = p; + break; + case TRPRO: + xa ^= xora[(p<<6) | to]; /* old to */ + xb ^= xorb[(p<<6) | to]; + p = WROOK | (p&BLACK); + xa ^= xora[(p<<6) | to]; /* new to */ + xb ^= xorb[(p<<6) | to]; + board[to] = p; + break; + case TQPRO: + xa ^= xora[(p<<6) | to]; /* old to */ + xb ^= xorb[(p<<6) | to]; + p = WQUEEN | (p&BLACK); + xa ^= xora[(p<<6) | to]; /* new to */ + xb ^= xorb[(p<<6) | to]; + board[to] = p; + break; + case TOO: + from = to+1; + to--; + goto mv; + case TOOO: + from = to-2; + to++; + mv: + p = board[to] & 017; + xa ^= xora[(p<<6) | to]; /* old to */ + xb ^= xorb[(p<<6) | to]; + + p = board[from] & 017; + xa ^= xora[(p<<6) | from]; /* old from */ + xb ^= xorb[(p<<6) | from]; + + xa ^= xora[(p<<6) | to]; /* new to */ + xb ^= xorb[(p<<6) | to]; + xa ^= xora[from]; /* new from */ + xb ^= xorb[from]; + + board[to] = p; + board[from] = 0; + break; + case TENPAS: + if(j & 1) + to -= 8; + else + to += 8; + p = board[to] & 017; + xa ^= xora[(p<<6) | to]; /* old to */ + xb ^= xorb[(p<<6) | to]; + xa ^= xora[to]; /* new to */ + xb ^= xorb[to]; + board[to] = 0; + break; + } + if(mw[(xa>>5) & mask] & (1 << (xa&31))) { + k1 = 0; + k2 = xp->cursize; + for(;;) { + k = ((k1+k2) / 4) * 2; + if(k <= k1) + break; + if(xa > xp->words[k+0]) { + k1 = k; + continue; + } + if(xa < xp->words[k+0]) { + k2 = k; + continue; + } + if(xb >= xp->words[k+1]) { + k1 = k; + continue; + } + k2 = k; + } + if(xa == xp->words[k+0]) + if(xb == xp->words[k+1]) { + s->position = j+1; + f = 1; + } + } + } + if(inv) + f = !f; + if(f) { + tmp = *s; + *s = str[ngames]; + str[ngames] = tmp; + ngames++; + } + } +} + +void +searchre(Reprog *re, long afield, long lb, long hb, long ng, int inv) +{ + Str *s, tmp; + long i, field, j; + Game g; + char *fld; + int f; + + if(afield == 0) + afield = (1<mark & b)) { + tmp = *s; + *s = str[ngames]; + str[ngames] = tmp; + ngames++; + } + } else { + for(i=lb; imark & b) { + tmp = *s; + *s = str[ngames]; + str[ngames] = tmp; + ngames++; + } + } +} + +void +searchgp(ushort *gp, long lb, long hb, long ng, int inv) +{ + Str *s, tmp; + long i; + + ngames = ng; + s = &str[lb]; + if(inv) { + for(i=lb; igp != gp) { + tmp = *s; + *s = str[ngames]; + str[ngames] = tmp; + ngames++; + } + } else { + for(i=lb; igp == gp) { + tmp = *s; + *s = str[ngames]; + str[ngames] = tmp; + ngames++; + } + } +} + +void +searchall(ushort *gp, long lb, long hb, long ng, int inv) +{ + Str *s, tmp; + long i; + + USED(gp); + ngames = ng; + s = &str[lb]; + if(!inv) + for(i=lb; iop) { + default: + yyerror("unknown search"); + break; + case Nnull: + break; + case Nmark: + searchmark(n->mark, lb, hb, ng, inv); + break; + case Nrex: + searchre(n->rex, n->field, lb, hb, ng, inv); + break; + case Ngame: + searchgp(n->gp, lb, hb, ng, inv); + break; + case Nall: + searchall(n->gp, lb, hb, ng, inv); + break; + case Nposit: + searchposit(n->xor, lb, hb, ng, inv); + break; + + case Nand: + if(inv) + goto or; + and: + search(n->left, lb, hb, ng, inv); + search(n->right, ng, ngames, ng, inv); + break; + case Nor: + if(inv) + goto and; + or: + search(n->left, lb, hb, ng, inv); + search(n->right, ngames, hb, ngames, inv); + break; + case Nsub: + search(n->left, lb, hb, ng, inv); + search(n->right, ng, ngames, ng, !inv); + break; + case Nnot: + search(n->left, lb, hb, ng, !inv); + break; + } +} + +void +setmark(int ch) +{ + long i; + Str *s; + ulong b; + + b = genmark(ch); + s = str; + for(i=0; imark |= b; + b = ~b; + for(; imark &= b; +} + +long +rellast(void) +{ + long i; + Str *s; + + s = str; + for(i=0; igp == lastgame) + return i; + return 0; +} + +void +regerror(char *s) +{ + char buf[STRSIZE]; + + sprint(buf, "reg: %s", s); + yyerror(buf); +} + +Node* +new(int op) +{ + Node *n; + + n = nodes+nodi; + nodi++; + if(nodi >= NODESIZE) { + yyerror("too many nodes"); + n = nodes; + } + memset(n, 0, sizeof(Node)); + n->op = op; + return n; +} + +void +freenodes(void) +{ + int i; + Node *n; + + n = &nodes[0]; + for(i=0; iop == Nrex) + if(n->rex) + free(n->rex); + if(n->op == Nposit) + if(n->xor) + free(n->xor); + } +} + +void +xorinit(void) +{ + int i; + + for(i=0; i> 8; + xorb[i] = lrand() >> 8; + xora[i] ^= lrand() << 8; + xorb[i] ^= lrand() << 8; + } + for(i=0; i<64; i++) { + xora[(010<<6)|i] = xora[(000<<6)|i]; + xorb[(010<<6)|i] = xorb[(000<<6)|i]; + } + btmxora = lrand() >> 8; + btmxorb = lrand() >> 8; + btmxora ^= lrand() << 8; + btmxorb ^= lrand() << 8; + + ginit(&initp); + initpxora = posxorw(); + initpxorb = xposxor; + + for(i=0; icursize + 4; + if(k > xp->maxsize) { + xp->maxsize += 1000; + xp = realloc(xp, sizeof(Xor) + xp->maxsize*sizeof(ulong)); + } + xp->words[k-4] = posxorw(); + xp->words[k-3] = xposxor; + xp->words[k-2] = posxorb(); + xp->words[k-1] = xposxor; + xp->cursize = k; + } + if(d > 0) + xp = xoradd(xp, d-1); + rmove(); + } + return xp; +} + +int +xcmp(ulong *a, ulong *b) +{ + + if(*a > *b) + return 1; + if(*a < *b) + return -1; + a++; b++; + if(*a > *b) + return 1; + if(*a < *b) + return -1; + return 0; +} + +int +ycmp(ulong *a, ulong *b) +{ + ushort* g1, *g2; + + if(*a > *b) + return 1; + if(*a < *b) + return -1; + a++; b++; + if(*a > *b) + return 1; + if(*a < *b) + return -1; + a++; b++; + g1 = (*(Str**)a)->gp; + g2 = (*(Str**)b)->gp; + if(g1 < g2) + return 1; + if(g1 > g2) + return -1; + return 0; +} + +Xor* +xorset(int d) +{ + Xor *xp; + ulong x, *mw; + long i, j, sz; + + xp = malloc(sizeof(Xor)); + xp->maxsize = nelem(xp->words); + xp->cursize = 0; + if(FLAG || d == 0) { + xp->words[0] = posxorb(); + xp->words[1] = xposxor; + xp->words[2] = posxorw(); + xp->words[3] = xposxor; + xp->cursize = 4; + } + if(d > 0) + xp = xoradd(xp, d-1); + + qsort(xp->words, xp->cursize/2, 2*sizeof(ulong), xcmp); + j = 0; + for(i=2; icursize; i+=2) + if(xp->words[j+0] != xp->words[i+0] || + xp->words[j+1] != xp->words[i+1]) { + j += 2; + xp->words[j+0] = xp->words[i+0]; + xp->words[j+1] = xp->words[i+1]; + } + xp->cursize = j+2; + + for(sz=1; sz; sz<<=1) + if(sz >= xp->cursize) + break; + if(xp->cursize+sz > xp->maxsize) { + xp->maxsize = xp->cursize+sz; + xp = realloc(xp, sizeof(Xor) + xp->maxsize*sizeof(ulong)); + } + + mw = &xp->words[xp->cursize]; + memset(mw, 0, sz); + + sz--; + xp->mask = sz; + for(i=xp->cursize-2; i>=0; i-=2) { + x = xp->words[i]; + mw[((x>>5) & sz)] |= 1 << (x&31); + } + + sprint(chars, " %ld positions", xp->cursize/4); + prline(8); + return xp; +} + +int +bputs(Biobuf *b, char *s) +{ + int t; + + t = strlen(s); + Bwrite(b, s, t); + return t; +} + +void +dowrite(int ch, char *name) +{ + int f, j, k, m; + Biobuf buf; + long i, n, t, nw; + Str *s; + ushort *sp; + Game g; + + while(*name == ' ') + name++; + + switch(ch) { + default: + yyerror("unknown write type"); + return; + case 'a': /* ascii */ + case 'f': /* figurine */ + if(*name == 0) + name = "wa.out"; + break; + case 'n': /* nroff */ + if(*name == 0) + name = "wn.out"; + break; + case 'm': /* binary */ + if(*name == 0) + name = "wm.out"; + break; + case 'r': /* result only */ + if(*name == 0) + name = "wr.out"; + break; + } + f = create(name, OWRITE, 0666); + if(f < 0) { + yyerror("cannot create file"); + return; + } + + if(ch == 'f' || ch == 'n') + chessinit('G', 0, 2); /* figurine */ + else + chessinit('G', 0, 0); /* ascii */ + Binit(&buf, f, OWRITE); + s = &str[1]; + i = 1; + if(ngames == 1) { + s--; + i--; + } + t = 0; + switch(ch) { + case 'a': + case 'f': + for(; i= 60) + if(j & 1) + t += Bprint(&buf, "\n%G", m); + else + t += Bprint(&buf, "\n%d %G", (j+2)/2, m); + else + if(j & 1) + t += Bprint(&buf, " %G", m); + else + t += Bprint(&buf, " %d %G", (j+2)/2, m); + } + if(printcol > 0) + t += Bprint(&buf, "\n"); + } + break; + + case 'n': + t += Bprint(&buf, ".na\n"); + for(; i= 60) { + if(j & 1) + n = Bprint(&buf, "\n%G", m); + else + n = Bprint(&buf, "\n%d %G", j/2+1, m); + } else { + if(j & 1) + n = Bprint(&buf, " %G", m); + else + n = Bprint(&buf, " %d %G", j/2+1, m); + } + t += n; + } + if(printcol >= 60) + t += Bprint(&buf, "\n%s\n", g.result); + else + t += Bprint(&buf, " %s\n", g.result); + } + break; + + case 'm': + for(; igp; + m = *sp++; + Bputc(&buf, m>>8); + Bputc(&buf, m); + nw = Bwrite(&buf, sp, 2*m); + if(nw != 2*m) { + yyerror("write error"); + break; + } + t += (m + 1)*2; + sp += m; + m = *sp++; + Bputc(&buf, m>>8); + Bputc(&buf, m); + for(j=0; j>8); + Bputc(&buf, k); + } + t += (m + 1)*2; + } + break; + + case 'r': + for(; i'); + t += bputs(&buf, g.black); + Bputc(&buf, '\n'); + t += 2; + } else + if(strcmp(g.result, "0-1") == 0) { + t += bputs(&buf, g.white); + Bputc(&buf, '<'); + t += bputs(&buf, g.black); + Bputc(&buf, '\n'); + t += 2; + } else + if(strcmp(g.result, "½-½") == 0 || + strcmp(g.result, "+-+") == 0) { + t += bputs(&buf, g.white); + Bputc(&buf, '='); + t += bputs(&buf, g.black); + Bputc(&buf, '\n'); + t += 2; + } + } + break; + + } + + Bflush(&buf); + close(f); + sprint(chars, " %s: %ld chars", name, t); + prline(8); + chessinit('G', cinitf1, cinitf2); + forcegame(gameno); +} + +void +dodupl(void) +{ + ulong *posn, *p; + long i, b; + int j, n; + Str *s; + Game g; + + posn = malloc(3*sizeof(ulong)*tgames); + if(posn == 0) { + yyerror("no memory"); + return; + } + b = ~genmark('1'); + p = posn; + s = &str[0]; + for(i=0; imark &= b; + decode(&g, s); + if(g.nmoves < 10) + s->mark |= ~b; + ginit(&initp); + n = g.nmoves/2; + for(j=0; jposition = g.nmoves; + s->mark |= b; + } + p += 3; + } + free(posn); +} + +ulong +genmark(int ch) +{ + + if(ch >= '0' && ch <= '9') + return 1 << (ch-'0'); + if(ch >= 'a' && ch <= 'z') + return 1 << 10 + (ch-'a'); + return 0; +}