From 6d5526c41d7279be959b90fa6bb7109ca2ac7676 Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Wed, 11 Apr 2018 19:37:00 +0200 Subject: [PATCH] Implement move exclusion A 64KB moveMap[] is added to keep track of which moves are excluded in the root. It is indexed directly by the lowest 16 bits of the move code, (the from- and to-square), and can be almost entirely used, as the board measures 121 squares, an the 'shadow' board (another 121 squares) can be used both as from- and to-square as well. So that in theory 242*242 moves can be encoded. --- dropper.c | 24 ++++++++++++++++++------ 1 files changed, 18 insertions(+), 6 deletions(-) diff --git a/dropper.c b/dropper.c index e967a55..07fe17d 100644 --- a/dropper.c +++ b/dropper.c @@ -888,6 +888,7 @@ Dump (char *s) #define attacks (rawAttacks + 23) static int attackKey, rawAttacks[13*22]; int depthLimit = MAXPLY; +char moveMap[1<<16]; // excluded root moves int MoveGen (int stm, MoveStack *m, int castle) @@ -1435,6 +1436,8 @@ Search (int stm, int alpha, int beta, StackFrame *ff, int depth, int reduction, } } + if(ply == 0 && moveMap[moveStack[curMove] & 0xFFFF]) continue; // excluded root move + // make move if(MakeMove(&f, moveStack[curMove])) { // aborts if fails to evade existing check @@ -1816,6 +1819,12 @@ void PrintResult(int stm, int score) else printf("0-1\n"); } +void +MapClear (int n) +{ + int i; for(i=0; i<0x10000; i++) moveMap[i] = n; +} + int ponderMove; char inBuf[800]; @@ -1879,7 +1888,7 @@ printf("# command: %s\n", inBuf); return 1; } if(!strcmp(command, "protover")){ - printf("feature ping=1 setboard=1 colors=0 usermove=1 memory=1 debug=1 reuse=0 sigint=0 sigterm=0 myname=\"CrazyWa " VERSION "\"\n"); + printf("feature ping=1 setboard=1 colors=0 usermove=1 memory=1 debug=1 reuse=0 sigint=0 sigterm=0 exclude=1 myname=\"CrazyWa " VERSION "\"\n"); printf("feature variants=\"crazyhouse,shogi,minishogi,judkinshogi,torishogi,euroshogi,crazywa,kyotoshogi," "5x5+4_shogi,5x5+5_shogi,6x6+6_shogi,7x7+6_shogi,11x17+16_chu\"\n"); printf("feature option=\"Resign -check 0\"\n"); // example of an engine-defined option @@ -1892,13 +1901,16 @@ printf("# command: %s\n", inBuf); if(!strcmp(command, "memory")) { if(SetMemorySize(atoi(inBuf+7))) printf("tellusererror Not enough memory\n"), exit(-1); return 1; } if(!strcmp(command, "ping")) { printf("pong%s", inBuf+4); return 1; } // if(!strcmp(command, "")) { sscanf(inBuf, " %d", &); return 1; } - if(!strcmp(command, "new")) { engineSide = BLACK; stm = WHITE; maxDepth = MAXPLY-2; randomize = OFF; moveNr = 0; ranKey = GetTickCount() | 0x1001; return 1; } + if(!strcmp(command, "new")) { engineSide = BLACK; stm = WHITE; maxDepth = MAXPLY-2; randomize = OFF; + moveNr = 0; ranKey = GetTickCount() | 0x1001; MapClear(0); return 1; } if(!strcmp(command, "variant")) { GameInit(inBuf + 8); Setup(startPos); return 1; } - if(!strcmp(command, "setboard")){ engineSide = NONE; stm = Setup(inBuf+9); return 1; } - if(!strcmp(command, "undo")) { TakeBack(1); return 1; } - if(!strcmp(command, "remove")) { TakeBack(2); return 1; } + if(!strcmp(command, "setboard")){ engineSide = NONE; stm = Setup(inBuf+9); MapClear(0); return 1; } + if(!strcmp(command, "undo")) { TakeBack(1); MapClear(0); return 1; } + if(!strcmp(command, "remove")) { TakeBack(2); MapClear(0); return 1; } if(!strcmp(command, "go")) { engineSide = stm; return 1; } if(!strcmp(command, "hint")) { if(ponderMove != INVALID) printf("Hint: %s\n", MoveToText(ponderMove)); return 1; } + if(!strcmp(command, "include")) { if(inBuf[9] == 'l') MapClear(0); else moveMap[ParseMove(stm, inBuf+8)] = 0; return 1; } + if(!strcmp(command, "exclude")) { if(inBuf[9] == 'l') MapClear(1); else moveMap[ParseMove(stm, inBuf+8)] = 1; return 1; } if(!strcmp(command, "book")) { return 1; } // completely ignored commands: if(!strcmp(command, "xboard")) { return 1; } @@ -1917,7 +1929,7 @@ printf("# command: %s\n", inBuf); if(move == INVALID) printf("Illegal move\n"); else if(!RootMakeMove(move)) printf("Illegal move\n"); else { - ponderMove = INVALID; + ponderMove = INVALID; MapClear(0); } return 1; } -- 1.7.0.4