From: H.G. Muller Date: Tue, 17 Apr 2012 18:00:29 +0000 (+0200) Subject: Put move translation in separate routines X-Git-Tag: v2.0~40 X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=3b37b287b6d8973dfd0385ad529e1d04963cb208;p=uci2wb.git Put move translation in separate routines --- diff --git a/UCI2WB.c b/UCI2WB.c index 26010a2..b2c4583 100644 --- a/UCI2WB.c +++ b/UCI2WB.c @@ -122,6 +122,27 @@ char *Convert(char *pv) return buf; } +void +Move4GUI(char *m) +{ + if(sc == 's') { + // convert USI move to WB format + m[2] = 'a'+'0'+size - m[2]; + m[3] = 'a'+'0'+size - m[3]; + if(m[1] == '*') { // drop + m[1] = '@'; + } else { + m[0] = 'a'+'0'+size - m[0]; + m[1] = 'a'+'0'+size - m[1]; + if((stm == WHITE ? (m[1]>'0'+size-size/3 || m[3]>'0'+size-size/3) + : (m[1] <= '0'+size/3 || m[3] <= '0'+size/3)) && m[4] != '+') + m[4] = '=', m[5] = 0; + } + } + if(m[0] == 'e' && (m[5] == 'a' || m[5] == 'h')) // seirawan castling + gating at Rook + m[0] = m[5], m[2] = 'e'; // convert to RxK notation +} + void * Engine2GUI() { @@ -157,22 +178,7 @@ Engine2GUI() } p[-1] = '\n'; *p = 0; // strip off ponder move } - if(sc == 's') { - // convert USI move to WB format - line[11] = 'a'+'0'+size - line[11]; - line[12] = 'a'+'0'+size - line[12]; - if(line[10] == '*') { // drop - line[10] = '@'; - } else { - line[9] = 'a'+'0'+size - line[9]; - line[10] = 'a'+'0'+size - line[10]; - if((stm == WHITE ? (line[10]>'0'+size-size/3 || line[12]>'0'+size-size/3) - : (line[10] <= '0'+size/3 || line[12] <= '0'+size/3)) && line[13] != '+') - line[13] = '=', line[14] = 0; - } - } - if(line[9] == 'e' && (line[14] == 'a' || line[14] == 'h')) // seirawan castling + gating at Rook - line[9] = line[14], line[11] = 'e'; // convert to RxK notation + Move4GUI(line+9); printf("move %s\n", line+9); // send move to GUI if(lastScore == 100001 && iniPos[0] != 'f') { printf("%s {mate}\n", stm == WHITE ? "1-0" : "0-1"); computer = NONE; } stm = WHITE+BLACK - stm; @@ -238,6 +244,29 @@ Engine2GUI() } void +Move4Engine(char *m) +{ + if(sc == 's') { + // convert input move to USI format + if(m[1] == '@') { // drop + m[1] = '*'; + } else { + m[0] = 'a'+'0'+size - m[0]; + m[1] = 'a'+'0'+size - m[1]; + } + m[2] = 'a'+'0'+size - m[2]; + m[3] = 'a'+'0'+size - m[3]; + if(m[4] == '=') m[4] = 0; // no '=' in USI format! + else if(m[4] != '\n') m[4] = '+'; // cater to WB 4.4 bug :-( + } + if(m[4] && (m[1] == '1' || m[1] == '8')) { // seirawan gating + m[5] = m[0], m[6] = m[1], m[7] = '\0'; // copy from-square behind it, as gating square + if(m[2] == 'e' && (m[0] == 'a' || m[0] == 'h')) + m[2] = (m[0]+m[2]+1)>>1, m[0] = 'e'; // gating at Rook + } +} + +void GUI2Engine() { char line[256], command[256], *p, *q; @@ -270,25 +299,8 @@ GUI2Engine() Sync(PAUSE); // wait for readyok } else if(!strcmp(command, "usermove")) { - if(sc == 's') { - // convert input move to USI format - if(line[10] == '@') { // drop - line[10] = '*'; - } else { - line[9] = 'a'+'0'+size - line[9]; - line[10] = 'a'+'0'+size - line[10]; - } - line[11] = 'a'+'0'+size - line[11]; - line[12] = 'a'+'0'+size - line[12]; - if(line[13] == '=') line[13] = 0; // no '=' in USI format! - else if(line[13] != '\n') line[13] = '+'; // cater to WB 4.4 bug :-( - } sscanf(line, "usermove %s", command); // strips off linefeed - if(command[4] && (command[1] == '1' || command[1] == '8')) { // seirawan gating - command[5] = command[0], command[6] = command[1], command[7] = '\0'; - if(command[2] == 'e' && (command[0] == 'a' || command[0] == 'h')) - command[2] = (command[0]+command[2]+1)>>1, command[0] = 'e'; // gating at Rook - } + Move4Engine(command); stm = WHITE+BLACK - stm; // when pondering we either continue the ponder search as normal search, or abort it if(pondering || computer == ANALYZE) { @@ -299,8 +311,7 @@ GUI2Engine() } StopPonder(1); } -// sscanf(line, "usermove %s", move[moveNr++]); // possibly overwrites ponder move - strcpy(move[moveNr++], command); + strcpy(move[moveNr++], command); // possibly overwrites ponder move } else if(!strcmp(command, "level")) { int sec = 0;