From: H.G.Muller Date: Mon, 27 Oct 2014 22:23:00 +0000 (+0100) Subject: Add infrastructure for keeping track of board position X-Git-Tag: v2.0~21 X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=5dafab747e0fa4aa877ea851383b985af00cfe98;p=uci2wb.git Add infrastructure for keeping track of board position A Xiangqi board is added, with code to set it up from a FEN, convert it to the board part of a FEN, and apply the moves from the move list to it, keeping track of what was the last capture. The FEN for setting it up is always taken from the "fen " position command ('iniPos') of the Cyclone dialect used in variant xiangqi. --- diff --git a/UCI2WB.c b/UCI2WB.c index 77cb1da..d7e9671 100644 --- a/UCI2WB.c +++ b/UCI2WB.c @@ -34,6 +34,7 @@ char move[2000][10], checkOptions[8192], iniPos[256], hashOpt[20], pause, ponder int mps, tc, inc, sTime, depth, myTime, hisTime, stm, computer = NONE, memory, oldMem=0, cores, moveNr, lastDepth, lastScore, startTime, debug; int statDepth, statScore, statNodes, statTime, currNr, size, collect, nr, sm, inex, on[500]; char currMove[20], moveMap[500][10], /* for analyze mode */ canPonder[20], threadOpt[20]; +char board[100]; // XQ board for UCCI int unit = 1; FILE *toE, *fromE, *fromF; @@ -79,6 +80,52 @@ Sync (int action) } void +FromFEN(char *fen) +{ int i=0; + while(*fen) { + char c = *fen++; + if(c >= 'A') board[i++] = c; else + if(c == '/') i++; else + if(c == ' ') break; else + while(c-- > '0' && i < 99) board[i++] = 0; + if(i >= 99) break; + } +} + +char * +ToFEN(int stm) +{ + int i, n=0; static char fen[200]; char *p = fen; + for(i=0; i<99; i++) { + char c = board[i]; + if(c >= 'A') { if(n) *p++ = '0' + n; n = 0; *p++ = c; } else n ++; + if(i%10 == 8) { if(n) *p++ = '0' + n; n = -1; *p++ = '/'; } + } + sprintf(p-1, " %c - - 0 1", stm); + return fen; +} + +int +Sqr(char *m, int j) +{ + int n = m[j] - 'a' + 10*('9' - m[j+1]); + if(n < 0) n = 0; else if(n > 99) n = 99; return n; +} + +int +Play(int nr) +{ + int i, last = -1; + FromFEN(iniPos + 4); // in XQ iniPos always has just "fen " prefix + for(i=0; i