X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=hachu.c;h=2af2697e14d3a618eced449ce5947bba7e050f29;hb=f70407bdade278fd65c3b4c1829168a38b56b101;hp=dcf484237b587a7bdcb9e0715c333ec6bdb06640;hpb=0675b3cbe33ae86364f12dbda3b2508d204d738d;p=hachu.git diff --git a/hachu.c b/hachu.c index dcf4842..2af2697 100644 --- a/hachu.c +++ b/hachu.c @@ -91,11 +91,11 @@ typedef struct { char fireMask; } UndoInfo; -char *array; +char *array, *reason; int bWidth, bHeight, bsize, zone, currentVariant; int stm, xstm, hashKeyH, hashKeyL, framePtr, msp, nonCapts, rootEval, retMSP, retFirst, retDep, pvPtr, level, cnt50, chuFlag=1, tenFlag, mobilityScore; -int nodes, startTime, tlim1, tlim2; -Move retMove, moveStack[10000], path[100], repStack[300], pv[1000]; +int nodes, startTime, tlim1, tlim2, repCnt, comp; +Move retMove, moveStack[10000], path[100], repStack[300], pv[1000], repeatMove[300]; #define X 36 /* slider */ #define R 37 /* jump capture */ @@ -1356,7 +1356,7 @@ void GenCapts(int sqr, int victimValue) { // generate all moves that capture the piece on the given square int i, range, att = attacks[2*sqr + stm]; -//printf("GenCapts(%d,%d)\n",sqr,victimValue); +//printf("GenCapts(%c%d,%d) %08x\n",sqr%BW+'a',sqr/BW,victimValue,att); if(!att) return; // no attackers at all! for(i=0; i<8; i++) { // try all rays int x, v, jumper, jcapt=0; @@ -1460,7 +1460,7 @@ GenCapts(int sqr, int victimValue) for(i=0; i<8; i++) { // scan all knight jumps to locate source int x = sqr - nStep[i], attacker = board[x]; if(attacker == EMPTY || (attacker & TYPE) != stm) continue; - if(p[attacker].range[i] <= N && p[attacker].range[i] >= S && p[attacker].range[i] != J) { // has Knight jump in our direction + if(p[attacker].range[i] <= L && p[attacker].range[i] >= S || p[attacker].range[i] == N) { // has Knight jump in our direction NewCapture(x, sqr + victimValue, p[attacker].promoFlag); // plain jump (as in N) if(p[attacker].range[i] < N) { // Lion power; generate double captures over two possible intermediates int v = kStep[i]; // leftish path @@ -1630,7 +1630,8 @@ if(flag & depth >= 0) printf("%2d:%d found %d/%d %08x %s\n", depth, iterDep, cur if(flag & depth >= 0) printf("%2d:%d made %d/%d %s\n", depth, iterDep, curMove, msp, MoveToText(moveStack[curMove], 0)); for(i=2; i<=cnt50; i+=2) if(repStack[level-i+200] == hashKeyH) { moveStack[curMove] = 0; // erase forbidden move - score = -INF; goto repetition; + if(!level) repeatMove[repCnt++] = move & 0xFFFFFF; // remember outlawed move + score = -INF; moveStack[curMove] = 0; goto repetition; } repStack[level+200] = hashKeyH; @@ -1912,7 +1913,7 @@ ParseMove (char *moveText) if(*moveText == '+') ret |= PROMOTE; printf("# suppress = %c%d\n", sup1%BW+'a', sup1/BW); MapFromScratch(attacks); - postThinking--; + postThinking--; repCnt = 0; Search(-INF-1, INF+1, 0, 1, sup1 & ~PROMOTE, sup2); postThinking++; for(i=retFirst; i= retMSP) - for(i=retFirst; i= retMSP) { + for(i=retFirst; i= retMSP ? INVALID : moveStack[i]); } @@ -1949,7 +1958,7 @@ MapFromScratch(attacks); //pmap(attacks, WHITE); //pmap(attacks, BLACK); //flag=1; - postThinking--; + postThinking--; repCnt = 0; Search(-INF-1, INF+1, 0, 1, sup1 & ~PROMOTE, sup2); postThinking++; flag=0; @@ -2007,6 +2016,7 @@ SearchBestMove (int stm, int timeLeft, int mps, int timeControl, int inc, int ti tlim2 = 1.9*targetTime; nodes = 0; MapFromScratch(attacks); + retMove = INVALID; repCnt = 0; score = Search(-INF-1, INF+1, rootEval, 20, sup1, sup2); *move = retMove; *ponderMove = INVALID; @@ -2030,9 +2040,11 @@ printf("# setup done");fflush(stdout); void PrintResult(int stm, int score) { - if(score == 0) printf("1/2-1/2\n"); - if(score > 0 && stm == WHITE || score < 0 && stm == BLACK) printf("1-0\n"); - else printf("0-1\n"); + char tail[100]; + if(reason) sprintf(tail, " {%s}", reason); else *tail = 0; + if(score == 0) printf("1/2-1/2%s\n", tail); + if(score > 0 && stm == WHITE || score < 0 && stm == BLACK) printf("1-0%s\n", tail); + else printf("0-1%s\n", tail); } main() @@ -2056,6 +2068,20 @@ printf("# setup done");fflush(stdout); score = SearchBestMove(stm, timeLeft, mps, timeControl, inc, timePerMove, &move, &ponderMove); if(move == INVALID) { // game apparently ended + int kcapt = 0, xstm = stm ^ WHITE, king, k = p[king=royal[xstm]].pos; + if( k != ABSENT) { // test if King capture possible + if(attacks[2*k + stm]) { + if( p[king + 2].pos == ABSENT ) kcapt = 1; // we have an attack on his only King + } + } else { // he has no king! Test for attacks on Crown Prince + k = p[king + 2].pos; + if(attacks[2*k + stm]) kcapt = 1; // we have attack on Crown Prince + } + if(kcapt) { // print King capture before claiming + GenCapts(k, 0); + printf("move %s\n", MoveToText(moveStack[msp-1], 1)); + reason = "king capture"; + } else reason = "resign"; engineSide = NONE; // so stop playing PrintResult(stm, score); } else { @@ -2135,7 +2161,10 @@ printf("var %d\n",i); if(!strcmp(command, "memory")) { SetMemorySize(atoi(inBuf+7)); continue; } if(!strcmp(command, "ping")) { printf("pong%s", inBuf+4); continue; } // if(!strcmp(command, "")) { sscanf(inBuf, " %d", &); continue; } - if(!strcmp(command, "new")) { engineSide = BLACK; Init(V_CHESS); stm = Setup2(DEFAULT_FEN); maxDepth = MAXPLY; randomize = OFF; continue; } + if(!strcmp(command, "new")) { + engineSide = BLACK; Init(V_CHESS); stm = Setup2(DEFAULT_FEN); maxDepth = MAXPLY; randomize = OFF; comp = 0; + continue; + } if(!strcmp(command, "setboard")){ engineSide = NONE; stm = Setup2(inBuf+9); continue; } if(!strcmp(command, "easy")) { ponder = OFF; continue; } if(!strcmp(command, "hard")) { ponder = ON; continue; } @@ -2157,7 +2186,7 @@ printf("var %d\n",i); if(!strcmp(command, "l")) { pplist(); continue; } // ignored commands: if(!strcmp(command, "xboard")) { continue; } - if(!strcmp(command, "computer")){ continue; } + if(!strcmp(command, "computer")){ comp = 1; continue; } if(!strcmp(command, "name")) { continue; } if(!strcmp(command, "ics")) { continue; } if(!strcmp(command, "accepted")){ continue; } @@ -2167,8 +2196,10 @@ printf("var %d\n",i); if(!strcmp(command, "")) { continue; } if(!strcmp(command, "usermove")){ int move = ParseMove(inBuf+9); - if(move == INVALID) printf("Illegal move\n"); - else { + if(move == INVALID) { + if(reason) printf("Illegal move {%s}\n", reason); else printf("%s\n", reason="Illegal move"); + if(comp) PrintResult(stm, -INF); // against computer: claim + } else { stm = MakeMove2(stm, move); ponderMove = INVALID; gameMove[moveNr++] = move; // remember game