// promotions by pieces with Lion power stepping in & out the zone in same turn\r
// promotion on capture\r
\r
-#define VERSION "0.9beta"\r
+#define VERSION "0.10 null"\r
\r
-#define PATH level==0 /*|| path[0] == 0x57097 && (level==1 || path[1] == 0x3f081 && (level == 2 || path[2] == 0x6f0ac && (level == 3 || path[3] == 0x3e865 && (level == 4 || path[4] == 0x4b865 && (level == 5)))))*/\r
+#define PATH level==0 || path[0] == 0x848f1 && (level==1 /*|| path[1] == 0x3f081 && (level == 2 || path[2] == 0x6f0ac && (level == 3 || path[3] == 0x3e865 && (level == 4 || path[4] == 0x4b865 && (level == 5))))*/)\r
//define PATH 0\r
\r
-#define XHASH\r
+#define HASH\r
#define XKILLERS\r
-#define XNULLMOVE\r
+#define NULLMOVE\r
\r
#include <stdio.h>\r
#include <stdlib.h>\r
} UndoInfo;\r
\r
char *array, fenArray[4000], *reason;\r
-int bWidth, bHeight, bsize, zone, currentVariant, chuFlag, tenFlag, chessFlag, repDraws;\r
-int stm, xstm, hashKeyH, hashKeyL, framePtr, msp, nonCapts, rootEval, retMSP, retFirst, retDep, pvPtr, level, cnt50, mobilityScore;\r
+int bWidth, bHeight, bsize, zone, currentVariant, chuFlag, tenFlag, chessFlag, repDraws, tsume;\r
+int stm, xstm, hashKeyH=1, hashKeyL=1, framePtr, msp, nonCapts, rootEval, retMSP, retFirst, retDep, pvPtr, level, cnt50, mobilityScore;\r
int nodes, startTime, lastRootMove, lastRootIter, tlim1, tlim2, tlim3, repCnt, comp, abortFlag;\r
Move ponderMove;\r
Move retMove, moveStack[10000], path[100], repStack[300], pv[1000], repeatMove[300], killer[100][2];\r
int postThinking;\r
int resign; // engine-defined option\r
int contemptFactor; // likewise\r
+ int seed;\r
\r
int squareKey[BSIZE];\r
\r
Search (int alpha, int beta, int difEval, int depth, int oldPromo, int promoSuppress, int threshold)\r
{\r
int i, j, k, phase, king, nextVictim, to, defer, autoFail=0;\r
- int start, firstMove, oldMSP = msp, curMove, sorted, bad, dubious, bestMoveNr;\r
+ int firstMove, oldMSP = msp, curMove, sorted, bad, dubious, bestMoveNr;\r
int resDep, iterDep, ext;\r
int myPV = pvPtr;\r
int score, bestScore, oldBest, curEval, iterAlpha;\r
if(PATH) /*pboard(board),pmap(attacks, BLACK),*/printf("search(%d) {%d,%d} eval=%d, stm=%d (flag=%d)\n",depth,alpha,beta,difEval,stm,abortFlag),fflush(stdout);\r
xstm = stm ^ WHITE;\r
//printf("map made\n");fflush(stdout);\r
+\r
+ // TSUME filter\r
+ if(tsume && tsume & stm+1) {\r
+ k = p[king=royal[stm]].pos;\r
+// if( k == ABSENT) k = p[king + 2].pos;\r
+ if( k != ABSENT && !attacks[2*k + xstm]) {\r
+ retDep = 60; return INF; // we win when not in check\r
+ }\r
+ }\r
+\r
// KING CAPTURE\r
k = p[king=royal[xstm]].pos;\r
if( k != ABSENT) {\r
pv[pvPtr++] = 0; // start empty PV, directly behind PV of parent\r
\r
\r
- firstMove = curMove = sorted = start = msp += 50; // leave 50 empty slots in front of move list\r
+ firstMove = curMove = sorted = msp += 50; // leave 50 empty slots in front of move list\r
iterDep = -(depth == 0); tb.fireMask = phase = 0;\r
\r
#ifdef HASH\r
- index = hashKeyL & hashMask; nr = hashKeyL >> 30; hit = -1;\r
+ index = (hashKeyL ^ 327*stm) & hashMask; nr = (hashKeyL >> 30) & 3; hit = -1;\r
if(hashTable[index].lock[nr] == hashKeyH) hit = nr; else\r
if(hashTable[index].lock[4] == hashKeyH) hit = 4;\r
+if(PATH) printf("# probe hash index=%x hit=%d\n", index, hit),fflush(stdout);\r
if(hit >= 0) {\r
bestScore = hashTable[index].score[hit];\r
+ hashMove = hashTable[index].move[hit];\r
if((bestScore <= alpha || hashTable[index].flag[hit] & H_LOWER) &&\r
(bestScore >= beta || hashTable[index].flag[hit] & H_UPPER) ) {\r
- iterDep = resDep = hashTable[index].depth[hit];\r
+ iterDep = resDep = hashTable[index].depth[hit]; bestMoveNr = 0;\r
+ if(!level) iterDep = 0; // no hash cutoff in root\r
}\r
} else { // decide on replacement\r
if(depth >= hashTable[index].depth[nr]) hit = nr; else hit = 4;\r
+ hashMove = 0;\r
}\r
+if(PATH) printf("# iterDep = %d score = %d move = %s\n",iterDep,bestScore,MoveToText(hashMove,0)),fflush(stdout);\r
#endif\r
\r
if(depth > QSdepth && iterDep < QSdepth) iterDep = QSdepth; // full-width: start at least from 1-ply\r
switch(phase) {\r
case 0: // null move\r
#ifdef NULLMOVE\r
- else if(curEval >= beta) {\r
+ if(depth > QSdepth && curEval >= beta) {\r
int nullDep = depth - 3;\r
stm ^= WHITE;\r
score = -Search(-beta, 1-beta, -difEval, nullDep<QSdepth ? QSdepth : nullDep, promoSuppress & SQUARE, ABSENT, INF);\r
//if(PATH) printf("mask=%x\n",tb.fireMask),pbytes(fireBoard);\r
phase = 1;\r
case 1: // hash move\r
+ phase = 2;\r
#ifdef HASH\r
- if(hashMove) {\r
+ if(hashMove && (depth > QSdepth || // must be capture in QS\r
+ (hashMove & SQUARE) >= SPECIAL || board[hashMove & SQUARE] != EMPTY)) {\r
moveStack[sorted = msp++] = hashMove;\r
goto extractMove;\r
}\r
#endif\r
- phase = 2;\r
case 2: // capture-gen init\r
nextVictim = xstm; autoFail = (depth == 0);\r
phase = 3;\r
\r
// MOVE EXTRACTION\r
extractMove:\r
-if(flag & depth >= 0 || (PATH)) printf("%2d:%d extract %d/%d\n", depth, iterDep, curMove, msp);\r
+//if(flag & depth >= 0 || (PATH)) printf("%2d:%d extract %d/%d\n", depth, iterDep, curMove, msp);\r
if(curMove > sorted) {\r
move = moveStack[sorted=j=curMove];\r
for(i=curMove+1; i<msp; i++)\r
defer = MakeMove(move, &tb);\r
ext = (depth == 0); // when out of depth we extend captures if there was no auto-fail-hi\r
\r
+// if(level == 1 && randomize) tb.booty += (hashKeyH * seed >> 24 & 31) - 20;\r
+\r
if(autoFail) {\r
UnMake(&tb); // never search moves during auto-fail phase\r
xstm = stm; stm ^= WHITE;\r
// hash store\r
hashTable[index].lock[hit] = hashKeyH;\r
hashTable[index].depth[hit] = iterDep;\r
+ hashTable[index].score[hit] = bestScore;\r
hashTable[index].flag[hit] = (bestScore < beta) * H_UPPER;\r
if(bestScore > alpha) {\r
hashTable[index].flag[hit] |= H_LOWER;\r
\r
// some parameter of your engine\r
#define MAXMOVES 2000 /* maximum game length */\r
- #define MAXPLY 20 /* maximum search depth */\r
+ #define MAXPLY 30 /* maximum search depth */\r
\r
#define OFF 0\r
#define ON 1\r
}\r
SetUp(array, currentVariant);\r
sup0 = sup1 = sup2 = ABSENT;\r
- rootEval = cnt50 = hashKeyH = hashKeyL = moveNr = 0;\r
+ rootEval = cnt50 = moveNr = 0;\r
+ hashKeyH = hashKeyL = 87620895*currentVariant;\r
return stm;\r
}\r
\r
{\r
#ifdef HASH\r
static HashBucket *realHash;\r
- static int oldSize;\r
- int m = 1;\r
- intptr_t l;\r
- if(n != oldSize) {\r
+ static intptr_t oldSize;\r
+ intptr_t l, m = 1;\r
+ while(m*sizeof(HashBucket) <= n*512UL) m <<= 1; // take largest power-of-2 that fits\r
+ if(m != oldSize) {\r
if(oldSize) free(realHash);\r
- while(m*sizeof(HashBucket) <= n*512) m <<= 1;\r
- m *= 1024; hashMask = m - 1;\r
- realHash = calloc(m + 1, sizeof(HashBucket));\r
- l = (intptr_t) realHash; hashTable = (HashBucket*) (l & ~63); // align with cache line\r
+ hashMask = m*1024 - 1; oldSize = m;\r
+ realHash = malloc(m*1024*sizeof(HashBucket) + 64);\r
+ l = (intptr_t) realHash; hashTable = (HashBucket*) (l & ~63UL); // align with cache line\r
}\r
#endif\r
}\r
int i, score, curVarNr;\r
\r
Init(V_CHU); // Chu\r
+ seed = GetTickCount(); moveNr = 0; // initialize random\r
\r
while(1) { // infinite loop\r
\r
fflush(stdout); // make sure everything is printed before we do something that might take time\r
- *inBuf = 0;\r
+ *inBuf = 0; if(moveNr >= 20) randomize = OFF;\r
+//if(moveNr >20) printf("resign\n");\r
\r
+#ifdef HASH\r
+ if(hashMask)\r
+#endif\r
if(listEnd == 0) ListMoves(); // always maintain a list of legal moves in root position\r
abortFlag = -(ponder && WHITE+BLACK-stm == engineSide && moveNr); // pondering and opponent on move\r
if(stm == engineSide || abortFlag && ponderMove) { // if it is the engine's turn to move, set it thinking, and let it move\r
printf("feature myname=\"HaChu " VERSION "\" highlight=1\n");\r
printf("feature option=\"Resign -check 0\"\n"); // example of an engine-defined option\r
printf("feature option=\"Contempt -spin 0 -200 200\"\n"); // and another one\r
+ printf("feature option=\"Tsume -combo no /// White Mates /// Black mates\"\n");\r
printf("feature done=1\n");\r
continue;\r
}\r
if(!strcmp(command, "option")) { // setting of engine-define option; find out which\r
if(sscanf(inBuf+7, "Resign=%d", &resign) == 1) continue;\r
if(sscanf(inBuf+7, "Contempt=%d", &contemptFactor) == 1) continue;\r
+ if(sscanf(inBuf+7, "Tsume=%s", command) == 1) {\r
+ if(!strcmp(command, "no")) tsume = 0; else\r
+ if(!strcmp(command, "White")) tsume = 1; else\r
+ if(!strcmp(command, "Black")) tsume = 2;\r
+ continue;\r
+ }\r
continue;\r
}\r
if(!strcmp(command, "sd")) { sscanf(inBuf, "sd %d", &maxDepth); continue; }\r