Components and supplies
Touchscreen
Resistor 100 ohm
Arduino Mega 2560
Buzzer
Tools and machines
Soldering iron (generic)
Apps and platforms
Arduino IDE
Project description
Code
gui.h
h
1#define mcufriend480 2//#define adafruit320 3 4#ifdef mcufriend480 5 //(MCUFRIEND screen 480x320) 6 #include <UTFTGLUE.h> 7 MCUFRIEND_kbv tft; 8 #define screen_width 480 9 #define screen_height 320 10 #define mapx1 980 11 #define mapx2 110 12 #define mapy1 145 13 #define mapy2 902 14#endif 15 16#ifdef adafruit320 17 //(screen 320x240) 18 #include <Adafruit_TFTLCD.h> 19 Adafruit_TFTLCD tft; 20 #define screen_width 320 21 #define screen_height 240 22 #define mapx1 930 23 #define mapx2 170 24 #define mapy1 145 25 #define mapy2 914 26#endif 27 28#include "TouchScreen.h" 29int XP = 6, YP = A1, XM = A2, YM = 7; 30TouchScreen ts(XP, YP, XM, YM, 300); 31TSPoint tp; 32 33int touchx,touchy,touched; 34#define MINPRESSURE 10 35#define MAXPRESSURE 1000 36#define PinBuzz 44 37 38boolean rotate=0; 39boolean sound=0; 40boolean menu=0; 41boolean pause=0; 42unsigned long guitime=0; 43unsigned long statustime=0; 44 45char poledisp[64]; // 46char statusbuf1[11],statusbuf2[11],statusbuf3[11]; 47char status_c1, status_c2; 48 49const uint8_t fig24[6][72] PROGMEM={ 50{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1E, 0x0, 0x0, 0x3F, 0x0, 0x80, 0x7F, 0x0, 0x80, 0x7F, 0x0, 510x80, 0x7F, 0x0, 0x0, 0x3F, 0x0, 0x0, 0x1C, 0x0, 0x0, 0x1C, 0x0, 0x80, 0xFF, 0x0, 0x80, 0xFF, 0x0, 0x0, 0x1C, 0x0, 0x0, 0x1C, 0x0, 520x0, 0x3E, 0x0, 0x0, 0x7F, 0x0, 0x80, 0xFF, 0x0, 0xC0, 0xFF, 0x1, 0xE0, 0xFF, 0x3, 0xE0, 0xFF,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 0x0, 0x0, 0x0 73} //king 74}; 75 76const uint8_t fig24_cont[6][72] PROGMEM={ 77{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1C, 0x0, 0x0, 0x22, 0x0, 0x0, 0x41, 0x0, 0x80, 0x80, 0x0, 0x80, 0x80, 0x0, 780x80, 0x80, 0x0, 0x0, 0x41, 0x0, 0x0, 0x22, 0x0, 0xC0, 0xE3, 0x1, 0x40, 0x0, 0x1, 0x40, 0x0, 0x1, 0xC0, 0xE3, 0x1, 0x0, 0x22, 0x0, 790x0, 0x41, 0x0, 0x80, 0x80, 0x0, 0x40, 0x0, 0x1, 0x20, 0x0, 0x2, 0x10, 0x0, 0x4, 0x10, 0x0, 0x4, 0x10, 0x0, 0x4, 0xF0, 0xFF, 0x7 80}, //pawn 81{0x0, 0x6E, 0x0, 0x0, 0x91, 0x0, 0x80, 0x0, 0x1, 0x40, 0x2, 0x2, 0x40, 0x0, 0x4, 0x20, 0x0, 0x8, 0x10, 0x0, 0x10, 0x10, 0x6, 0x10, 820x8, 0x5, 0x10, 0x8, 0x5, 0x10, 0x90, 0x2, 0x10, 0x60, 0x1, 0x10, 0x80, 0x0, 0x10, 0x80, 0x0, 0x8, 0x80, 0x0, 0x4, 0x80, 0x0, 0x2, 830x0, 0x1, 0x1, 0x0, 0x82, 0x0, 0x0, 0x44, 0x0, 0x0, 0x44, 0x0, 0xF8, 0x83, 0x1F, 0x8, 0x0, 0x10, 0x8, 0x0, 0x10, 0xF8, 0xFF, 0x1F 84}, //knight 85{0x0, 0x3C, 0x0, 0x0, 0x42, 0x0, 0x0, 0x81, 0x0, 0x0, 0x81, 0x0, 0x0, 0x42, 0x0, 0x80, 0xE7, 0x1, 0x40, 0x0, 0x2, 0x20, 0x18, 0x4, 860x10, 0x18, 0x8, 0x10, 0x18, 0x8, 0x10, 0x18, 0x8, 0x90, 0xFF, 0x9, 0x90, 0xFF, 0x9, 0x10, 0x18, 0x8, 0x10, 0x18, 0x8, 0x10, 0x18, 0x8, 870x10, 0x18, 0x8, 0x20, 0x18, 0x4, 0x40, 0x18, 0x2, 0x88, 0x0, 0x11, 0x14, 0x81, 0x28, 0xE2, 0xC3, 0x47, 0x1, 0x0, 0x80, 0xFF, 0xFF, 0xFF 88}, //bishop 89{0xF8, 0x7E, 0x1F, 0x8, 0xC3, 0x10, 0x8, 0xC3, 0x10, 0x8, 0x0, 0x10, 0x10, 0x0, 0x8, 0xE0, 0xFF, 0x7, 0x20, 0x0, 0x4, 0x20, 0x0, 0x4, 900x20, 0x0, 0x4, 0x20, 0x0, 0x4, 0x20, 0x0, 0x4, 0x20, 0x0, 0x4, 0x20, 0x0, 0x4, 0x20, 0x0, 0x4, 0x20, 0x0, 0x4, 0x20, 0x0, 0x4, 910x20, 0x0, 0x4, 0x20, 0x0, 0x4, 0x20, 0x0, 0x4, 0xE0, 0xFF, 0x7, 0x10, 0x0, 0x8, 0x8, 0x0, 0x10, 0x8, 0x0, 0x10, 0xF8, 0xFF, 0x1F 92}, //rook 93{0xEF, 0xBD, 0xF7, 0x11, 0x42, 0x88, 0x11, 0x42, 0x88, 0x29, 0xA5, 0x94, 0x29, 0xA5, 0x94, 0x29, 0xA5, 0x94, 0x32, 0xA5, 0x4C, 0x32, 0xA5, 0x4C, 940x32, 0xA5, 0x4C, 0x32, 0xA5, 0x4C, 0x32, 0xA5, 0x4C, 0x64, 0x66, 0x26, 0x64, 0x66, 0x26, 0x64, 0x66, 0x26, 0x64, 0x66, 0x26, 0x64, 0x66, 0x26, 950xC8, 0x0, 0x13, 0x48, 0x0, 0x12, 0x8, 0x0, 0x10, 0x10, 0x0, 0x8, 0xF0, 0xFF, 0xF, 0x8, 0x0, 0x10, 0x8, 0x0, 0x10, 0xF8, 0xFF, 0x1F 96}, //queen 97{0x0, 0x18, 0x0, 0xF0, 0x24, 0xF, 0x8, 0xA5, 0x10, 0x4, 0x66, 0x20, 0x2, 0x24, 0x40, 0x1, 0x24, 0x80, 0x1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, 0x0, 0x0, 0x4, 0x10, 0x0, 0x0, 0x8, 0x8, 0x0, 0x0, 0x10, 1950xE8, 0xFF, 0xFF, 0x17, 0x8, 0x0, 0x0, 0x10, 0x8, 0x0, 0x0, 0x10, 0xF8, 0xFF, 0xFF, 0x1F 196}, { 1970x0, 0x80, 0x1, 0x0, 0x0, 0x46, 0x62, 0x0, 0x0, 0x29, 0x94, 0x0, 0x8C, 0x30, 0xC, 0x31, 1980x92, 0x50, 0xA, 0x49, 0x21, 0x49, 0x92, 0x84, 0x21, 0x29, 0x94, 0x84, 0x92, 0x30, 0xC, 0x49, 1990x92, 0x30, 0xC, 0x49, 0xA1, 0x30, 0xC, 0x85, 0xA1, 0x30, 0xC, 0x85, 0xA2, 0x30, 0xC, 0x45, 2000x42, 0x51, 0x8A, 0x42, 0x42, 0x31, 0x8C, 0x42, 0x44, 0x11, 0x88, 0x22, 0x44, 0x1, 0x80, 0x21, 2010xC4, 0x0, 0x0, 0x21, 0x84, 0x0, 0x0, 0x21, 0x8, 0xE0, 0x7, 0x10, 0x8, 0x1E, 0x78, 0x10, 2020xC8, 0x1, 0x80, 0x13, 0x8, 0x80, 0x1, 0x10, 0x8, 0xC2, 0x43, 0x8, 0x10, 0x87, 0xE1, 0x8, 2030x20, 0x2, 0x40, 0x4, 0x20, 0x0, 0x0, 0x4, 0x40, 0x0, 0x0, 0x2, 0x80, 0x0, 0x0, 0x1, 2040x80, 0xFE, 0x7F, 0x1, 0x40, 0x0, 0x0, 0x2, 0x40, 0x0, 0x0, 0x2, 0xC0, 0xFF, 0xFF, 0x3 205}, { 206 0x0, 0x80, 0x1, 0x0, 0x0, 0x40, 0x2, 0x0, 0x0, 0x20, 0x4, 0x0, 0xE0, 0x21, 0x84, 0x7, 2070x18, 0x46, 0x62, 0x18, 0x4, 0x48, 0x12, 0x20, 0x2, 0x30, 0xC, 0x40, 0x1, 0x30, 0xC, 0x80, 2080x1, 0x60, 0x6, 0x80, 0x1, 0xC0, 0x3, 0x80, 0x1, 0x80, 0x1, 0x80, 0x1, 0x80, 0x1, 0x80, 2090x1, 0x80, 0x1, 0x80, 0x1, 0x80, 0x1, 0x80, 0x1, 0x80, 0x1, 0x80, 0x1, 0x80, 0x1, 0x80, 2100x1, 0x80, 0x1, 0x80, 0x1, 0x80, 0x1, 0x80, 0x2, 0x80, 0x1, 0x40, 0x4, 0x80, 0x1, 0x20, 2110x4, 0x80, 0x1, 0x20, 0x8, 0xE0, 0x7, 0x10, 0x8, 0x1C, 0x38, 0x10, 0xD0, 0x3, 0xC0, 0xB, 2120x20, 0x80, 0x1, 0x4, 0x20, 0xC6, 0x63, 0x4, 0x40, 0x80, 0x1, 0x2, 0x80, 0x0, 0x0, 0x1, 2130x80, 0xFE, 0x5F, 0x1, 0x40, 0x0, 0x0, 0x2, 0x40, 0x0, 0x0, 0x2, 0xC0, 0xFF, 0xFF, 0x3 214} 215}; 216 217uint16_t BLACK,BLUE,RED,GREEN,CYAN,MAGENTA,YELLOW,WHITE,GRAY,DARK,GRAY2,BLACKF,WHITEF; 218 219//********************************** 220class Button { 221public: 222int bx,by,bw,bh,bshift; 223String bs; 224const uint8_t* bp; 225 Button(int x,int y,int w,int h,int x1,int y1,int w1,int h1,String s,const uint8_t* p, int shift); 226 void Show(int shift); 227 void Show(String s); 228 void Hide(); 229 boolean IsPressed(); 230private: 231boolean active; 232 void ishow(uint16_t textcolor,uint16_t backcolor); 233}; 234Button::Button(int x,int y,int w,int h,int x1,int y1,int w1,int h1,String s,const uint8_t* p=NULL, int shift=0) { 235 if (screen_height==320) { 236 bx=x; by=y; bw=w; bh=h; 237 } else { 238 bx=x1; by=y1; bw=w1; bh=h1; 239 } 240 bs=s; bp=p; bshift=shift; 241}; 242void Button::Show(int shift=0) { 243 bshift=shift; 244 active=true; 245 ishow(WHITE,DARK); 246}; 247void Button::Show(String s) { 248 bs=s; 249 active=true; 250 ishow(WHITE,DARK); 251}; 252void Button::Hide() { 253 active=false; 254 ishow(GRAY,DARK); 255}; 256boolean Button::IsPressed() { 257 if (active&&abs(bx+bw/2-touchx)<bw/2&&abs(by+bh/2-touchy)<bh/2) { 258 ishow(WHITE,GRAY); 259 touchx=0; touchy=0; 260 return true; 261 } 262 return false; 263}; 264void Button::ishow(uint16_t textcolor,uint16_t backcolor) { 265 tft.fillRoundRect(bx+2,by+2,bw,bh,3,GRAY2); 266 tft.fillRoundRect(bx,by,bw,bh,3,backcolor); 267 tft.setTextColor(textcolor); 268 if (screen_height==320) { 269 tft.setTextSize(2); 270 tft.setCursor(bx+(bw-bs.length()*12)/2,by+(bh-12)/2); 271 } else { 272 tft.setTextSize(1); 273 tft.setCursor(bx+(bw-bs.length()*6)/2,by+(bh-8)/2); 274 } 275 if (bp!=NULL) { 276 tft.drawBitmap(1+bx+(bw-16)/2, by+(bh-16)/2, bp+bshift*32, 16, 16,textcolor); 277 } 278 else tft.print(bs); 279} 280 281Button BAction(354, 280, 100, 30, 252, 210, 60, 20, "START"); 282Button BMenu(354, 20, 100, 30, 252, 20, 60, 20, "MENU"); 283Button BBack(354, 58, 100, 30, 252, 47, 60, 20, "BACK"); 284Button BTime(354, 96, 100, 30, 252, 74, 60, 20, "5 s"); 285Button BNew(354, 134, 100, 30, 252, 101, 60, 20, "NEW"); 286Button BAuto(354, 172, 100, 30, 252, 128, 60, 20, "AUTO:B"); 287Button BRotate(354, 210, 100, 30, 252, 155, 60, 20, "ROTATE"); 288Button BSave(354, 248, 100, 30, 252, 182, 60, 20, "SAVE"); 289Button BLoad(354, 286, 100, 30, 252, 209, 60, 20, "LOAD"); 290 291//********************************** 292void drawBitmap(int16_t x, int16_t y, 293 const uint8_t *bitmap, int16_t w, int16_t h, 294 uint16_t color) { 295 int16_t i, j, byteWidth = (w + 7) / 8; 296 for(j=0; j<h; j++) { 297 for(i=0; i<w; i++ ) { 298 if(pgm_read_byte(bitmap + j * byteWidth + i / 8) & (1 << (i % 8))) { 299 tft.drawPixel(x+i, y+j, color); 300 } 301 } 302 } 303} 304//**************************** 305uint16_t getColor(uint8_t red, uint8_t green, uint8_t blue) 306{ 307 red >>= 3; 308 green >>= 2; 309 blue >>= 3; 310 return (red << 11) | (green << 5) | blue; 311} 312//**************************** 313void show_fig(int c) { 314uint16_t colorf,color,color_cont; 315 colorf=BLACKF; 316 int i=column[c]-1; 317 int j=8-row[c]; 318 if ((i+j+2)%2==0) colorf=WHITEF; 319 int jj=j, ii=i; 320 if (rotate) { jj=7-j; ii=7-i; } 321 color=BLACK; color_cont=getColor(128,128,100); 322 if (pole[c]>0) { color=WHITE; color_cont=BLACK; } 323 if (screen_height==320) { 324 tft.fillRect(ii*39+10,jj*39,39,39,colorf); 325 tft.drawRect(ii*39+10,jj*39,39,39,GRAY); 326 if (pole[c]!=0) { 327 drawBitmap(ii*39+14, jj*39+5,&fig32[abs(pole[c])-1][0], 32, 32,color); 328 drawBitmap(ii*39+14, jj*39+5,&fig32_cont[abs(pole[c])-1][0], 32, 32,color_cont); 329 } 330 } else { //height 240 331 tft.fillRect(ii*28+12,jj*28,29,29,colorf); 332 tft.drawRect(ii*28+12,jj*28,29,29,GRAY); 333 if (pole[c]!=0) { 334 drawBitmap(ii*28+14, jj*28+3,&fig24[abs(pole[c])-1][0], 24, 24,color); 335 drawBitmap(ii*28+14, jj*28+3,&fig24_cont[abs(pole[c])-1][0], 24, 24,color_cont); 336 } 337 } 338} 339//**************************** 340void show_color() { 341int posx, posyw, posyb, rad; 342if (screen_height==320) { 343 posx=334; posyw=290; posyb=24; rad=5; 344 } else { //240 345 posx=244; posyw=214; posyb=20; rad=4; 346 } 347 if (rotate) { int r=posyb; posyb=posyw; posyw=r; } 348 tft.fillCircle(posx,posyb,rad,BLACK); tft.fillCircle(posx,posyw,rad,BLACK); 349 if (pos[0].w) tft.fillCircle(posx,posyw,rad,GRAY); else tft.drawCircle(posx,posyb,rad,GRAY); 350 uint16_t col=BLACK; 351 int r2=rad*2; 352 if (autow) col=DARK; 353 tft.drawRect(posx-rad,posyw+r2,r2,r2,col); 354 col=BLACK; 355 if (autob) col=DARK; 356 tft.drawRect(posx-rad,posyb+r2,r2,r2,col); 357} 358//**************************** 359void show_board() { 360 for (int i=0;i<64;i++) { 361 if (poledisp[i]!=pole[i]) show_fig(i); 362 poledisp[i]=pole[i]; 363 } 364 show_color(); 365} 366//**************************** 367void border() { 368 tft.setTextColor(GRAY,BLACK); 369 tft.setTextSize(1); 370 if (screen_height==320) { 371 for (int j=1;j<9;j++) { 372 tft.setCursor(1,j*39-22); 373 if (rotate) tft.print(j); else tft.print(9-j); 374 } 375 for (byte i=1;i<9;i++) { 376 tft.setCursor(i*39-11,312); 377 if (rotate) tft.print(char(96+9-i)); else tft.print(char(96+i)); 378 } 379 } else { //240 380 for (int j=1;j<9;j++) { 381 tft.setCursor(2,j*28-15); 382 if (rotate) tft.print(j); else tft.print(9-j); 383 } 384 for (byte i=1;i<9;i++) { 385 tft.setCursor(i*28-1,228); 386 if (rotate) tft.print(char(96+9-i)); else tft.print(char(96+i)); 387 } 388 } 389} 390//**************************** 391void cleardisplayboard() { 392 for (int i=0;i<64;i++) poledisp[i]=-100; // 393} 394//**************************** 395void initboard() { 396 cleardisplayboard(); 397 tft.fillScreen(BLACK); 398 border(); 399 tft.setTextSize(1); 400 if (screen_height==320) { 401 tft.setCursor(337,1); tft.setTextColor(WHITE); 402 tft.print(F("Arduino Mega Chess II")); 403 } else { //240 404 tft.setCursor(242,1); tft.setTextColor(WHITE); 405 tft.print(F("Arduino Mega")); 406 tft.setCursor(252,10); 407 tft.print(F("Chess II")); 408 } 409} 410//**************************** 411void show_steps() { 412 if (screen_height==320) { 413 tft.fillRect(330,56,135,150,GRAY2); 414 } 415 else { 416 tft.fillRect(240,44,74,114,GRAY2); 417 } 418 tft.setTextColor(GRAY); 419 tft.setTextSize(2); 420 int st=0; 421 if (ply>8) st=ply-8; 422 if (st<0) st=0; 423 for (int i=st;i<ply;i++) { 424 if (i%2==0) { 425 tft.setTextSize(1); 426 if (screen_height==320) 427 tft.setCursor(332,(i-st)*18+64); 428 else 429 tft.setCursor(244,(i-st)*14+48); 430 tft.print(String(i/2+1)+"."); 431 } 432 if (screen_height==320) { 433 tft.setTextSize(2); 434 tft.setCursor(360,(i-st)*18+60); 435 } else { 436 tft.setTextSize(1); 437 tft.setCursor(268,(i-st)*14+48); 438 } 439 tft.print(str_step(steps[i])); 440 } 441 442 443 444} 445//**************************** 446void definecolors() { 447 BLACK =0x0000; 448 BLUE =0x07FF; //0x001F; 449 RED =0xF800; 450 GREEN =0x07E0; 451 CYAN =0x07FF; 452 MAGENTA=0xF81F; 453 YELLOW =0xFFE0; 454 WHITE =0xFFFF; 455 GRAY =0x7BEF; 456 DARK =getColor(32,32,32); 457 GRAY2 =getColor(16,16,16); 458 BLACKF =getColor(94,58,0); 459 WHITEF =getColor(180,114,0); 460} 461//**************************** 462void beep(int leng) { 463 analogWrite(PinBuzz, 20); 464 delay(2); 465 if (!sound) analogWrite(PinBuzz, 0); 466 delay(leng); 467 analogWrite(PinBuzz, 0); 468} 469//**************************** 470void guistart() { 471 tft.reset(); 472 tft.begin(tft.readID()); 473 tft.setRotation(1); 474 definecolors(); 475 initboard(); 476 BAction.Show("START"); 477 BMenu.Show("MENU"); 478 show_board(); 479} 480//**************************** 481String get_time(int tim) { 482 char sz[10]; 483 //sprintf(sz, "%02d:%02d:%02d", tim/3600,(tim%3600)/60,tim%60); 484 sprintf(sz, "%d:%02d",tim/60,tim%60); 485 String s=sz; s.trim(); 486 return String(sz); 487} 488//**************************** 489void clearstatus() { 490 if (screen_height==320) { 491 tft.fillRect(330,210,135,60,GRAY2); 492 } else { 493 tft.fillRect(242,169,70,36,GRAY2); 494 } 495 for (int j=0;j<11;j++) { statusbuf1[j]=' '; statusbuf2[j]=' '; statusbuf3[j]=' '; } 496 guitime=millis(); 497 statustime=guitime; 498 status_c1=-1; 499 status_c2=-1; 500} 501//**************************** 502void print_changed(String s, char* b, uint16_t c) { 503 for (int i=0;i<11;i++) { 504 if (b[i]!=s[i]) { 505 tft.setTextColor(c,GRAY2); 506 tft.print(s[i]); 507 } else { 508 tft.setTextColor(GRAY2,GRAY2); 509 tft.print(" "); 510 } 511 b[i]=s[i]; 512 } 513} 514//**************************** 515void status_step(char c,byte show,uint16_t col=0) { 516uint16_t color,color2; 517 if (c<0||c>63) return; 518 color=BLACKF; 519 int i=column[c]-1; 520 int j=8-row[c]; 521 if ((i+j+2)%2==0) color=WHITEF; 522 color2=GRAY; 523 if (show) { color=col; color2=color; } 524 int jj=j, ii=i; 525 if (rotate) { jj=7-j; ii=7-i; } 526 if (screen_height==320) { 527 tft.drawRect(ii*39+10,jj*39,39,39,color2); 528 tft.drawRect(ii*39+11,jj*39+1,37,37,color); 529 } else { //height 240 530 tft.drawRect(ii*28+12,jj*28,29,29,color2); 531 tft.drawRect(ii*28+13,jj*28+1,27,27,color); 532 } 533} 534//**************************** 535void showstatus(String s1, String s2, String s3, uint16_t c1=GRAY, uint16_t c2=GRAY, uint16_t c3=GRAY) { 536 tft.setTextWrap(1); 537 tft.setTextColor(GRAY); 538 if (screen_height==320) { 539 tft.setTextSize(2); 540 tft.setCursor(334,213); print_changed(s1,statusbuf1,c1); 541 tft.setCursor(334,233); print_changed(s2,statusbuf2,c2); 542 tft.setCursor(334,253); print_changed(s3,statusbuf3,c3); 543 } else { 544 tft.setTextSize(1); 545 tft.setCursor(244,172); print_changed(s1,statusbuf1,c1); 546 tft.setCursor(244,184); print_changed(s2,statusbuf2,c2); 547 tft.setCursor(244,196); print_changed(s3,statusbuf3,c3); 548 } 549 if (status_c1!=pos[0].cut.c1||status_c2!=pos[0].cut.c2) { 550 if (status_c1!=-1) { status_step(status_c1,0); status_step(status_c2,0); } 551 status_c1=pos[0].cut.c1; 552 status_c2=pos[0].cut.c2; 553 status_step(status_c1,1,getColor(220,0,0)); 554 status_step(status_c2,1,getColor(0,180,0)); 555 } 556} 557//**************************** 558boolean gettouch() { 559 //digitalWrite(13, HIGH); 560 tp = ts.getPoint(); 561 //digitalWrite(13, LOW); 562 // if sharing pins, you'll need to fix the directions of the touchscreen pins 563 pinMode(XM, OUTPUT); 564 pinMode(YP, OUTPUT); 565 int x=map(tp.y,mapx1,mapx2,0,screen_width-1); 566 int y=map(tp.x,mapy1,mapy2,0,screen_height-1); 567 touched=0; 568 if ((abs(x-touchx)>5||abs(y-touchy)>5)&&tp.z>MINPRESSURE&&tp.z<MAXPRESSURE) { 569 touched=1; 570 touchx=x; 571 touchy=y; 572 //tft.drawPixel(x,y,GREEN); 573 //Serial.println(tp.y); 574 //Serial.println(tp.x); 575 } 576 return touched; 577} 578//**************************** 579void erasestatus() { 580 if (status_c1>-1) status_step(status_c1,0); 581 if (status_c2>-1) status_step(status_c2,0); 582 status_c1=-1; 583 status_c2=-1; 584} 585//********************************** 586signed char field_pressed() { 587 signed char c; 588 if (screen_height==320) { 589 c=(touchx-10)/39+8*(touchy/39); 590 } else { 591 c=(touchx-10)/28+8*(touchy/28); 592 } 593 if (c<0||c>63) c=-1; else if (rotate) c=63-c; 594 if (c!=-1&&status_c1==-1) 595 if ((pos[0].w&&pole[c]<=0)||(!pos[0].w&&pole[c]>=0)) c=-1; 596 if (c!=-1&&status_c1!=-1&&c==status_c1) c=-1; 597 //Serial.println(c); 598 return c; 599} 600//**************************** 601void clearmenu() { 602 if (screen_height==320) { 603 tft.fillRect(330,56,135,220,BLACK); 604 tft.fillRect(350,276,115,43,BLACK); 605 } else { 606 tft.fillRect(240,40,80,166,BLACK); 607 tft.fillRect(250,206,69,33,BLACK); 608 } 609} 610//**************************** 611
wac.h
h
1const char wac1[] PROGMEM= "2rr3k/pp3pp1/1nnqbN1p/3pN3/2pP4/2P3Q1/PPB4P/R4RK1 w - - bm Qg6; id ""WAC.001""; d5+m2"; 2const char wac2[] PROGMEM="8/7p/5k2/5p2/p1p2P2/Pr1pPK2/1P1R3P/8 b - - bm Rxb2; id ""WAC.002""; d18+4"; 3const char wac3[] PROGMEM="5rk1/1ppb3p/p1pb4/6q1/3P1p1r/2P1R2P/PP1BQ1P1/5RKN w - - bm Rg3; id ""WAC.003""; d5+3"; 4const char wac4[] PROGMEM="r1bq2rk/pp3pbp/2p1p1pQ/7P/3P4/2PB1N2/PP3PPR/2KR4 w - - bm Qxh7+; id ""WAC.004""; d5+m2"; 5const char wac5[] PROGMEM="5k2/6pp/p1qN4/1p1p4/3P4/2PKP2Q/PP3r2/3R4 b - - bm Qc4+; id ""WAC.005""; d5+m2"; 6const char wac6[] PROGMEM="7k/p7/1R5K/6r1/6p1/6P1/8/8 w - - bm Rb7; id ""WAC.006""; d5+7"; 7const char wac7[] PROGMEM="rnbqkb1r/pppp1ppp/8/4P3/6n1/7P/PPPNPPP1/R1BQKBNR b KQkq - bm Ne3; id ""WAC.007""; d5+3"; 8const char wac8[] PROGMEM="r4q1k/p2bR1rp/2p2Q1N/5p2/5p2/2P5/PP3PPP/R5K1 w - - bm Rf7; id ""WAC.008""; d5+7 d11+m8"; 9const char wac9[] PROGMEM="3q1rk1/p4pp1/2pb3p/3p4/6Pr/1PNQ4/P1PB1PP1/4RRK1 b - - bm Bh2+; id ""WAC.009""; d5+m5"; 10const char wac10[] PROGMEM="2br2k1/2q3rn/p2NppQ1/2p1P3/Pp5R/4P3/1P3PPP/3R2K1 w - - bm Rxh7; id ""WAC.010""; d5+4"; 11const char wac11[] PROGMEM="r1b1kb1r/3q1ppp/pBp1pn2/8/Np3P2/5B2/PPP3PP/R2Q1RK1 w kq - bm Bxc6; id ""WAC.011""; d5+3"; 12const char wac12[] PROGMEM="4k1r1/2p3r1/1pR1p3/3pP2p/3P2qP/P4N2/1PQ4P/5R1K b - - bm Qxf3+; id ""WAC.012""; d5+m2"; 13const char wac13[] PROGMEM="5rk1/pp4p1/2n1p2p/2Npq3/2p5/6P1/P3P1BP/R4Q1K w - - bm Qxf8+; id ""WAC.013""; d5+1.5"; 14const char wac14[] PROGMEM="r2rb1k1/pp1q1p1p/2n1p1p1/2bp4/5P2/PP1BPR1Q/1BPN2PP/R5K1 w - - bm Qxh7+; id ""WAC.014""; d5+m4"; 15const char wac15[] PROGMEM="1R6/1brk2p1/4p2p/p1P1Pp2/P7/6P1/1P4P1/2R3K1 w - - bm Rxb7; id ""WAC.015""; d5+7"; 16const char wac16[] PROGMEM="r4rk1/ppp2ppp/2n5/2bqp3/8/P2PB3/1PP1NPPP/R2Q1RK1 w - - bm Nc3; id ""WAC.016""; d5+2"; 17const char wac17[] PROGMEM="1k5r/pppbn1pp/4q1r1/1P3p2/2NPp3/1QP5/P4PPP/R1B1R1K1 w - - bm Ne5; id ""WAC.017""; d5+1"; 18const char wac18[] PROGMEM="R7/P4k2/8/8/8/8/r7/6K1 w - - bm Rh8; id ""WAC.018""; d6+6"; 19const char wac19[] PROGMEM="r1b2rk1/ppbn1ppp/4p3/1QP4q/3P4/N4N2/5PPP/R1B2RK1 w - - bm c6; id ""WAC.019""; d6+0.7"; 20const char wac20[] PROGMEM="r2qkb1r/1ppb1ppp/p7/4p3/P1Q1P3/2P5/5PPP/R1B2KNR b kq - bm Bb5; id ""WAC.020""; d6+7"; 21const char wac21[] PROGMEM="5rk1/1b3p1p/pp3p2/3n1N2/1P6/P1qB1PP1/3Q3P/4R1K1 w - - bm Qh6; id ""WAC.021""; d5+6"; 22const char wac22[] PROGMEM="r1bqk2r/ppp1nppp/4p3/n5N1/2BPp3/P1P5/2P2PPP/R1BQK2R w KQkq - bm Ba2 Nxf7; id ""WAC.022""; Nxf7 d5+0.5"; 23const char wac23[] PROGMEM="r3nrk1/2p2p1p/p1p1b1p1/2NpPq2/3R4/P1N1Q3/1PP2PPP/4R1K1 w - - bm g4; id ""WAC.023""; d5+4"; 24const char wac24[] PROGMEM="6k1/1b1nqpbp/pp4p1/5P2/1PN5/4Q3/P5PP/1B2B1K1 b - - bm Bd4; id ""WAC.024""; d5+7"; 25const char wac25[] PROGMEM="3R1rk1/8/5Qpp/2p5/2P1p1q1/P3P3/1P2PK2/8 b - - bm Qh4+; id ""WAC.025""; d5+12"; 26const char wac26[] PROGMEM="3r2k1/1p1b1pp1/pq5p/8/3NR3/2PQ3P/PP3PP1/6K1 b - - bm Bf5; id ""WAC.026""; d5+1.2"; 27const char wac27[] PROGMEM="7k/pp4np/2p3p1/3pN1q1/3P4/Q7/1r3rPP/2R2RK1 w - - bm Qf8+; id ""WAC.027""; d5+m2"; 28const char wac28[] PROGMEM="1r1r2k1/4pp1p/2p1b1p1/p3R3/RqBP4/4P3/1PQ2PPP/6K1 b - - bm Qe1+; id ""WAC.028""; d5+3"; 29const char wac29[] PROGMEM="r2q2k1/pp1rbppp/4pn2/2P5/1P3B2/6P1/P3QPBP/1R3RK1 w - - bm c6; id ""WAC.029""; d5+1"; 30const char wac30[] PROGMEM="1r3r2/4q1kp/b1pp2p1/5p2/pPn1N3/6P1/P3PPBP/2QRR1K1 w - - bm Nxd6; id ""WAC.030""; d7+0.7"; 31const char wac31[] PROGMEM="rb3qk1/pQ3ppp/4p3/3P4/8/1P3N2/1P3PPP/3R2K1 w - - bm Qxa8 d6 dxe6 g3; id ""WAC.031""; d6 d5+3 g3 d10+3.3"; 32const char wac32[] PROGMEM="6k1/p4p1p/1p3np1/2q5/4p3/4P1N1/PP3PPP/3Q2K1 w - - bm Qd8+; id ""WAC.032""; d5+1.7"; 33const char wac33[] PROGMEM="8/p1q2pkp/2Pr2p1/8/P3Q3/6P1/5P1P/2R3K1 w - - bm Qe5+ Qf4; id ""WAC.033""; d6+5"; 34const char wac34[] PROGMEM="7k/1b1r2p1/p6p/1p2qN2/3bP3/3Q4/P5PP/1B1R3K b - - bm Bg1; id ""WAC.034""; d5+2.7"; 35const char wac35[] PROGMEM="r3r2k/2R3pp/pp1q1p2/8/3P3R/7P/PP3PP1/3Q2K1 w - - bm Rxh7+; id ""WAC.035""; d5+m4"; 36const char wac36[] PROGMEM="3r4/2p1rk2/1pQq1pp1/7p/1P1P4/P4P2/6PP/R1R3K1 b - - bm Re1+; id ""WAC.036""; d5+4"; 37const char wac37[] PROGMEM="2r5/2rk2pp/1pn1pb2/pN1p4/P2P4/1N2B3/nPR1KPPP/3R4 b - - bm Nxd4+; id ""WAC.037""; d5+1"; 38const char wac38[] PROGMEM="4k3/p4prp/1p6/2b5/8/2Q3P1/P2R1PKP/4q3 w - - bm Qd3 Rd8+; id ""WAC.038""; Rd8+ 5+1.5 Qd3 13+1.8"; 39const char wac39[] PROGMEM="r1br2k1/pp2bppp/2nppn2/8/2P1PB2/2N2P2/PqN1B1PP/R2Q1R1K w - - bm Na4; id ""WAC.039""; d5+2.3"; 40const char wac40[] PROGMEM="3r1r1k/1p4pp/p4p2/8/1PQR4/6Pq/P3PP2/2R3K1 b - - bm Rc8; id ""WAC.040""; d5+3.8"; 41const char wac41[] PROGMEM="1k6/5RP1/1P6/1K6/6r1/8/8/8 w - - bm Ka5 Kc5 b7; id ""WAC.041""; Ka5 d6+16"; 42const char wac42[] PROGMEM="r1b1r1k1/pp1n1pbp/1qp3p1/3p4/1B1P4/Q3PN2/PP2BPPP/R4RK1 w - - bm Ba5; id ""WAC.042""; d5+3"; 43const char wac43[] PROGMEM="r2q3k/p2P3p/1p3p2/3QP1r1/8/B7/P5PP/2R3K1 w - - bm Be7 Qxa8; id ""WAC.043""; Be7 d6+12"; 44const char wac44[] PROGMEM="3rb1k1/pq3pbp/4n1p1/3p4/2N5/2P2QB1/PP3PPP/1B1R2K1 b - - bm dxc4; id ""WAC.044""; d6+2"; 45const char wac45[] PROGMEM="7k/2p1b1pp/8/1p2P3/1P3r2/2P3Q1/1P5P/R4qBK b - - bm Qxa1; id ""WAC.045""; d6+5"; 46const char wac46[] PROGMEM="r1bqr1k1/pp1nb1p1/4p2p/3p1p2/3P4/P1N1PNP1/1PQ2PP1/3RKB1R w K - bm Nb5; id ""WAC.046""; d5+0.5"; 47const char wac47[] PROGMEM="r1b2rk1/pp2bppp/2n1pn2/q5B1/2BP4/2N2N2/PP2QPPP/2R2RK1 b - - bm Nxd4; id ""WAC.047""; d5+0.3"; 48const char wac48[] PROGMEM="1rbq1rk1/p1p1bppp/2p2n2/8/Q1BP4/2N5/PP3PPP/R1B2RK1 b - - bm Rb4; id ""WAC.048""; d5+1.7"; 49const char wac49[] PROGMEM="2b3k1/4rrpp/p2p4/2pP2RQ/1pP1Pp1N/1P3P1P/1q6/6RK w - - bm Qxh7+; id ""WAC.049""; d7+m6"; 50const char wac50[] PROGMEM="k4r2/1R4pb/1pQp1n1p/3P4/5p1P/3P2P1/r1q1R2K/8 w - - bm Rxb6+; id ""WAC.050""; d5+m3"; 51const char wac51[] PROGMEM="r1bq1r2/pp4k1/4p2p/3pPp1Q/3N1R1P/2PB4/6P1/6K1 w - - bm Rg4+; id ""WAC.051""; d5+9 d11+m8"; 52const char wac52[] PROGMEM="r1k5/1p3q2/1Qpb4/3N1p2/5Pp1/3P2Pp/PPPK3P/4R3 w - - bm Re7 c4; id ""WAC.052""; Re7 d5+4"; 53const char wac53[] PROGMEM="6k1/6p1/p7/3Pn3/5p2/4rBqP/P4RP1/5QK1 b - - bm Re1; id ""WAC.053""; d5+4"; 54const char wac54[] PROGMEM="r3kr2/1pp4p/1p1p4/7q/4P1n1/2PP2Q1/PP4P1/R1BB2K1 b q - bm Qh1+; id ""WAC.054"";"; 55const char wac55[] PROGMEM="r3r1k1/pp1q1pp1/4b1p1/3p2B1/3Q1R2/8/PPP3PP/4R1K1 w - - bm Qxg7+; id ""WAC.055""; d8+m4"; 56const char wac56[] PROGMEM="r1bqk2r/pppp1ppp/5n2/2b1n3/4P3/1BP3Q1/PP3PPP/RNB1K1NR b KQkq - bm Bxf2+; id ""WAC.056""; d5+4"; 57const char wac57[] PROGMEM="r3q1kr/ppp5/3p2pQ/8/3PP1b1/5R2/PPP3P1/5RK1 w - - bm Rf8+; id ""WAC.057""; d5+m3"; 58const char wac58[] PROGMEM="8/8/2R5/1p2qp1k/1P2r3/2PQ2P1/5K2/8 w - - bm Qd1+; id ""WAC.058""; d5+7"; 59const char wac59[] PROGMEM="r1b2rk1/2p1qnbp/p1pp2p1/5p2/2PQP3/1PN2N1P/PB3PP1/3R1RK1 w - - bm Nd5; id ""WAC.059""; d5+4"; 60const char wac60[] PROGMEM="rn1qr1k1/1p2np2/2p3p1/8/1pPb4/7Q/PB1P1PP1/2KR1B1R w - - bm Qh8+; id ""WAC.060""; d5+m2"; 61const char wac61[] PROGMEM="3qrbk1/ppp1r2n/3pP2p/3P4/2P4P/1P3Q2/PB6/R4R1K w - - bm Qf7+; id ""WAC.061""; d5+m2"; 62const char wac62[] PROGMEM="6r1/3Pn1qk/p1p1P1rp/2Q2p2/2P5/1P4P1/P3R2P/5RK1 b - - bm Rxg3+; id ""WAC.062""; d6+0"; 63const char wac63[] PROGMEM="r1brnbk1/ppq2pp1/4p2p/4N3/3P4/P1PB1Q2/3B1PPP/R3R1K1 w - - bm Nxf7; id ""WAC.063""; d5+2"; 64const char wac64[] PROGMEM="8/6pp/3q1p2/3n1k2/1P6/3NQ2P/5PP1/6K1 w - - bm g4+; id ""WAC.064""; d5+m2"; 65const char wac65[] PROGMEM="1r1r1qk1/p2n1p1p/bp1Pn1pQ/2pNp3/2P2P1N/1P5B/P6P/3R1RK1 w - - bm Ne7+; id ""WAC.065""; d5+9"; 66const char wac66[] PROGMEM="1k1r2r1/ppq5/1bp4p/3pQ3/8/2P2N2/PP4P1/R4R1K b - - bm Qxe5; id ""WAC.066""; d5+4"; 67const char wac67[] PROGMEM="3r2k1/p2q4/1p4p1/3rRp1p/5P1P/6PK/P3R3/3Q4 w - - bm Rxd5; id ""WAC.067""; d5+4"; 68const char wac68[] PROGMEM="6k1/5ppp/1q6/2b5/8/2R1pPP1/1P2Q2P/7K w - - bm Qxe3; id ""WAC.068""; d5+6"; 69const char wac69[] PROGMEM="2k5/pppr4/4R3/4Q3/2pp2q1/8/PPP2PPP/6K1 w - - bm f3 h3; id ""WAC.069""; f3 d7+6"; 70const char wac70[] PROGMEM="2kr3r/pppq1ppp/3p1n2/bQ2p3/1n1PP3/1PN1BN1P/1PP2PP1/2KR3R b - - bm Na2+; id ""WAC.070""; d5+4"; 71const char wac71[] PROGMEM="2kr3r/pp1q1ppp/5n2/1Nb5/2Pp1B2/7Q/P4PPP/1R3RK1 w - - bm Nxa7+; id ""WAC.071""; d8+3"; 72const char wac72[] PROGMEM="r3r1k1/pp1n1ppp/2p5/4Pb2/2B2P2/B1P5/P5PP/R2R2K1 w - - bm e6; id ""WAC.072""; d5+2"; 73const char wac73[] PROGMEM="r1q3rk/1ppbb1p1/4Np1p/p3pP2/P3P3/2N4R/1PP1Q1PP/3R2K1 w - - bm Qd2; id ""WAC.073""; d5+3.5"; 74const char wac74[] PROGMEM="5r1k/pp4pp/2p5/2b1P3/4Pq2/1PB1p3/P3Q1PP/3N2K1 b - - bm Qf1+; id ""WAC.074""; d5+7"; 75const char wac75[] PROGMEM="r3r1k1/pppq1ppp/8/8/1Q4n1/7P/PPP2PP1/RNB1R1K1 b - - bm Qd6; id ""WAC.075""; d5+4"; 76const char wac76[] PROGMEM="r1b1qrk1/2p2ppp/pb1pnn2/1p2pNB1/3PP3/1BP5/PP2QPPP/RN1R2K1 w - - bm Bxf6; id ""WAC.076""; d5+2"; 77const char wac77[] PROGMEM="3r2k1/ppp2ppp/6q1/b4n2/3nQB2/2p5/P4PPP/RN3RK1 b - - bm Ng3; id ""WAC.077""; d5+8"; 78const char wac78[] PROGMEM="r2q3r/ppp2k2/4nbp1/5Q1p/2P1NB2/8/PP3P1P/3RR1K1 w - - bm Ng5+; id ""WAC.078""; d5+4.5"; 79const char wac79[] PROGMEM="r3k2r/pbp2pp1/3b1n2/1p6/3P3p/1B2N1Pq/PP1PQP1P/R1B2RK1 b kq - bm Qxh2+; id ""WAC.079""; d5+m3"; 80const char wac80[] PROGMEM="r4rk1/p1B1bpp1/1p2pn1p/8/2PP4/3B1P2/qP2QP1P/3R1RK1 w - - bm Ra1; id ""WAC.080""; d9+3"; 81const char wac81[] PROGMEM="r4rk1/1bR1bppp/4pn2/1p2N3/1P6/P3P3/4BPPP/3R2K1 b - - bm Bd6; id ""WAC.081""; d5+0.5"; 82const char wac82[] PROGMEM="3rr1k1/pp3pp1/4b3/8/2P1B2R/6QP/P3q1P1/5R1K w - - bm Bh7+; id ""WAC.082""; d5+8"; 83const char wac83[] PROGMEM="3rr1k1/ppqbRppp/2p5/8/3Q1n2/2P3N1/PPB2PPP/3R2K1 w - - bm Qxd7; id ""WAC.083""; d5+3.5"; 84const char wac84[] PROGMEM="r2q1r1k/2p1b1pp/p1n5/1p1Q1bN1/4n3/1BP1B3/PP3PPP/R4RK1 w - - bm Qg8+; id ""WAC.084""; d5+m2"; 85const char wac85[] PROGMEM="kr2R3/p4r2/2pq4/2N2p1p/3P2p1/Q5P1/5P1P/5BK1 w - - bm Na6; id ""WAC.085""; d5+6 d7+10"; 86const char wac86[] PROGMEM="8/p7/1ppk1n2/5ppp/P1PP4/2P1K1P1/5N1P/8 b - - bm Ng4+; id ""WAC.086""; d5+0.5"; 87const char wac87[] PROGMEM="8/p3k1p1/4r3/2ppNpp1/PP1P4/2P3KP/5P2/8 b - - bm Rxe5; id ""WAC.087""; d8+6"; 88const char wac88[] PROGMEM="r6k/p1Q4p/2p1b1rq/4p3/B3P3/4P3/PPP3P1/4RRK1 b - - bm Rxg2+; id ""WAC.088""; d5+m5"; 89const char wac89[] PROGMEM="1r3b1k/p4rpp/4pp2/3q4/2ppbPPQ/6RK/PP5P/2B1NR2 b - - bm g5; id ""WAC.089""; d5+7"; 90const char wac90[] PROGMEM="3qrrk1/1pp2pp1/1p2bn1p/5N2/2P5/P1P3B1/1P4PP/2Q1RRK1 w - - bm Nxg7; id ""WAC.090""; d5+2.5"; 91const char wac91[] PROGMEM="2qr2k1/4b1p1/2p2p1p/1pP1p3/p2nP3/PbQNB1PP/1P3PK1/4RB2 b - - bm Be6; id ""WAC.091""; d6+1"; 92const char wac92[] PROGMEM="r4rk1/1p2ppbp/p2pbnp1/q7/3BPPP1/2N2B2/PPP4P/R2Q1RK1 b - - bm Bxg4; id ""WAC.092""; d9+0.7"; 93const char wac93[] PROGMEM="r1b1k1nr/pp3pQp/4pq2/3pn3/8/P1P5/2P2PPP/R1B1KBNR w KQkq - bm Bh6; id ""WAC.093""; d5+1"; 94const char wac94[] PROGMEM="8/k7/p7/3Qp2P/n1P5/3KP3/1q6/8 b - - bm e4+; id ""WAC.094""; d5+9"; 95const char wac95[] PROGMEM="2r5/1r6/4pNpk/3pP1qp/8/2P1QP2/5PK1/R7 w - - bm Ng4+; id ""WAC.095""; d5+9"; 96const char wac96[] PROGMEM="r1b4k/ppp2Bb1/6Pp/3pP3/1qnP1p1Q/8/PPP3P1/1K1R3R w - - bm Qd8+ b3; id ""WAC.096""; d5+2 d14+m9"; 97const char wac97[] PROGMEM="6k1/5p2/p5np/4B3/3P4/1PP1q3/P3r1QP/6RK w - - bm Qa8+; id ""WAC.097"";"; 98const char wac98[] PROGMEM="1r3rk1/5pb1/p2p2p1/Q1n1q2p/1NP1P3/3p1P1B/PP1R3P/1K2R3 b - - bm Nxe4; id ""WAC.098""; d5+5"; 99const char wac99[] PROGMEM="r1bq1r1k/1pp1Np1p/p2p2pQ/4R3/n7/8/PPPP1PPP/R1B3K1 w - - bm Rh5; id ""WAC.099""; d5+m2"; 100const char wac100[] PROGMEM="8/k1b5/P4p2/1Pp2p1p/K1P2P1P/8/3B4/8 w - - bm Be3 b6+; id ""WAC.100""; Be3 d14+2.6 b6+ d17+4"; 101const char wac101[] PROGMEM="5rk1/p5pp/8/8/2Pbp3/1P4P1/7P/4RN1K b - - bm Bc3; id ""WAC.101""; d10+1.5"; 102const char wac102[] PROGMEM="2Q2n2/2R4p/1p1qpp1k/8/3P3P/3B2P1/5PK1/r7 w - - bm Qxf8+; id ""WAC.102""; d5+m3"; 103const char wac103[] PROGMEM="6k1/2pb1r1p/3p1PpQ/p1nPp3/1q2P3/2N2P2/PrB5/2K3RR w - - bm Qxg6+; id ""WAC.103""; d5+m4"; 104const char wac104[] PROGMEM="b4r1k/pq2rp2/1p1bpn1p/3PN2n/2P2P2/P2B3K/1B2Q2N/3R2R1 w - - bm Qxh5; id ""WAC.104""; d5+m3"; 105const char wac105[] PROGMEM="r2r2k1/pb3ppp/1p1bp3/7q/3n2nP/PP1B2P1/1B1N1P2/RQ2NRK1 b - - bm Bxg3 Qxh4; id ""WAC.105""; Qxh4 d7+m8 d8+m6"; 106const char wac106[] PROGMEM="4rrk1/pppb4/7p/3P2pq/3Qn3/P5P1/1PP4P/R3RNNK b - - bm Nf2+; id ""WAC.106""; d5+9"; 107const char wac107[] PROGMEM="5n2/pRrk2p1/P4p1p/4p3/3N4/5P2/6PP/6K1 w - - bm Nb5; id ""WAC.107""; d5+3"; 108const char wac108[] PROGMEM="r5k1/1q4pp/2p5/p1Q5/2P5/5R2/4RKPP/r7 w - - bm Qe5; id ""WAC.108""; d5+3"; 109const char wac109[] PROGMEM="rn2k1nr/pbp2ppp/3q4/1p2N3/2p5/QP6/PB1PPPPP/R3KB1R b KQkq - bm c3; id ""WAC.109""; d7+0.5"; 110const char wac110[] PROGMEM="2kr4/bp3p2/p2p2b1/P7/2q5/1N4B1/1PPQ2P1/2KR4 b - - bm Be3; id ""WAC.110""; d5+7"; 111const char wac111[] PROGMEM="6k1/p5p1/5p2/2P2Q2/3pN2p/3PbK1P/7P/6q1 b - - bm Qf1+; id ""WAC.111""; d5+10"; 112const char wac112[] PROGMEM="r4kr1/ppp5/4bq1b/7B/2PR1Q1p/2N3P1/PP3P1P/2K1R3 w - - bm Rxe6; id ""WAC.112""; d5+2.5"; 113const char wac113[] PROGMEM="rnbqkb1r/1p3ppp/5N2/1p2p1B1/2P5/8/PP2PPPP/R2QKB1R b KQkq - bm Qxf6; id ""WAC.113""; d5+1"; 114const char wac114[] PROGMEM="r1b1rnk1/1p4pp/p1p2p2/3pN2n/3P1PPq/2NBPR1P/PPQ5/2R3K1 w - - bm Bxh7+; id ""WAC.114""; d5+2.5"; 115const char wac115[] PROGMEM="4N2k/5rpp/1Q6/p3q3/8/P5P1/1P3P1P/5K2 w - - bm Nd6; id ""WAC.115""; d5+2.5"; 116const char wac116[] PROGMEM="r2r2k1/2p2ppp/p7/1p2P1n1/P6q/5P2/1PB1QP1P/R5RK b - - bm Rd2; id ""WAC.116""; d8+2"; 117const char wac117[] PROGMEM="3r1rk1/q4ppp/p1Rnp3/8/1p6/1N3P2/PP3QPP/3R2K1 b - - bm Ne4; id ""WAC.117""; d5+6"; 118const char wac118[] PROGMEM="r5k1/pb2rpp1/1p6/2p4q/5R2/2PB2Q1/P1P3PP/5R1K w - - bm Rh4; id ""WAC.118""; d5+4"; 119const char wac119[] PROGMEM="r2qr1k1/p1p2ppp/2p5/2b5/4nPQ1/3B4/PPP3PP/R1B2R1K b - - bm Qxd3; id ""WAC.119""; d5+4"; 120const char wac120[] PROGMEM="r4rk1/1bn2qnp/3p1B1Q/p2P1pP1/1pp5/5N1P/PPB2P2/2KR3R w - - bm Rhg1 g6; id ""WAC.120""; g6 d7+3"; 121const char wac121[] PROGMEM="6k1/5p1p/2bP2pb/4p3/2P5/1p1pNPPP/1P1Q1BK1/1q6 b - - bm Bxf3+; id ""WAC.121""; d5+11"; 122const char wac122[] PROGMEM="1k6/ppp4p/1n2pq2/1N2Rb2/2P2Q2/8/P4KPP/3r1B2 b - - bm Rxf1+; id ""WAC.122""; d5+12"; 123const char wac123[] PROGMEM="6k1/1b2rp2/1p4p1/3P4/PQ4P1/2N2q2/5P2/3R2K1 b - - bm Bxd5 Rc7 Re6; id ""WAC.123""; Rc7 d5+2 Bxd5 d10+4 Re6 d17+6"; 124const char wac124[] PROGMEM="6k1/3r4/2R5/P5P1/1P4p1/8/4rB2/6K1 b - - bm g3; id ""WAC.124""; d5+2"; 125const char wac125[] PROGMEM="r1bqr1k1/pp3ppp/1bp5/3n4/3B4/2N2P1P/PPP1B1P1/R2Q1RK1 b - - bm Bxd4+; id ""WAC.125""; d5+3"; 126const char wac126[] PROGMEM="r5r1/pQ5p/1qp2R2/2k1p3/4P3/2PP4/P1P3PP/6K1 w - - bm Rxc6+; id ""WAC.126""; d5+4"; 127const char wac127[] PROGMEM="2k4r/1pr1n3/p1p1q2p/5pp1/3P1P2/P1P1P3/1R2Q1PP/1RB3K1 w - - bm Rxb7; id ""WAC.127""; d5+3"; 128const char wac128[] PROGMEM="6rk/1pp2Qrp/3p1B2/1pb1p2R/3n1q2/3P4/PPP3PP/R6K w - - bm Qg6; id ""WAC.128""; d5+2"; 129const char wac129[] PROGMEM="3r1r1k/1b2b1p1/1p5p/2p1Pp2/q1B2P2/4P2P/1BR1Q2K/6R1 b - - bm Bf3; id ""WAC.129""; d5+1.3"; 130const char wac130[] PROGMEM="6k1/1pp3q1/5r2/1PPp4/3P1pP1/3Qn2P/3B4/4R1K1 b - - bm Qh6 Qh8; id ""WAC.130""; Qh6 d5+1"; 131const char wac131[] PROGMEM="2rq1bk1/p4p1p/1p4p1/3b4/3B1Q2/8/P4PpP/3RR1K1 w - - bm Re8; id ""WAC.131""; d6+2"; 132const char wac132[] PROGMEM="4r1k1/5bpp/2p5/3pr3/8/1B3pPq/PPR2P2/2R2QK1 b - - bm Re1; id ""WAC.132""; d5+m3"; 133const char wac133[] PROGMEM="r1b1k2r/1pp1q2p/p1n3p1/3QPp2/8/1BP3B1/P5PP/3R1RK1 w kq - bm Bh4; id ""WAC.133""; d5+3"; 134const char wac134[] PROGMEM="3r2k1/p6p/2Q3p1/4q3/2P1p3/P3Pb2/1P3P1P/2K2BR1 b - - bm Rd1+; id ""WAC.134""; d5+m4"; 135const char wac135[] PROGMEM="3r1r1k/N2qn1pp/1p2np2/2p5/2Q1P2N/3P4/PP4PP/3R1RK1 b - - bm Nd4; id ""WAC.135""; d5+1.3"; 136const char wac136[] PROGMEM="6kr/1q2r1p1/1p2N1Q1/5p2/1P1p4/6R1/7P/2R3K1 w - - bm Rc8+; id ""WAC.136""; Qf6 d6+m6 Rc8+ d8+m3"; 137const char wac137[] PROGMEM="3b1rk1/1bq3pp/5pn1/1p2rN2/2p1p3/2P1B2Q/1PB2PPP/R2R2K1 w - - bm Rd7; id ""WAC.137""; d5+2"; 138const char wac138[] PROGMEM="r1bq3r/ppppR1p1/5n1k/3P4/6pP/3Q4/PP1N1PP1/5K1R w - - bm h5; id ""WAC.138""; d5+m7 d8+m5"; 139const char wac139[] PROGMEM="rnb3kr/ppp2ppp/1b6/3q4/3pN3/Q4N2/PPP2KPP/R1B1R3 w - - bm Nf6+; id ""WAC.139""; d5+m4"; 140const char wac140[] PROGMEM="r2b1rk1/pq4p1/4ppQP/3pB1p1/3P4/2R5/PP3PP1/5RK1 w - - bm Bc7 Rc7; id ""WAC.140""; Rc7 d5+9"; 141const char wac141[] PROGMEM="4r1k1/p1qr1p2/2pb1Bp1/1p5p/3P1n1R/1B3P2/PP3PK1/2Q4R w - - bm Qxf4; id ""WAC.141""; d10+19 d12+m6"; 142const char wac142[] PROGMEM="r2q3n/ppp2pk1/3p4/5Pr1/2NP1Qp1/2P2pP1/PP3K2/4R2R w - - bm Re8 f6+; id ""WAC.142""; f6+ d5+3"; 143const char wac143[] PROGMEM="5b2/pp2r1pk/2pp1pRp/4rP1N/2P1P3/1P4QP/P3q1P1/5R1K w - - bm Rxh6+; id ""WAC.143""; d5+m3"; 144const char wac144[] PROGMEM="r2q1rk1/pp3ppp/2p2b2/8/B2pPPb1/7P/PPP1N1P1/R2Q1RK1 b - - bm d3; id ""WAC.144""; d5+1.6"; 145const char wac145[] PROGMEM="r1bq4/1p4kp/3p1n2/p4pB1/2pQ4/8/1P4PP/4RRK1 w - - bm Re8; id ""WAC.145""; d8+15"; 146const char wac146[] PROGMEM="8/8/2Kp4/3P1B2/2P2k2/5p2/8/8 w - - bm Bc8 Bd3 Bh3; id ""WAC.146""; Bc8 d5+2"; 147const char wac147[] PROGMEM="r2r2k1/ppqbppbp/2n2np1/2pp4/6P1/1P1PPNNP/PBP2PB1/R2QK2R b KQ - bm Nxg4; id ""WAC.147""; d5+1.7"; 148const char wac148[] PROGMEM="2r1k3/6pr/p1nBP3/1p3p1p/2q5/2P5/P1R4P/K2Q2R1 w - - bm Rxg7; id ""WAC.148""; d5+9"; 149const char wac149[] PROGMEM="6k1/6p1/2p4p/4Pp2/4b1qP/2Br4/1P2RQPK/8 b - - bm Bxg2; id ""WAC.149""; d5+2"; 150const char wac150[] PROGMEM="r3r1k1/5p2/pQ1b2pB/1p6/4p3/6P1/Pq2BP1P/2R3K1 b - - bm Ba3 Be5 Bf8 e3; c0 ""All win but e3 is best.""; id ""WAC.150""; e3 d3+3.5"; 151const char wac151[] PROGMEM="8/3b2kp/4p1p1/pr1n4/N1N4P/1P4P1/1K3P2/3R4 w - - bm Nc3; id ""WAC.151""; d5+1"; 152const char wac152[] PROGMEM="1br2rk1/1pqb1ppp/p3pn2/8/1P6/P1N1PN1P/1B3PP1/1QRR2K1 w - - bm Ne4; id ""WAC.152""; d5+2"; 153const char wac153[] PROGMEM="2r3k1/q4ppp/p3p3/pnNp4/2rP4/2P2P2/4R1PP/2R1Q1K1 b - - bm Nxd4; id ""WAC.153""; d5+2"; 154const char wac154[] PROGMEM="r1b2rk1/2p2ppp/p7/1p6/3P3q/1BP3bP/PP3QP1/RNB1R1K1 w - - bm Qxf7+; id ""WAC.154""; d5+m2"; 155const char wac155[] PROGMEM="5bk1/1rQ4p/5pp1/2pP4/3n1PP1/7P/1q3BB1/4R1K1 w - - bm d6; id ""WAC.155""; d5+2.5"; 156const char wac156[] PROGMEM="r1b1qN1k/1pp3p1/p2p3n/4p1B1/8/1BP4Q/PP3KPP/8 w - - bm Qxh6+; id ""WAC.156""; d5+m2"; 157const char wac157[] PROGMEM="5rk1/p4ppp/2p1b3/3Nq3/4P1n1/1p1B2QP/1PPr2P1/1K2R2R w - - bm Ne7+; id ""WAC.157""; d7+1.5"; 158const char wac158[] PROGMEM="5rk1/n1p1R1bp/p2p4/1qpP1QB1/7P/2P3P1/PP3P2/6K1 w - - bm Rxg7+; id ""WAC.158""; d5+m3"; 159const char wac159[] PROGMEM="r1b2r2/5P1p/ppn3pk/2p1p1Nq/1bP1PQ2/3P4/PB4BP/1R3RK1 w - - bm Ne6+; id ""WAC.159""; d5+6"; 160const char wac160[] PROGMEM="qn1kr2r/1pRbb3/pP5p/P2pP1pP/3N1pQ1/3B4/3B1PP1/R5K1 w - - bm Qxd7+; id ""WAC.160""; d5+m2"; 161const char wac161[] PROGMEM="3r3k/3r1P1p/pp1Nn3/2pp4/7Q/6R1/Pq4PP/5RK1 w - - bm Qxd8+; id ""WAC.161""; d5+m4"; 162const char wac162[] PROGMEM="r3kbnr/p4ppp/2p1p3/8/Q1B3b1/2N1B3/PP3PqP/R3K2R w KQkq - bm Bd5; id ""WAC.162""; d5+1.2"; 163const char wac163[] PROGMEM="5rk1/2p4p/2p4r/3P4/4p1b1/1Q2NqPp/PP3P1K/R4R2 b - - bm Qg2+; id ""WAC.163""; d12+m11"; 164const char wac164[] PROGMEM="8/6pp/4p3/1p1n4/1NbkN1P1/P4P1P/1PR3K1/r7 w - - bm Rxc4+; id ""WAC.164""; d5+3.5"; 165const char wac165[] PROGMEM="1r5k/p1p3pp/8/8/4p3/P1P1R3/1P1Q1qr1/2KR4 w - - bm Re2; id ""WAC.165""; d5+3.5"; 166const char wac166[] PROGMEM="r3r1k1/5pp1/p1p4p/2Pp4/8/q1NQP1BP/5PP1/4K2R b K - bm d4; id ""WAC.166""; d5+2"; 167const char wac167[] PROGMEM="7Q/ppp2q2/3p2k1/P2Ppr1N/1PP5/7R/5rP1/6K1 b - - bm Rxg2+; id ""WAC.167""; d5+m5"; 168const char wac168[] PROGMEM="r3k2r/pb1q1p2/8/2p1pP2/4p1p1/B1P1Q1P1/P1P3K1/R4R2 b kq - bm Qd2+; id ""WAC.168""; d5+17 d9+m11 d11+m8"; 169const char wac169[] PROGMEM="5rk1/1pp3bp/3p2p1/2PPp3/1P2P3/2Q1B3/4q1PP/R5K1 b - - bm Bh6; id ""WAC.169""; d7+4"; 170const char wac170[] PROGMEM="5r1k/6Rp/1p2p3/p2pBp2/1qnP4/4P3/Q4PPP/6K1 w - - bm Qxc4; id ""WAC.170""; d5+4"; 171const char wac171[] PROGMEM="2rq4/1b2b1kp/p3p1p1/1p1nNp2/7P/1B2B1Q1/PP3PP1/3R2K1 w - - bm Bh6+; id ""WAC.171""; d5+1.8"; 172const char wac172[] PROGMEM="5r1k/p5pp/8/1P1pq3/P1p2nR1/Q7/5BPP/6K1 b - - bm Qe1+; id ""WAC.172""; d5+m3"; 173const char wac173[] PROGMEM="2r1b3/1pp1qrk1/p1n1P1p1/7R/2B1p3/4Q1P1/PP3PP1/3R2K1 w - - bm Qh6+; id ""WAC.173""; d5+m3"; 174const char wac174[] PROGMEM="2r2rk1/6p1/p3pq1p/1p1b1p2/3P1n2/PP3N2/3N1PPP/1Q2RR1K b - - bm Nxg2; id ""WAC.174""; d5+2"; 175const char wac175[] PROGMEM="r5k1/pppb3p/2np1n2/8/3PqNpP/3Q2P1/PPP5/R4RK1 w - - bm Nh5; id ""WAC.175""; d5+1.7"; 176const char wac176[] PROGMEM="r1bq3r/ppp2pk1/3p1pp1/8/2BbPQ2/2NP2P1/PPP4P/R4R1K b - - bm Rxh2+; id ""WAC.176""; d5+2"; 177const char wac177[] PROGMEM="r1b3r1/4qk2/1nn1p1p1/3pPp1P/p4P2/1p3BQN/PKPBN3/3R3R b - - bm Qa3+; id ""WAC.177""; d5+m3"; 178const char wac178[] PROGMEM="3r2k1/p1rn1p1p/1p2pp2/6q1/3PQNP1/5P2/P1P4R/R5K1 w - - bm Nxe6; id ""WAC.178""; d6+1"; 179const char wac179[] PROGMEM="r1b2r1k/pp4pp/3p4/3B4/8/1QN3Pn/PP3q1P/R3R2K b - - bm Qg1+; id ""WAC.179""; d5+m3"; 180const char wac180[] PROGMEM="r1q2rk1/p3bppb/3p1n1p/2nPp3/1p2P1P1/6NP/PP2QPB1/R1BNK2R b KQ - bm Nxd5; id ""WAC.180""; d5+1"; 181const char wac181[] PROGMEM="r3k2r/2p2p2/p2p1n2/1p2p3/4P2p/1PPPPp1q/1P5P/R1N2QRK b kq - bm Ng4; id ""WAC.181""; d5+5.5"; 182const char wac182[] PROGMEM="r1b2rk1/ppqn1p1p/2n1p1p1/2b3N1/2N5/PP1BP3/1B3PPP/R2QK2R w KQ - bm Qh5; id ""WAC.182""; d5+m7 d11+m6"; 183const char wac183[] PROGMEM="1r2k1r1/5p2/b3p3/1p2b1B1/3p3P/3B4/PP2KP2/2R3R1 w - - bm Bf6; id ""WAC.183""; d5+1.7"; 184const char wac184[] PROGMEM="4kn2/r4p1r/p3bQ2/q1nNP1Np/1p5P/8/PPP3P1/2KR3R w - - bm Qe7+; id ""WAC.184""; d5+m2"; 185const char wac185[] PROGMEM="1r1rb1k1/2p3pp/p2q1p2/3PpP1Q/Pp1bP2N/1B5R/1P4PP/2B4K w - - bm Qxh7+; id ""WAC.185""; d6+4"; 186const char wac186[] PROGMEM="r5r1/p1q2p1k/1p1R2pB/3pP3/6bQ/2p5/P1P1NPPP/6K1 w - - bm Bf8+; id ""WAC.186""; d5+m3"; 187const char wac187[] PROGMEM="6k1/5p2/p3p3/1p3qp1/2p1Qn2/2P1R3/PP1r1PPP/4R1K1 b - - bm Nh3+; id ""WAC.187""; d5+6"; 188const char wac188[] PROGMEM="3RNbk1/pp3p2/4rQpp/8/1qr5/7P/P4P2/3R2K1 w - - bm Qg7+; id ""WAC.188""; d5+m2"; 189const char wac189[] PROGMEM="3r1k2/1ppPR1n1/p2p1rP1/3P3p/4Rp1N/5K2/P1P2P2/8 w - - bm Re8+; id ""WAC.189""; d6+7"; 190const char wac190[] PROGMEM="8/p2b2kp/1q1p2p1/1P1Pp3/4P3/3B2P1/P2Q3P/2Nn3K b - - bm Bh3; id ""WAC.190""; d5+6"; 191const char wac191[] PROGMEM="2r1Rn1k/1p1q2pp/p7/5p2/3P4/1B4P1/P1P1QP1P/6K1 w - - bm Qc4; id ""WAC.191""; d5+m3"; 192const char wac192[] PROGMEM="r3k3/ppp2Npp/4Bn2/2b5/1n1pp3/N4P2/PPP3qP/R2QKR2 b Qq - bm Nd3+; id ""WAC.192""; d5+6"; 193const char wac193[] PROGMEM="5bk1/p4ppp/Qp6/4B3/1P6/Pq2P1P1/2rr1P1P/R4RK1 b - - bm Qxe3; id ""WAC.193""; d6+8 d11+m8"; 194const char wac194[] PROGMEM="5rk1/ppq2ppp/2p5/4bN2/4P3/6Q1/PPP2PPP/3R2K1 w - - bm Nh6+; id ""WAC.194""; d6+5"; 195const char wac195[] PROGMEM="3r1rk1/1p3p2/p3pnnp/2p3p1/2P2q2/1P5P/PB2QPPN/3RR1K1 w - - bm g3; id ""WAC.195""; d5+2"; 196const char wac196[] PROGMEM="rr4k1/p1pq2pp/Q1n1pn2/2bpp3/4P3/2PP1NN1/PP3PPP/R1B1K2R b KQ - bm Nb4; id ""WAC.196""; d8+1"; 197const char wac197[] PROGMEM="7k/1p4p1/7p/3P1n2/4Q3/2P2P2/PP3qRP/7K b - - bm Qf1+; id ""WAC.197""; d5+m3"; 198const char wac198[] PROGMEM="2br2k1/ppp2p1p/4p1p1/4P2q/2P1Bn2/2Q5/PP3P1P/4R1RK b - - bm Rd3; id ""WAC.198""; d5+3.5"; 199const char wac199[] PROGMEM="r1br2k1/pp2nppp/2n5/1B1q4/Q7/4BN2/PP3PPP/2R2RK1 w - - bm Bxc6 Rcd1 Rfd1; id ""WAC.199""; Rfd1 d5+3"; 200const char wac200[] PROGMEM="2rqrn1k/pb4pp/1p2pp2/n2P4/2P3N1/P2B2Q1/1B3PPP/2R1R1K1 w - - bm Bxf6; id ""WAC.200""; d5+2.5"; 201const char wac201[] PROGMEM="2b2r1k/4q2p/3p2pQ/2pBp3/8/6P1/1PP2P1P/R5K1 w - - bm Ra7; id ""WAC.201""; d5+m6"; 202const char wac202[] PROGMEM="QR2rq1k/2p3p1/3p1pPp/8/4P3/8/P1r3PP/1R4K1 b - - bm Rxa2; id ""WAC.202""; d5+0.3"; 203const char wac203[] PROGMEM="r4rk1/5ppp/p3q1n1/2p2NQ1/4n3/P3P3/1B3PPP/1R3RK1 w - - bm Qh6; id ""WAC.203""; d5+m3"; 204const char wac204[] PROGMEM="r1b1qrk1/1p3ppp/p1p5/3Nb3/5N2/P7/1P4PQ/K1R1R3 w - - bm Rxe5; id ""WAC.204""; d5+0.4"; 205const char wac205[] PROGMEM="r3rnk1/1pq2bb1/p4p2/3p1Pp1/3B2P1/1NP4R/P1PQB3/2K4R w - - bm Qxg5; id ""WAC.205""; d6+3"; 206const char wac206[] PROGMEM="1Qq5/2P1p1kp/3r1pp1/8/8/7P/p4PP1/2R3K1 b - - bm Rc6; id ""WAC.206""; d5+1.5"; 207const char wac207[] PROGMEM="r1bq2kr/p1pp1ppp/1pn1p3/4P3/2Pb2Q1/BR6/P4PPP/3K1BNR w - - bm Qxg7+; id ""WAC.207""; d5+2"; 208const char wac208[] PROGMEM="3r1bk1/ppq3pp/2p5/2P2Q1B/8/1P4P1/P6P/5RK1 w - - bm Bf7+; id ""WAC.208""; d5+10"; 209const char wac209[] PROGMEM="4kb1r/2q2p2/r2p4/pppBn1B1/P6P/6Q1/1PP5/2KRR3 w k - bm Rxe5+; id ""WAC.209""; d6+8"; 210const char wac210[] PROGMEM="3r1rk1/pp1q1ppp/3pn3/2pN4/5PP1/P5PQ/1PP1B3/1K1R4 w - - bm Rh1; id ""WAC.210""; d7+3"; 211const char wac211[] PROGMEM="r1bqrk2/pp1n1n1p/3p1p2/P1pP1P1Q/2PpP1NP/6R1/2PB4/4RBK1 w - - bm Qxf7+; id ""WAC.211""; d5+m5"; 212const char wac212[] PROGMEM="rn1qr2Q/pbppk1p1/1p2pb2/4N3/3P4/2N5/PPP3PP/R4RK1 w - - bm Qxg7+; id ""WAC.212""; d5+m5"; 213const char wac213[] PROGMEM="3r1r1k/1b4pp/ppn1p3/4Pp1R/Pn5P/3P4/4QP2/1qB1NKR1 w - - bm Rxh7+ Rxg7+; id ""WAC.213""; d7+0"; 214const char wac214[] PROGMEM="r2r2k1/1p2qpp1/1np1p1p1/p3N3/2PPN3/bP5R/4QPPP/4R1K1 w - - bm Ng5; id ""WAC.214""; d5+3"; 215const char wac215[] PROGMEM="3r2k1/pb1q1pp1/1p2pb1p/8/3N4/P2QB3/1P3PPP/1Br1R1K1 w - - bm Qh7+; id ""WAC.215""; d5+m4"; 216const char wac216[] PROGMEM="r2qr1k1/1b1nbppp/p3pn2/1p1pN3/3P1B2/2PB1N2/PP2QPPP/R4RK1 w - - bm Nxf7 a4; id ""WAC.216""; d5+1.5"; 217const char wac217[] PROGMEM="r3kb1r/1pp3p1/p3bp1p/5q2/3QN3/1P6/PBP3P1/3RR1K1 w kq - bm Qd7+; id ""WAC.217""; d7+m5"; 218const char wac218[] PROGMEM="6k1/pp5p/2p3q1/6BP/2nPr1Q1/8/PP3R1K/8 w - - bm Bh6; id ""WAC.218""; d7+m6"; 219const char wac219[] PROGMEM="7k/p4q1p/1pb5/2p5/4B2Q/2P1B3/P6P/7K b - - bm Qf1+; id ""WAC.219""; d5+m3"; 220const char wac220[] PROGMEM="3rr1k1/ppp2ppp/8/5Q2/4n3/1B5R/PPP1qPP1/5RK1 b - - bm Qxf1+; id ""WAC.220""; d6+6"; 221const char wac221[] PROGMEM="r3k3/P5bp/2N1bp2/4p3/2p5/6NP/1PP2PP1/3R2K1 w q - bm Rd8+; id ""WAC.221""; d5+5"; 222const char wac222[] PROGMEM="2r1r2k/1q3ppp/p2Rp3/2p1P3/6QB/p3P3/bP3PPP/3R2K1 w - - bm Bf6; id ""WAC.222""; d9+m6"; 223const char wac223[] PROGMEM="r1bqk2r/pp3ppp/5n2/8/1b1npB2/2N5/PP1Q2PP/1K2RBNR w kq - bm Nxe4; id ""WAC.223""; d7+0.7"; 224const char wac224[] PROGMEM="5rk1/p1q3pp/1p1r4/2p1pp1Q/1PPn1P2/3B3P/P2R2P1/3R2K1 b - - bm Rh6 e4; id ""WAC.224""; Rh6 d6+3 e4 d9+4"; 225const char wac225[] PROGMEM="4R3/4q1kp/6p1/1Q3b2/1P1b1P2/6KP/8/8 b - - bm Qh4+; id ""WAC.225""; d5+m3"; 226const char wac226[] PROGMEM="2b2rk1/p1p4p/2p1p1p1/br2N1Q1/1p2q3/8/PB3PPP/3R1RK1 w - - bm Nf7; id ""WAC.226""; d7+3.5 "; 227const char wac227[] PROGMEM="2k1rb1r/ppp3pp/2np1q2/5b2/2B2P2/2P1BQ2/PP1N1P1P/2KR3R b - - bm d5; id ""WAC.227""; d5+2.5"; 228const char wac228[] PROGMEM="r4rk1/1bq1bp1p/4p1p1/p2p4/3BnP2/1N1B3R/PPP3PP/R2Q2K1 w - - bm Bxe4; id ""WAC.228""; d6+1.5"; 229const char wac229[] PROGMEM="8/8/8/1p5r/p1p1k1pN/P2pBpP1/1P1K1P2/8 b - - bm Rxh4 b4; id ""WAC.229""; b4 d14+4.5"; 230const char wac230[] PROGMEM="2b5/1r6/2kBp1p1/p2pP1P1/2pP4/1pP3K1/1R3P2/8 b - - bm Rb4; id ""WAC.230""; ??? Rh7d5+2.5"; 231const char wac231[] PROGMEM="r4rk1/1b1nqp1p/p5p1/1p2PQ2/2p5/5N2/PP3PPP/R1BR2K1 w - - bm Bg5; id ""WAC.231""; d5+0.5"; 232const char wac232[] PROGMEM="1R2rq1k/2p3p1/Q2p1pPp/8/4P3/8/P1r3PP/1R4K1 w - - bm Qb5 Rxe8; id ""WAC.232""; Rxe8 d8+3 Qb5 d14+7"; 233const char wac233[] PROGMEM="5rk1/p1p2r1p/2pp2p1/4p3/PPPnP3/3Pq1P1/1Q1R1R1P/4NK2 b - - bm Nb3; id ""WAC.233""; d7+6"; 234const char wac234[] PROGMEM="2kr1r2/p6p/5Pp1/2p5/1qp2Q1P/7R/PP6/1KR5 w - - bm Rb3; id ""WAC.234""; d5+5"; 235const char wac235[] PROGMEM="5r2/1p1RRrk1/4Qq1p/1PP3p1/8/4B3/1b3P1P/6K1 w - - bm Qe4 Qxf7+ Rxf7+; id ""WAC.235""; Qe4 d5+3 Rxf7 13+5"; 236const char wac236[] PROGMEM="1R6/p5pk/4p2p/4P3/8/2r3qP/P3R1b1/4Q1K1 b - - bm Rc1; id ""WAC.236""; d5+0.8"; 237const char wac237[] PROGMEM="r5k1/pQp2qpp/8/4pbN1/3P4/6P1/PPr4P/1K1R3R b - - bm Rc1+; id ""WAC.237""; d12+15"; 238const char wac238[] PROGMEM="1k1r4/pp1r1pp1/4n1p1/2R5/2Pp1qP1/3P2QP/P4PB1/1R4K1 w - - bm Bxb7; id ""WAC.238""; d5+4"; 239const char wac239[] PROGMEM="8/6k1/5pp1/Q6p/5P2/6PK/P4q1P/8 b - - bm Qf1+; id ""WAC.239""; d10+13"; 240const char wac240[] PROGMEM="2b4k/p1b2p2/2p2q2/3p1PNp/3P2R1/3B4/P1Q2PKP/4r3 w - - bm Qxc6; id ""WAC.240""; d6+5"; 241const char wac241[] PROGMEM="2rq1rk1/pp3ppp/2n2b2/4NR2/3P4/PB5Q/1P4PP/3R2K1 w - - bm Qxh7+; id ""WAC.241""; d11+m6"; 242const char wac242[] PROGMEM="r1b1r1k1/pp1nqp2/2p1p1pp/8/4N3/P1Q1P3/1P3PPP/1BRR2K1 w - - bm Rxd7; id ""WAC.242""; d5+3.5"; 243const char wac243[] PROGMEM="1r3r1k/3p4/1p1Nn1R1/4Pp1q/pP3P1p/P7/5Q1P/6RK w - - bm Qe2; id ""WAC.243""; d7+1.5"; 244const char wac244[] PROGMEM="r6r/pp3ppp/3k1b2/2pb4/B4Pq1/2P1Q3/P5PP/1RBR2K1 w - - bm Qxc5+; id ""WAC.244""; d5+m4"; 245const char wac245[] PROGMEM="4rrn1/ppq3bk/3pPnpp/2p5/2PB4/2NQ1RPB/PP5P/5R1K w - - bm Qxg6+; id ""WAC.245""; d7+4"; 246const char wac246[] PROGMEM="6R1/4qp1p/ppr1n1pk/8/1P2P1QP/6N1/P4PP1/6K1 w - - bm Qh5+; id ""WAC.246""; d5+m2"; 247const char wac247[] PROGMEM="2k1r3/1p2Bq2/p2Qp3/Pb1p1p1P/2pP1P2/2P5/2P2KP1/1R6 w - - bm Rxb5; id ""WAC.247""; d8+7"; 248const char wac248[] PROGMEM="5r1k/1p4pp/3q4/3Pp1R1/8/8/PP4PP/4Q1K1 b - - bm Qc5+; id ""WAC.248""; d6+0.5"; 249const char wac249[] PROGMEM="r4rk1/pbq2pp1/1ppbpn1p/8/2PP4/1P1Q1N2/PBB2PPP/R3R1K1 w - - bm c5 d5; id ""WAC.249""; d5 d5+9 c5 d10+1.7"; 250const char wac250[] PROGMEM="1b5k/7P/p1p2np1/2P2p2/PP3P2/4RQ1R/q2r3P/6K1 w - - bm Re8+; id ""WAC.250""; d5+m8"; 251const char wac251[] PROGMEM="k7/p4p2/P1q1b1p1/3p3p/3Q4/7P/5PP1/1R4K1 w - - bm Qe5 Qf4; id ""WAC.251""; d8+m6"; 252const char wac252[] PROGMEM="1rb1r1k1/p1p2ppp/5n2/2pP4/5P2/2QB4/qNP3PP/2KRB2R b - - bm Bg4 Re2; c0 ""Bg4 wins, but Re2 is far better.""; id ""WAC.252""; Bg4 +3 Re2 d7+m7 d8+m5"; 253const char wac253[] PROGMEM="k5r1/p4b2/2P5/5p2/3P1P2/4QBrq/P5P1/4R1K1 w - - bm Qe8+; id ""WAC.253""; d5+m4"; 254const char wac254[] PROGMEM="r6k/pp3p1p/2p1bp1q/b3p3/4Pnr1/2PP2NP/PP1Q1PPN/R2B2RK b - - bm Nxh3; id ""WAC.254""; d5+2.5"; 255const char wac255[] PROGMEM="3r3r/p4pk1/5Rp1/3q4/1p1P2RQ/5N2/P1P4P/2b4K w - - bm Rfxg6+; id ""WAC.255""; d5+4"; 256const char wac256[] PROGMEM="3r1rk1/1pb1qp1p/2p3p1/p7/P2Np2R/1P5P/1BP2PP1/3Q1BK1 w - - bm Nf5; id ""WAC.256""; d9+3"; 257const char wac257[] PROGMEM="4r1k1/pq3p1p/2p1r1p1/2Q1p3/3nN1P1/1P6/P1P2P1P/3RR1K1 w - - bm Rxd4; id ""WAC.257""; d5+3"; 258const char wac258[] PROGMEM="r3brkn/1p5p/2p2Ppq/2Pp3B/3Pp2Q/4P1R1/6PP/5R1K w - - bm Bxg6; id ""WAC.258""; d5+0.2"; 259const char wac259[] PROGMEM="r1bq1rk1/ppp2ppp/2np4/2bN1PN1/2B1P3/3p4/PPP2nPP/R1BQ1K1R w - - bm Qh5; id ""WAC.259""; d5-1.5"; 260const char wac260[] PROGMEM="2r2b1r/p1Nk2pp/3p1p2/N2Qn3/4P3/q6P/P4PP1/1R3K1R w - - bm Qe6+; id ""WAC.260""; d5+m5"; 261const char wac261[] PROGMEM="r5k1/1bp3pp/p2p4/1p6/5p2/1PBP1nqP/1PP3Q1/R4R1K b - - bm Nd4; id ""WAC.261""; d6+9"; 262const char wac262[] PROGMEM="6k1/p1B1b2p/2b3r1/2p5/4p3/1PP1N1Pq/P2R1P2/3Q2K1 b - - bm Rh6; id ""WAC.262""; d5+1.2"; 263const char wac263[] PROGMEM="rnbqr2k/pppp1Qpp/8/b2NN3/2B1n3/8/PPPP1PPP/R1B1K2R w KQ - bm Qg8+; id ""WAC.263""; d6+m4"; 264const char wac264[] PROGMEM="r2r2k1/1R2qp2/p5pp/2P5/b1PN1b2/P7/1Q3PPP/1B1R2K1 b - - bm Qe5 Rab8; id ""WAC.264""; Rab8 d5+2"; 265const char wac265[] PROGMEM="2r1k2r/2pn1pp1/1p3n1p/p3PP2/4q2B/P1P5/2Q1N1PP/R4RK1 w k - bm exf6; id ""WAC.265""; d10+2"; 266const char wac266[] PROGMEM="r3q2r/2p1k1p1/p5p1/1p2Nb2/1P2nB2/P7/2PNQbPP/R2R3K b - - bm Rxh2+; id ""WAC.266""; d5+m6"; 267const char wac267[] PROGMEM="2r1kb1r/pp3ppp/2n1b3/1q1N2B1/1P2Q3/8/P4PPP/3RK1NR w Kk - bm Nc7+; id ""WAC.267""; d5+m5"; 268const char wac268[] PROGMEM="2r3kr/ppp2n1p/7B/5q1N/1bp5/2Pp4/PP2RPPP/R2Q2K1 w - - bm Re8+; id ""WAC.268""; d5+11"; 269const char wac269[] PROGMEM="2kr2nr/pp1n1ppp/2p1p3/q7/1b1P1B2/P1N2Q1P/1PP1BPP1/R3K2R w KQ - bm axb4; id ""WAC.269""; d8+3"; 270const char wac270[] PROGMEM="2r1r1k1/pp1q1ppp/3p1b2/3P4/3Q4/5N2/PP2RPPP/4R1K1 w - - bm Qg4; id ""WAC.270""; d8+0.7"; 271const char wac271[] PROGMEM="2kr4/ppp3Pp/4RP1B/2r5/5P2/1P6/P2p4/3K4 w - - bm Rd6; id ""WAC.271""; d6+0"; 272const char wac272[] PROGMEM="nrq4r/2k1p3/1p1pPnp1/pRpP1p2/P1P2P2/2P1BB2/1R2Q1P1/6K1 w - - bm Bxc5; id ""WAC.272""; d5+2"; 273const char wac273[] PROGMEM="2k4B/bpp1qp2/p1b5/7p/1PN1n1p1/2Pr4/P5PP/R3QR1K b - - bm Ng3+ g3; id ""WAC.273""; Ng3+ d6+6"; 274const char wac274[] PROGMEM="8/1p6/p5R1/k7/Prpp4/K7/1NP5/8 w - - am Rd6; bm Rb6 Rg5+; id ""WAC.274""; Rb6 d6+2.5"; 275const char wac275[] PROGMEM="r1b2rk1/1p1n1ppp/p1p2q2/4p3/P1B1Pn2/1QN2N2/1P3PPP/3R1RK1 b - - bm Nc5 Nxg2 b5; id ""WAC.275""; b5 d5+1.3"; 276const char wac276[] PROGMEM="r5k1/pp1RR1pp/1b6/6r1/2p5/B6P/P4qPK/3Q4 w - - bm Qd5+; id ""WAC.276""; d5+9"; 277const char wac277[] PROGMEM="1r4r1/p2kb2p/bq2p3/3p1p2/5P2/2BB3Q/PP4PP/3RKR2 b - - bm Rg3 Rxg2; id ""WAC.277""; Rg3 d5+1.3"; 278const char wac278[] PROGMEM="r2qkb1r/pppb2pp/2np1n2/5pN1/2BQP3/2N5/PPP2PPP/R1B1K2R w KQkq - bm Bf7+; id ""WAC.278""; d5+m5"; 279const char wac279[] PROGMEM="r7/4b3/2p1r1k1/1p1pPp1q/1P1P1P1p/PR2NRpP/2Q3K1/8 w - - bm Nxf5 Rc3; id ""WAC.279""; d5+1.6"; 280const char wac280[] PROGMEM="r1r2bk1/5p1p/pn4p1/N2b4/3Pp3/B3P3/2q1BPPP/RQ3RK1 b - - bm Bxa3; id ""WAC.280""; d6+2"; 281const char wac281[] PROGMEM="2R5/2R4p/5p1k/6n1/8/1P2QPPq/r7/6K1 w - - bm Rxh7+; id ""WAC.281""; d5+6"; 282const char wac282[] PROGMEM="6k1/2p3p1/1p1p1nN1/1B1P4/4PK2/8/2r3b1/7R w - - bm Rh8+; id ""WAC.282""; d5+m4"; 283const char wac283[] PROGMEM="3q1rk1/4bp1p/1n2P2Q/3p1p2/6r1/Pp2R2N/1B4PP/7K w - - bm Ng5; id ""WAC.283""; d5+m4"; 284const char wac284[] PROGMEM="3r3k/pp4pp/8/1P6/3N4/Pn2P1qb/1B1Q2B1/2R3K1 w - - bm Nf5; id ""WAC.284""; d6+3.5"; 285const char wac285[] PROGMEM="2rr3k/1b2bppP/p2p1n2/R7/3P4/1qB2P2/1P4Q1/1K5R w - - bm Qxg7+; id ""WAC.285""; d5+m5"; 286const char wac286[] PROGMEM="3r1k2/1p6/p4P2/2pP2Qb/8/1P1KB3/P6r/8 b - - bm Rxd5+; id ""WAC.286""; d5+3"; 287const char wac287[] PROGMEM="rn3k1r/pp2bBpp/2p2n2/q5N1/3P4/1P6/P1P3PP/R1BQ1RK1 w - - bm Qg4 Qh5; id ""WAC.287""; Qh5 d5+4"; 288const char wac288[] PROGMEM="r1b2rk1/p4ppp/1p1Qp3/4P2N/1P6/8/P3qPPP/3R1RK1 w - - bm Nf6+; id ""WAC.288""; d5+3.5"; 289const char wac289[] PROGMEM="2r3k1/5p1p/p3q1p1/2n3P1/1p1QP2P/1P4N1/PK6/2R5 b - - bm Qe5; id ""WAC.289""; d5+3.5"; 290const char wac290[] PROGMEM="2k2r2/2p5/1pq5/p1p1n3/P1P2n1B/1R4Pp/2QR4/6K1 b - - bm Ne2+; id ""WAC.290""; d5+m4"; 291const char wac291[] PROGMEM="5r1k/3b2p1/p6p/1pRpR3/1P1P2q1/P4pP1/5QnP/1B4K1 w - - bm h3; id ""WAC.291""; d7+3"; 292const char wac292[] PROGMEM="4r3/1Q1qk2p/p4pp1/3Pb3/P7/6PP/5P2/4R1K1 w - - bm d6+; id ""WAC.292""; d5+2.5"; 293const char wac293[] PROGMEM="1nbq1r1k/3rbp1p/p1p1pp1Q/1p6/P1pPN3/5NP1/1P2PPBP/R4RK1 w - - bm Nfg5; id ""WAC.293""; d9+m4"; 294const char wac294[] PROGMEM="3r3k/1r3p1p/p1pB1p2/8/p1qNP1Q1/P6P/1P4P1/3R3K w - - bm Bf8 Nf5 Qf4; id ""WAC.294""; Qf4 d5+4 Bf8 d6+7"; 295const char wac295[] PROGMEM="4r3/p4r1p/R1p2pp1/1p1bk3/4pNPP/2P1K3/2P2P2/3R4 w - - bm Rxd5+; id ""WAC.295""; d5+m3"; 296const char wac296[] PROGMEM="3r4/1p2k2p/p1b1p1p1/4Q1Pn/2B3KP/4pP2/PP2R1N1/6q1 b - - bm Rd4+ Rf8; id ""WAC.296""; Rf8 d5+5 Rd4+ d9+9"; 297const char wac297[] PROGMEM="3r1rk1/p3qp1p/2bb2p1/2p5/3P4/1P6/PBQN1PPP/2R2RK1 b - - bm Bxg2 Bxh2+; id ""WAC.297""; Bxg2 d8+1.6"; 298const char wac298[] PROGMEM="3Q4/p3b1k1/2p2rPp/2q5/4B3/P2P4/7P/6RK w - - bm Qh8+; id ""WAC.298""; d6+m4"; 299const char wac299[] PROGMEM="1n2rr2/1pk3pp/pNn2p2/2N1p3/8/6P1/PP2PPKP/2RR4 w - - bm Nca4; id ""WAC.299""; d5+5"; 300const char wac300[] PROGMEM="b2b1r1k/3R1ppp/4qP2/4p1PQ/4P3/5B2/4N1K1/8 w - - bm g6; id ""WAC.300""; d5+2"; 301 302const char * const wacs[] PROGMEM = { 303 wac1,wac2,wac3,wac4,wac5,wac6,wac7,wac8,wac9,wac10, 304 wac11,wac12,wac13,wac14,wac15,wac16,wac17,wac18,wac19,wac20, 305 wac21,wac22,wac23,wac24,wac25,wac26,wac27,wac28,wac29,wac30, 306 wac31,wac32,wac33,wac34,wac35,wac36,wac37,wac38,wac39,wac40, 307 wac41,wac42,wac43,wac44,wac45,wac46,wac47,wac48,wac49,wac50, 308 wac51,wac52,wac53,wac54,wac55,wac56,wac57,wac58,wac59,wac60, 309 wac61,wac62,wac63,wac64,wac65,wac66,wac67,wac68,wac69,wac70, 310 wac71,wac72,wac73,wac74,wac75,wac76,wac77,wac78,wac79,wac80, 311 wac81,wac82,wac83,wac84,wac85,wac86,wac87,wac88,wac89,wac90, 312 wac91,wac92,wac93,wac94,wac95,wac96,wac97,wac98,wac99,wac100, 313 wac101,wac102,wac103,wac104,wac105,wac106,wac107,wac108,wac109,wac110, 314 wac111,wac112,wac113,wac114,wac115,wac116,wac117,wac118,wac119,wac120, 315 wac121,wac122,wac123,wac124,wac125,wac126,wac127,wac128,wac129,wac130, 316 wac131,wac132,wac133,wac134,wac135,wac136,wac137,wac138,wac139,wac140, 317 wac141,wac142,wac143,wac144,wac145,wac146,wac147,wac148,wac149,wac150, 318 wac151,wac152,wac153,wac154,wac155,wac156,wac157,wac158,wac159,wac160, 319 wac161,wac162,wac163,wac164,wac165,wac166,wac167,wac168,wac169,wac170, 320 wac171,wac172,wac173,wac174,wac175,wac176,wac177,wac178,wac179,wac180, 321 wac181,wac182,wac183,wac184,wac185,wac186,wac187,wac188,wac189,wac190, 322 wac191,wac192,wac193,wac194,wac195,wac196,wac197,wac198,wac199,wac200, 323 wac201,wac202,wac203,wac204,wac205,wac206,wac207,wac208,wac209,wac210, 324 wac211,wac212,wac213,wac214,wac215,wac216,wac217,wac218,wac219,wac220, 325 wac221,wac222,wac223,wac224,wac225,wac226,wac227,wac228,wac229,wac230, 326 wac231,wac232,wac233,wac234,wac235,wac236,wac237,wac238,wac239,wac240, 327 wac241,wac242,wac243,wac244,wac245,wac246,wac247,wac248,wac249,wac250, 328 wac251,wac252,wac253,wac254,wac255,wac256,wac257,wac258,wac259,wac260, 329 wac261,wac262,wac263,wac264,wac265,wac266,wac267,wac268,wac269,wac270, 330 wac271,wac272,wac273,wac274,wac275,wac276,wac277,wac278,wac279,wac280, 331 wac281,wac282,wac283,wac284,wac285,wac286,wac287,wac288,wac289,wac290, 332 wac291,wac292,wac293,wac294,wac295,wac296,wac297,wac298,wac299,wac300 333 }; 334 335 336
ArduinoMegaChess2.ino
arduino
1//ArduinoMega Chess 2.0 2//Sergey Urusov, ususovsv@gmail.com 3#include "wac.h" 4#include "logic.h" 5#include <stdint.h> 6#include <avr/pgmspace.h> 7#include <EEPROM.h> 8 9#define MAXSTEPS 600 //600*7=4200 bytes, 700 - works too 10#define MAXDEPTH 20 //28*20=560 bytes 11 12typedef struct { 13 signed char f1,f2; //figure moved and taken 14 signed char c1,c2; //from and to coordinates 15 signed char typecheck; //check after move &B1000, move type &B111 1-En Passant,2-king castle,3-quween castle,4-5-6-7-promotion to khight,bishop,rook,queen 16 short weight; //position weight 17} step_t; 18 19step_t steps[MAXSTEPS]; //moves massive include solving tree 20short ply; //number of halfstep in match, started with 0 21 22struct position_t { 23 byte w; //white to move 1, black - 0 24 byte wrk, wrq, brk, brq; //castle ability 25 byte pp; //number of field 1..63 of last two squares pawn move 26 short b_step; //number of levels first move 27 short l_step; //quantity of moves on level 28 short cur_step; //current move on level 29 short best_step; //best move on level 30 step_t cut; //move for sorting (cut alpha-beta) 31 byte check_on_table; //moving side under check 32 short weight_w; //weight of white figures 33 short weight_b; //weight of black figures 34 short weight_s; //statistic estimation of position, in favor of whites + 35} pos[MAXDEPTH]; 36 37 38struct startpos_t { 39 byte w; 40 byte wrk, wrq, brk, brq; 41 byte pp; 42 char pole[64]; 43 int ply; 44} startpos; 45 46byte poswk=0; //white king field 47byte posbk=0; //black king field 48 49int level; //number of current level of solving tree 50unsigned long timelimith=5000; //limith of thinking time in ms 51const int limits[10]={5,10,30,60,120,180,300,600,1800,3600}; 52const char* limitstrings[10]={"5 sec","10 sec","30 sec","1 min","2 min","3 min","5 min","10 min","30 min","1 hr"}; 53byte limit=0; 54unsigned long starttime; 55boolean endspiel=0; 56boolean halt=0; 57unsigned long count=0; 58int depth; 59boolean TRACE=0; 60int maxstep; 61boolean solving=0; 62boolean gameover=0; 63boolean autow=0; 64boolean autob=1; 65boolean debute; 66 67String str_step(step_t); 68#include "gui.h" 69 70//**************************** 71void new_game(String fen="") { 72 if (fen=="") fen=F("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -"); // 73 fenload(fen); 74 for (int i=0;i<64;i++) startpos.pole[i]=pole[i]; 75 startpos.w=pos[0].w; 76 startpos.wrk=pos[0].wrk; 77 startpos.wrq=pos[0].wrq; 78 startpos.brk=pos[0].brk; 79 startpos.brq=pos[0].brq; 80 startpos.w=pos[0].w; 81 startpos.pp=pos[0].pp; 82 startpos.ply=ply; 83 kingpositions(); 84} 85//**************************** 86void setup() { 87 Serial.begin(115200); 88 while (!Serial) ; 89 Serial.println(F("Start")); 90 new_game(); 91 cleardisplayboard(); 92 if (!rotate) { autow=0; autob=1; } else { autow=1; autob=0; } 93 guistart(); 94 clearstatus(); 95 //wactest(); 96 Serial.println(F("Command:")); 97} 98//**************************** 99void start_game() { 100 for (int i=0;i<64;i++) pole[i]=startpos.pole[i]; 101 pos[0].w=startpos.w; 102 pos[0].wrk=startpos.wrk; 103 pos[0].wrq=startpos.wrq; 104 pos[0].brk=startpos.brk; 105 pos[0].brq=startpos.brq; 106 pos[0].w=startpos.w; 107 pos[0].pp=startpos.pp; 108 ply=startpos.ply; 109 kingpositions(); 110} 111//********************************** 112boolean fenload(String ss) { 113 char s='x',i=0,j=0; boolean load=false; 114 for (int i=0;i<64;i++) pole[i]=0; 115 pos[0].w=1; 116 pos[0].wrk=0; pos[0].wrq=0; pos[0].brk=0; pos[0].brq=0; 117 pos[0].pp=0; 118 pos[0].cur_step=0; pos[0].b_step=MAXDEPTH; pos[0].l_step=0; 119 int spaces=0; 120 for (int c=0; c<ss.length(); c++) { 121 s=ss[c]; 122 if (i>7) { i=0; j++; } 123 if (spaces==3&&int(s)>='a'&&int(s)<='h') { 124 c++; 125 char s1=ss[c]; 126 if (int(s1)>='1'&&int(s1)<='8') { 127 pos[0].pp=8*(7-(int(s1)-int('1')))+int(s)-int('a'); 128 } 129 } else { 130 int l=j*8+i; 131 switch (s) { 132 case '/': i=0; break; 133 case 'p': pole[l]=-fp; i++; break; 134 case 'P': pole[l]=fp; i++; break; 135 case 'n': pole[l]=-fn; i++; break; 136 case 'N': pole[l]=fn; i++; break; 137 case 'b': if (spaces==0) { pole[l]=-fb; i++; } else 138 if (spaces==1) { pos[0].w=0; load=true; } 139 break; 140 case 'B': pole[l]=fb; i++; break; 141 case 'r': pole[l]=-fr; i++; break; 142 case 'R': pole[l]=fr; i++; break; 143 case 'q': if (spaces==0) { pole[l]=-fq; i++; } else pos[0].brq=1; 144 break; 145 case 'Q': if (spaces==0) { pole[l]=fq; i++; } else pos[0].wrq=1; 146 break; 147 case 'k': if (spaces==0) { pole[l]=-fk; i++; } else pos[0].brk=1; 148 break; 149 case 'K': if (spaces==0) { pole[l]=fk; i++; } else pos[0].wrk=1; 150 break; 151 case '1': i++; break; 152 case '2': i+=2; break; 153 case '3': i+=3; break; 154 case '4': i+=4; break; 155 case '5': i+=5; break; 156 case '6': i+=6; break; 157 case '7': i+=7; break; 158 case '8': i=0; j++; break; 159 case ' ': spaces++; break; 160 case 'w': if (spaces==1) { pos[0].w=1; load=true; } break; 161 } 162 } 163 if (spaces==4) break; 164 } 165 if (!load) Serial.println(F("Error")); 166 if (pos[0].w) ply=0; else ply=1; 167 steps[0].f1=0; steps[1].f1=0; 168 return load; 169} 170//**************************** 171void show_position() { 172 for (int i=0;i<8;i++) { 173 Serial.println(F("-----------------------------------------")); 174 Serial.print("|"); 175 for (int j=0;j<8;j++) { 176 signed char f=pole[i*8+j]; 177 if (f>=0) { Serial.print(" "); Serial.print(fig_symb1[f]); Serial.print(" |"); } 178 else { Serial.print(" -"); Serial.print(fig_symb1[-f]); Serial.print(" |"); } 179 } 180 Serial.print(" "); 181 Serial.println(8-i); 182 } 183 Serial.println(F("-----------------------------------------")); 184 Serial.print(F(" a b c d e f g h ")); 185 if (pos[0].w==0) Serial.print(F("Black")); else Serial.print(F("White")); 186 Serial.println(); 187} 188//**************************** 189String str_pole(int i) { 190 return String(char('a'+i%8)+String(8-i/8)); 191} 192//**************************** 193String str_step(step_t st) { 194 String s=""; 195 if (st.f1==0) return s; 196 if ((st.typecheck&B111)==2) s="0-0"; 197 else if ((st.typecheck&B111)==3) s="0-0-0"; 198 else { 199 if (abs(st.f1)>1) s=s+fig_symb[abs(st.f1)]; 200 s=s+str_pole(st.c1); 201 if (st.f2==0) s=s+"-"; 202 if (st.f2!=0) s=s+"x"; 203 s=s+str_pole(st.c2); 204 } 205 if ((st.typecheck&B111)>3) s=s+"="+fig_symb[(st.typecheck&B111)-2]; 206 if (st.typecheck&B1000) s=s+"+"; 207 return s; 208} 209//**************************** 210void show_steps(int l) { 211 Serial.print(F("Steps=")); Serial.println(String(pos[l].l_step-pos[l].b_step)); 212 for (int i=pos[l].b_step;i<pos[l].l_step;i++) { 213 Serial.print(str_step(steps[i])); Serial.print(" "); Serial.print(steps[i].weight); Serial.print(F(" ")); 214 if ((i+1)%3==0) Serial.println(); 215 } 216 Serial.println(); 217} 218//**************************** 219//**************************** 220//**************************** 221//**************************** 222//**************************** 223//**************************** 224//**************************** 225void movestep(int l, step_t &s) { 226 pole[s.c1]=0; 227 pole[s.c2]=s.f1; 228 if (pos[l].w) { //white to move 229 if (s.f1==fk) poswk=s.c2; 230 switch (s.typecheck&B111) { 231 case 0: 232 return; 233 case 1: //En Passant 234 pole[s.c2+8]=0; 235 break; 236 case 2: //short castle 237 pole[60]=0; 238 pole[61]=fr; 239 pole[62]=fk; 240 pole[63]=0; 241 poswk=62; 242 break; 243 case 3: //long castle 244 pole[60]=0; 245 pole[59]=fr; 246 pole[58]=fk; 247 pole[57]=0; 248 pole[56]=0; 249 poswk=58; 250 break; 251 default: 252 pole[s.c2]=(s.typecheck&B111)-2; 253 } 254 } else { //black to move 255 if (s.f1==-fk) posbk=s.c2; 256 switch ((s.typecheck&B111)) { 257 case 0: 258 return; 259 case 1: //En Passant 260 pole[s.c2-8]=0; 261 break; 262 case 2: //short castle 263 pole[4]=0; 264 pole[5]=-fr; 265 pole[6]=-fk; 266 pole[7]=0; 267 posbk=6; 268 break; 269 case 3: //long castle 270 pole[4]=0; 271 pole[3]=-fr; 272 pole[2]=-fk; 273 pole[1]=0; 274 pole[0]=0; 275 posbk=2; 276 break; 277 default: 278 pole[s.c2]=2-(s.typecheck&B111); 279 } 280 } 281} 282//**************************** 283void backstep(int l, step_t &s) { 284 pole[s.c1]=s.f1; 285 pole[s.c2]=s.f2; 286 if (pos[l].w) { //white to move 287 if (s.f1==fk) poswk=s.c1; 288 switch (s.typecheck&B111) { 289 case 0: return; 290 case 1: //En Passant 291 pole[s.c2]=0; 292 pole[s.c2+8]=-fp; 293 break; 294 case 2: //short castle 295 pole[60]=fk; 296 pole[61]=0; 297 pole[62]=0; 298 pole[63]=fr; 299 poswk=60; 300 break; 301 case 3: //long castle 302 pole[60]=fk; 303 pole[59]=0; 304 pole[58]=0; 305 pole[57]=0; 306 pole[56]=fr; 307 poswk=60; 308 break; 309 } 310 } else { //black to move 311 if (s.f1==-fk) posbk=s.c1; 312 switch (s.typecheck&B111) { 313 case 0: return; 314 case 1: //En Passant 315 pole[s.c2]=0; 316 pole[s.c2-8]=fp; 317 break; 318 case 2: //short castle 319 pole[4]=-fk; 320 pole[5]=0; 321 pole[6]=0; 322 pole[7]=-fr; 323 posbk=4; 324 break; 325 case 3: //long castle 326 pole[4]=-fk; 327 pole[3]=0; 328 pole[2]=0; 329 pole[1]=0; 330 pole[0]=-fr; 331 posbk=4; 332 break; 333 } 334 } 335} 336//**************************** 337void movepos(int l, step_t &s) { 338 pos[l+1].wrk=pos[l].wrk; pos[l+1].wrq=pos[l].wrq; 339 pos[l+1].brk=pos[l].brk; pos[l+1].brq=pos[l].brq; 340 pos[l+1].pp=0; 341 if (pos[l].w) { // 342 if (pos[l].wrk||pos[l].wrq) { 343 if (s.c1==60) { 344 pos[l+1].wrk=0; pos[l+1].wrq=0; 345 } else if (s.c1==63) pos[l+1].wrk=0; 346 else if (s.c1==56) pos[l+1].wrq=0; 347 } 348 if ((s.typecheck&B111)==0&&s.f1==fp&&s.c2==s.c1-16) 349 if (column[s.c2]>1&&pole[s.c2-1]==-fp||column[s.c2]<8&&pole[s.c2+1]==-fp) pos[l+1].pp=s.c1-8; 350 pos[l+1].weight_w=pos[l].weight_w; pos[l+1].weight_b=pos[l].weight_b; 351 if (s.f2!=0) pos[l+1].weight_b-=fig_weight[-s.f2]; 352 if ((s.typecheck&B111)>3) pos[l+1].weight_w+=fig_weight[(s.typecheck&B111)-2]-100; 353 if (s.f1==fk&&endspiel) 354 pos[l+1].weight_s=pos[l].weight_s+(int)pgm_read_word(&stat_weightw[6][s.c2])-(int)pgm_read_word(&stat_weightw[6][s.c1]); 355 else 356 pos[l+1].weight_s=pos[l].weight_s+(int)pgm_read_word(&stat_weightw[s.f1-1][s.c2])-(int)pgm_read_word(&stat_weightw[s.f1-1][s.c1]); 357 if (s.f2!=0) pos[l+1].weight_s+=(int)pgm_read_word(&stat_weightb[-s.f2-1][s.c2]); 358 } else { // 359 if (pos[l].brk||pos[l].brq) { 360 if (s.c1==4) { 361 pos[l+1].brk=0; pos[l+1].brq=0; 362 } else if (s.c1==7) pos[l+1].brk=0; 363 else if (s.c1==0) pos[l+1].brq=0; 364 } 365 if ((s.typecheck&B111)==0&&s.f1==-fp&&s.c2==s.c1+16) 366 if (column[s.c2]>1&&pole[s.c2-1]==fp||column[s.c2]<8&&pole[s.c2+1]==fp) pos[l+1].pp=s.c1+8; 367 pos[l+1].weight_w=pos[l].weight_w; pos[l+1].weight_b=pos[l].weight_b; 368 if (s.f2!=0) pos[l+1].weight_w-=fig_weight[s.f2]; 369 if ((s.typecheck&&B111)>3) pos[l+1].weight_b+=fig_weight[(s.typecheck&B111)-2]-100; 370 if (s.f1==-fk&&endspiel) 371 pos[l+1].weight_s=pos[l].weight_s-(int)pgm_read_word(&stat_weightb[6][s.c2])+(int)pgm_read_word(&stat_weightb[6][s.c1]); 372 else 373 pos[l+1].weight_s=pos[l].weight_s-(int)pgm_read_word(&stat_weightb[-s.f1-1][s.c2])+(int)pgm_read_word(&stat_weightb[-s.f1-1][s.c1]); 374 if (s.f2!=0) pos[l+1].weight_s-=(int)pgm_read_word(&stat_weightw[s.f2-1][s.c2]); 375 } 376 count++; //estimated positions count 377} 378//**************************** 379boolean check_w() { 380 signed char f2=0; 381 int j=0; 382 if (pole[poswk]!=fk) { 383 for (int i=0;i<64;i++) if (pole[i]==fk) { poswk=i; break; } 384 } 385 while (pgm_read_byte(&diag_step[poswk][j])!=99) { 386 if (pgm_read_byte(&diag_step[poswk][j])==88) f2=0; 387 else if (f2==0) { 388 f2=pole[pgm_read_byte(&diag_step[poswk][j])]; 389 if (f2==-fb||f2==-fq) return(true); 390 } 391 j++; 392 } 393 f2=0; j=0; 394 while (pgm_read_byte(&stra_step[poswk][j])!=99) { 395 if (pgm_read_byte(&stra_step[poswk][j])==88) f2=0; 396 else if (f2==0) { 397 f2=pole[pgm_read_byte(&stra_step[poswk][j])]; 398 if (f2==-fr||f2==-fq) return(true); 399 if (j==0||pgm_read_byte(&stra_step[poswk][j])==88) 400 if (f2==-fk) return(true); 401 } 402 j++; 403 } 404 j=0; 405 while (pgm_read_byte(&knight_step[poswk][j])!=99) { 406 if (pole[pgm_read_byte(&knight_step[poswk][j])]==-fn) return(true); 407 j++; 408 } 409 if (row[poswk]<7) { 410 if (column[poswk]>1&&pole[poswk-9]==-fp) return(true); 411 if (column[poswk]<8&&pole[poswk-7]==-fp) return(true); 412 } 413 j=0; 414 while (pgm_read_byte(&king_step[poswk][j])!=99) { 415 if (pole[pgm_read_byte(&king_step[poswk][j])]==-fk) return(true); 416 j++; 417 } 418 return(false); 419} 420//**************************** 421boolean check_b() { 422 signed char f2=0; 423 int j=0; 424 if (pole[posbk]!=-fk) { 425 for (int i=0;i<64;i++) if (pole[i]==-fk) { posbk=i; break; } 426 } 427 while (pgm_read_byte(&diag_step[posbk][j])!=99) { 428 if (pgm_read_byte(&diag_step[posbk][j])==88) f2=0; 429 else if (f2==0) { 430 f2=pole[pgm_read_byte(&diag_step[posbk][j])]; 431 if (f2==fb||f2==fq) return(true); 432 } 433 j++; 434 } 435 f2=0; j=0; 436 while (pgm_read_byte(&stra_step[posbk][j])!=99) { 437 if (pgm_read_byte(&stra_step[posbk][j])==88) f2=0; 438 else if (f2==0) { 439 f2=pole[pgm_read_byte(&stra_step[posbk][j])]; 440 if (f2==fr||f2==fq) return(true); 441 if (j==0||pgm_read_byte(&stra_step[posbk][j])==88) 442 if (f2==fk) return(true); 443 } 444 j++; 445 } 446 j=0; 447 while (pgm_read_byte(&knight_step[posbk][j])!=99) { 448 if (pole[pgm_read_byte(&knight_step[posbk][j])]==fn) return(true); 449 j++; 450 } 451 if (row[posbk]>2) { 452 if (column[posbk]>1&&pole[posbk+7]==fp) return(true); 453 if (column[posbk]<8&&pole[posbk+9]==fp) return(true); 454 } 455 j=0; 456 while (pgm_read_byte(&king_step[posbk][j])!=99) { 457 if (pole[pgm_read_byte(&king_step[posbk][j])]==fk) return(true); 458 j++; 459 } 460 return(false); 461} 462//**************************** 463 464//**************************** 465void add_king(int l, int i) { 466 signed char f1=pole[i]; 467 signed char f2; 468 int j=0; 469 while (pgm_read_byte(&king_step[i][j])!=99) { 470 f2=pole[pgm_read_byte(&king_step[i][j])]; 471 if (f2==0||f2<0&&f1>0||f2>0&&f1<0) { 472 steps[pos[l].l_step].typecheck=0; 473 steps[pos[l].l_step].c1=i; 474 steps[pos[l].l_step].c2=pgm_read_byte(&king_step[i][j]); 475 steps[pos[l].l_step].f1=f1; 476 steps[pos[l].l_step].f2=f2; 477 pos[l].l_step++; 478 } 479 j++; 480 } 481} 482//**************************** 483void add_knight(int l, int i) { 484 signed char f1=pole[i]; 485 signed char f2; 486 int j=0; 487 while (pgm_read_byte(&knight_step[i][j])!=99) { 488 f2=pole[pgm_read_byte(&knight_step[i][j])]; 489 if (f2==0||f2<0&&f1>0||f2>0&&f1<0) { 490 steps[pos[l].l_step].typecheck=0; 491 steps[pos[l].l_step].c1=i; 492 steps[pos[l].l_step].c2=pgm_read_byte(&knight_step[i][j]); 493 steps[pos[l].l_step].f1=f1; 494 steps[pos[l].l_step].f2=f2; 495 pos[l].l_step++; 496 } 497 j++; 498 } 499} 500//**************************** 501void add_stra(int l, int i) { 502 signed char f1=pole[i]; 503 signed char f2=0; 504 int j=0; 505 while (pgm_read_byte(&stra_step[i][j])!=99) { 506 if (pgm_read_byte(&stra_step[i][j])==88) f2=0; 507 else if (f2==0) { 508 f2=pole[pgm_read_byte(&stra_step[i][j])]; 509 if (f2==0||f2<0&&f1>0||f2>0&&f1<0) { 510 steps[pos[l].l_step].typecheck=0; 511 steps[pos[l].l_step].c1=i; 512 steps[pos[l].l_step].c2=pgm_read_byte(&stra_step[i][j]); 513 steps[pos[l].l_step].f1=f1; 514 steps[pos[l].l_step].f2=f2; 515 516 pos[l].l_step++; 517 } 518 } 519 j++; 520 } 521} 522//**************************** 523void add_diag(int l, int i) { 524 signed char f1=pole[i]; 525 signed char f2=0; 526 int j=0; 527 while (pgm_read_byte(&diag_step[i][j])!=99) { 528 if (pgm_read_byte(&diag_step[i][j])==88) f2=0; 529 else if (f2==0) { 530 f2=pole[pgm_read_byte(&diag_step[i][j])]; 531 if (f2==0||f2<0&&f1>0||f2>0&&f1<0) { 532 steps[pos[l].l_step].typecheck=0; 533 steps[pos[l].l_step].c1=i; 534 steps[pos[l].l_step].c2=pgm_read_byte(&diag_step[i][j]); 535 steps[pos[l].l_step].f1=f1; 536 steps[pos[l].l_step].f2=f2; 537 pos[l].l_step++; 538 } 539 } 540 j++; 541 } 542} 543//**************************** 544void add_one(int l, int c1, int c2) { 545 steps[pos[l].l_step].typecheck=0; 546 steps[pos[l].l_step].c1=c1; 547 steps[pos[l].l_step].c2=c2; 548 steps[pos[l].l_step].f1=pole[c1]; 549 steps[pos[l].l_step].f2=pole[c2]; 550 pos[l].l_step++; 551} 552//**************************** 553void sort_steps(int l) { //moves massive sort by weight 554step_t buf; 555 for (int i=pos[l].b_step;i<pos[l].l_step-1;i++) { 556 int maxweight=steps[i].weight; 557 int maxj=i; 558 for (int j=i+1;j<pos[l].l_step;j++) { 559 if (steps[j].weight>maxweight) { 560 maxweight=steps[j].weight; maxj=j; 561 } 562 } 563 if (maxweight==0&&l>0) return; 564 if (maxj==i) continue; 565 buf=steps[i]; 566 steps[i]=steps[maxj]; 567 steps[maxj]=buf; 568 } 569} 570//**************************** 571void generate_steps(int l) { 572 if (l>0) pos[l].b_step=pos[l-1].l_step; else pos[l].b_step=ply+MAXDEPTH; 573 pos[l].cur_step=pos[l].b_step; pos[l].l_step=pos[l].b_step; 574 int check; 575 signed char f; 576 if (pole[poswk]!=fk) { 577 for (int i=0;i<64;i++) if (pole[i]==fk) { poswk=i; break; } 578 } 579 if (pole[posbk]!=-fk) { 580 for (int i=0;i<64;i++) if (pole[i]==-fk) { posbk=i; break; } 581 } 582 if (l>0) { 583 if ((steps[pos[l-1].cur_step].typecheck&B1000)==0) { 584 if (pos[l].w) pos[l].check_on_table=check_w(); else pos[l].check_on_table=check_b(); 585 if (pos[l].check_on_table) steps[pos[l-1].cur_step].typecheck=steps[pos[l-1].cur_step].typecheck|B1000; 586 } else pos[l].check_on_table=1; 587 } else if (pos[0].w) pos[0].check_on_table=check_w(); else pos[0].check_on_table=check_b(); 588 for (int ii=0;ii<64;ii++) { 589 int i; 590 if (pos[l].w) i=ii; else i=63-ii; 591 f=pole[i]; 592 if (f==0||f<0&&pos[l].w||f>0&&!pos[l].w) continue; 593 if (pos[l].l_step>MAXSTEPS-30) break; 594 switch (abs(f)) { 595 case fn: add_knight(l,i);break; 596 case fb: add_diag(l,i); break; 597 case fr: add_stra(l,i); break; 598 case fq: add_stra(l,i); add_diag(l,i); break; 599 } 600 } 601 for (int ii=0;ii<64;ii++) { 602 int i; 603 if (pos[l].w) i=ii; else i=63-ii; 604 f=pole[i]; 605 if (f==0||f<0&&pos[l].w||f>0&&!pos[l].w) continue; 606 if (pos[l].l_step>MAXSTEPS-30) break; 607 switch (abs(f)) { 608 case fk: add_king(l,i); break; 609 case fp: 610 if (f==fp) { 611 if (row[i]<7&&pole[i-8]==0) add_one(l,i,i-8); 612 if (row[i]==2&&pole[i-8]==0&&pole[i-16]==0) add_one(l,i,i-16); 613 if (row[i]==7) { 614 if (pole[i-8]==0) { 615 add_one(l,i,i-8); steps[pos[l].l_step-1].typecheck=4; 616 add_one(l,i,i-8); steps[pos[l].l_step-1].typecheck=5; 617 add_one(l,i,i-8); steps[pos[l].l_step-1].typecheck=6; 618 add_one(l,i,i-8); steps[pos[l].l_step-1].typecheck=7; 619 } 620 if (column[i]>1&&pole[i-9]<0) { 621 add_one(l,i,i-9); steps[pos[l].l_step-1].typecheck=4; 622 add_one(l,i,i-9); steps[pos[l].l_step-1].typecheck=5; 623 add_one(l,i,i-9); steps[pos[l].l_step-1].typecheck=6; 624 add_one(l,i,i-9); steps[pos[l].l_step-1].typecheck=7; 625 } 626 if (column[i]<8&&pole[i-7]<0) { 627 add_one(l,i,i-7); steps[pos[l].l_step-1].typecheck=4; 628 add_one(l,i,i-7); steps[pos[l].l_step-1].typecheck=5; 629 add_one(l,i,i-7); steps[pos[l].l_step-1].typecheck=6; 630 add_one(l,i,i-7); steps[pos[l].l_step-1].typecheck=7; 631 } 632 } else { 633 if (column[i]>1&&pole[i-9]<0) add_one(l,i,i-9); 634 if (column[i]<8&&pole[i-7]<0) add_one(l,i,i-7); 635 } 636 } else if (f==-fp) { 637 if (row[i]>2&&pole[i+8]==0) add_one(l,i,i+8); 638 if (row[i]==7&&pole[i+8]==0&&pole[i+16]==0) add_one(l,i,i+16); 639 if (row[i]==2) { 640 if (pole[i+8]==0) { 641 add_one(l,i,i+8); steps[pos[l].l_step-1].typecheck=4; 642 add_one(l,i,i+8); steps[pos[l].l_step-1].typecheck=5; 643 add_one(l,i,i+8); steps[pos[l].l_step-1].typecheck=6; 644 add_one(l,i,i+8); steps[pos[l].l_step-1].typecheck=7; 645 } 646 if (column[i]>1&&pole[i+7]>0) { 647 add_one(l,i,i+7); steps[pos[l].l_step-1].typecheck=4; 648 add_one(l,i,i+7); steps[pos[l].l_step-1].typecheck=5; 649 add_one(l,i,i+7); steps[pos[l].l_step-1].typecheck=6; 650 add_one(l,i,i+7); steps[pos[l].l_step-1].typecheck=7; 651 } 652 if (column[i]<8&&pole[i+9]>0) { 653 add_one(l,i,i+9); steps[pos[l].l_step-1].typecheck=4; 654 add_one(l,i,i+9); steps[pos[l].l_step-1].typecheck=5; 655 add_one(l,i,i+9); steps[pos[l].l_step-1].typecheck=6; 656 add_one(l,i,i+9); steps[pos[l].l_step-1].typecheck=7; 657 } 658 } else { 659 if (column[i]>1&&pole[i+7]>0) add_one(l,i,i+7); 660 if (column[i]<8&&pole[i+9]>0) add_one(l,i,i+9); 661 } 662 } 663 } //switch 664 } // 665 666 if (pos[l].pp!=0&&pole[pos[l].pp]==0) { //en passant !!! 667 if (pos[l].w==1) { 668 if (column[pos[l].pp]>1&&pole[pos[l].pp+7]==fp) { add_one(l,pos[l].pp+7,pos[l].pp); steps[pos[l].l_step-1].typecheck=1; steps[pos[l].l_step-1].f2=-fp;} 669 if (column[pos[l].pp]<8&&pole[pos[l].pp+9]==fp) { add_one(l,pos[l].pp+9,pos[l].pp); steps[pos[l].l_step-1].typecheck=1; steps[pos[l].l_step-1].f2=-fp;} 670 } else { 671 if (column[pos[l].pp]>1&&pole[pos[l].pp-9]==-fp) { add_one(l,pos[l].pp-9,pos[l].pp); steps[pos[l].l_step-1].typecheck=1; steps[pos[l].l_step-1].f2=fp;} 672 if (column[pos[l].pp]<8&&pole[pos[l].pp-7]==-fp) { add_one(l,pos[l].pp-7,pos[l].pp); steps[pos[l].l_step-1].typecheck=1; steps[pos[l].l_step-1].f2=fp;} 673 } 674 } 675 676 if (pos[l].w==1&&!pos[l].check_on_table) { //white catle 677 if (pos[l].wrk) { //short 678 if (pole[60]==fk&&pole[61]==0&&pole[62]==0&&pole[63]==fr) { 679 pole[60]=0; pole[61]=fk; poswk=61; check=check_w(); pole[60]=fk; poswk=60; pole[61]=0; 680 if (!check) { 681 steps[pos[l].l_step].typecheck=2; 682 steps[pos[l].l_step].c1=60; 683 steps[pos[l].l_step].c2=62; 684 steps[pos[l].l_step].f1=fk; 685 steps[pos[l].l_step].f2=0; 686 pos[l].l_step++; 687 } 688 } 689 } 690 if (pos[l].wrq) { //long 691 if (pole[60]==fk&&pole[59]==0&&pole[58]==0&&pole[57]==0&&pole[56]==fr) { 692 pole[60]=0; pole[59]=fk; poswk=59; check=check_w(); pole[60]=fk; poswk=60; pole[59]=0; 693 if (!check) { 694 steps[pos[l].l_step].typecheck=3; 695 steps[pos[l].l_step].c1=60; 696 steps[pos[l].l_step].c2=58; 697 steps[pos[l].l_step].f1=fk; 698 steps[pos[l].l_step].f2=0; 699 pos[l].l_step++; 700 } 701 } 702 } 703 } else if (pos[l].w==0&&!pos[l].check_on_table) { //black castle 704 if (pos[l].brk) { //short 705 if (pole[4]==-fk&&pole[5]==0&&pole[6]==0&&pole[7]==-fr) { 706 pole[4]=0; pole[5]=-fk; posbk=5; check=check_b(); pole[4]=-fk; posbk=4; pole[5]=0; 707 if (!check) { 708 steps[pos[l].l_step].typecheck=2; 709 steps[pos[l].l_step].c1=4; 710 steps[pos[l].l_step].c2=6; 711 steps[pos[l].l_step].f1=-fk; 712 steps[pos[l].l_step].f2=0; 713 pos[l].l_step++; 714 } 715 } 716 } 717 if (pos[l].brq) { //long 718 if (pole[4]==-fk&&pole[3]==0&&pole[2]==0&&pole[1]==0&&pole[0]==-fr) { 719 pole[4]=0; pole[3]=-fk; posbk=3; check=check_b(); pole[4]=-fk; posbk=4; pole[3]=0; 720 if (!check) { 721 steps[pos[l].l_step].typecheck=3; 722 steps[pos[l].l_step].c1=4; 723 steps[pos[l].l_step].c2=2; 724 steps[pos[l].l_step].f1=-fk; 725 steps[pos[l].l_step].f2=0; 726 pos[l].l_step++; 727 } 728 } 729 } 730 } 731 for (int i=pos[l].b_step;i<pos[l].l_step;i++) { 732 steps[i].typecheck=steps[i].typecheck&B111; 733 steps[i].weight=abs(steps[i].f2); 734 if (abs(steps[i].typecheck&&B111)>3) steps[i].weight+=fig_weight[abs(steps[i].typecheck&&B111)-2]; 735 steps[i].weight<<=2; 736 if (l>0) { //add to weight of best level move 737 if (pos[l].cut.c2==steps[i].c2&&pos[l].cut.c1==steps[i].c1) steps[i].weight+=5; //best move 738 if (steps[i].c2==steps[pos[l-1].cur_step].c2) steps[i].weight+=8; //taking last moves figure 739 } 740 } //i 741 sort_steps(l); 742 743} 744//**************************** 745int evaluate(int l) { //calculating position weight proportional 746int res; 747 if (pos[l].w) res=5000L*(pos[l].weight_w-pos[l].weight_b+pos[l].weight_s)/(pos[l].weight_w+pos[l].weight_b+2000); 748 else res=5000L*(pos[l].weight_b-pos[l].weight_w-pos[l].weight_s)/(pos[l].weight_w+pos[l].weight_b+2000); 749 if (debute) res+=random(30); 750 return res; 751} 752//**************************** 753boolean checkd_w() { 754 signed char f2=0; 755 int j=0; 756 while (pgm_read_byte(&diag_step[poswk][j])!=99) { 757 if (pgm_read_byte(&diag_step[poswk][j])==88) f2=0; 758 else if (f2==0) { 759 f2=pole[pgm_read_byte(&diag_step[poswk][j])]; 760 if (f2==-fb||f2==-fq) return(true); 761 } 762 j++; 763 } 764 f2=0; j=0; 765 while (pgm_read_byte(&stra_step[poswk][j])!=99) { 766 if (pgm_read_byte(&stra_step[poswk][j])==88) f2=0; 767 else if (f2==0) { 768 f2=pole[pgm_read_byte(&stra_step[poswk][j])]; 769 if (f2==-fr||f2==-fq) return(true); 770 if (j==0||pgm_read_byte(&stra_step[poswk][j])==88) 771 if (f2==-fk) return(true); 772 } 773 j++; 774 } 775 return(false); 776} 777//**************************** 778boolean checkd_b() { 779 signed char f2=0; 780 int j=0; 781 while (pgm_read_byte(&diag_step[posbk][j])!=99) { 782 if (pgm_read_byte(&diag_step[posbk][j])==88) f2=0; 783 else if (f2==0) { 784 f2=pole[pgm_read_byte(&diag_step[posbk][j])]; 785 if (f2==fb||f2==fq) return(true); 786 } 787 j++; 788 } 789 f2=0; j=0; 790 while (pgm_read_byte(&stra_step[posbk][j])!=99) { 791 if (pgm_read_byte(&stra_step[posbk][j])==88) f2=0; 792 else if (f2==0) { 793 f2=pole[pgm_read_byte(&stra_step[posbk][j])]; 794 if (f2==fr||f2==fq) return(true); 795 if (j==0||pgm_read_byte(&stra_step[posbk][j])==88) 796 if (f2==fk) return(true); 797 } 798 j++; 799 } 800 return(false); 801} 802//**************************** 803int active(step_t& s) { //determines if move active before move 804int j; 805 if (s.f2!=0||(s.typecheck&B111)>3) return 1; //taking or promotion 806 if (abs(s.f2)==fk) return -1; //king moves not active, castling too 807 switch (s.f1) { 808 case fp: 809 if (row[s.c2]>5) return 1; //en passant 810 if (column[s.c2]>1&&posbk==s.c2-9||column[s.c2]<8&&posbk==s.c2-7) return 1; //check by pawn 811 return -1; 812 case -fp: 813 if (row[s.c2]<4) return 1; //en passant 814 if (column[s.c2]>1&&poswk==s.c2+7||column[s.c2]<8&&posbk==s.c2+9) return 1; //check by pawn 815 return -1; 816 case fn: 817 j=0; 818 while (pgm_read_byte(&knight_step[s.c2][j])!=99) { 819 if (pole[pgm_read_byte(&knight_step[s.c2][j])]==-fk) return 1; //check by knight 820 j++; 821 } 822 return 0; 823 case -fn: 824 j=0; 825 while (pgm_read_byte(&knight_step[s.c2][j])!=99) { 826 if (pole[pgm_read_byte(&knight_step[s.c2][j])]==fk) return 1; //check by knight 827 j++; 828 } 829 return 0; 830 case fb: 831 if (diag1[s.c2]!=diag1[posbk]&&diag2[s.c2]!=diag2[posbk]) return -1; //not king diagonal 832 return 0; 833 case -fb: 834 if (diag1[s.c2]!=diag1[poswk]&&diag2[s.c2]!=diag2[poswk]) return -1; //not king diagonal 835 return 0; 836 case fr: 837 if (row[s.c2]!=row[posbk]&&column[s.c2]!=column[posbk]) return -1; //not horiz-vert of king 838 return 0; 839 case -fr: 840 if (row[s.c2]!=row[poswk]&&column[s.c2]!=column[poswk]) return -1; //not horiz-vert of king 841 return 0; 842 case fq: 843 if (diag1[s.c2]!=diag1[posbk]&&diag2[s.c2]!=diag2[posbk]&& //not king diagonal 844 row[s.c2]!=row[posbk]&&column[s.c2]!=column[posbk]) return -1; //not horiz-vert of king 845 return 0; 846 case -fq: 847 if (diag1[s.c2]!=diag1[poswk]&&diag2[s.c2]!=diag2[poswk]&& //not king diagonal 848 row[s.c2]!=row[poswk]&&column[s.c2]!=column[poswk]) return -1; //not horiz-vert of king 849 return 0; 850 } //switch 851 return 0; 852} 853//**************************** 854int quiescence(int l, int alpha, int beta, int depthleft) { 855 if (depthleft<=0||l>MAXDEPTH-1) { 856 if (l>depth) depth=l; 857 return evaluate(l); 858 } 859 // Serial.println(l); 860 int score=-20000; 861 generate_steps(l); 862 if (pos[l].l_step>MAXSTEPS-30) return(evaluate(l)); 863 //if (pos[l].l_step>maxstep) maxstep=pos[l].l_step; 864 865 if (!pos[l].check_on_table) { 866 int weight=evaluate(l); 867 if (weight >= score) score=weight; 868 if (score>alpha) alpha=score; 869 if (alpha>=beta) return alpha; 870 } 871 int check,checked,act; 872 for (int i=pos[l].b_step;i<pos[l].l_step;i++) { 873 act=1; 874 if (!pos[l].check_on_table) { 875 act=active(steps[i]); 876 if (act==-1) continue; 877 } 878 movestep(l,steps[i]); 879 check=0; 880 if (act==0) { 881 if (pos[l].w) check=checkd_b(); else check=checkd_w(); 882 if (check) steps[i].typecheck=steps[i].typecheck|B1000; 883 if (!check) { backstep(l,steps[i]); continue; } 884 } 885 if (pos[l].w) checked=check_w(); else checked=check_b(); 886 if (checked) { backstep(l,steps[i]); continue; } //if check opens - move restricted 887 888 if (check&&depthleft==1&&l<MAXDEPTH-1) depthleft++; 889 890 pos[l].cur_step=i; 891 892 movepos(l,steps[i]); 893 steps[ply+l]=steps[i]; 894 int tmp=-quiescence(l+1,-beta,-alpha,depthleft-1); 895 backstep(l,steps[i]); 896 if (tmp>score) score=tmp; 897 if (score>alpha) { 898 alpha=score; 899 pos[l].best_step=i; 900 pos[l].cut=steps[i]; 901 } 902 if (alpha>=beta ) return alpha; 903 } 904 if (score==-20000) { 905 if (pos[l].check_on_table) { 906 score=-10000+l; 907 } 908 } 909 return score; 910} 911//**************************** 912void print_best(step_t& s) { 913 String wei=String(getcoeff()*s.weight/100.,2); 914 if (s.weight>9000) wei="+M"+String((10001-s.weight)/2); 915 int tim=(millis()-starttime)/1000; 916 Serial.print(str_step(pos[0].cut)+" ("+wei+") "+get_time(tim)+" "); 917} 918//**************************** 919int draw_repeat(int l) { 920 if (l+ply<=12) return 0; 921 for (int i=0;i<4;i++) { 922 int li=ply+l-i; 923 if (steps[li].c1!=steps[li-4].c1||steps[li].c2!=steps[li-4].c2|| 924 steps[li].c1!=steps[li-8].c1||steps[li].c2!=steps[li-8].c2) return 0; 925 } 926 if (TRACE>0) Serial.println("repeat!"); 927 return 1; 928} 929//**************************** 930int alphaBeta(int l, int alpha, int beta, int depthleft) { 931 int score=-20000, check, tmp; 932 if (depthleft<=0||l>=MAXDEPTH) { 933 int fd=4; //4 934 if (l<5&&steps[pos[0].cur_step].typecheck&B1000) fd+=2; // 935 if (steps[pos[l-1].cur_step].f2!=0) fd+=2; // 936 return quiescence(l,alpha,beta,fd); 937 } 938 if (l>0) generate_steps(l); 939 if (pos[l].l_step>MAXSTEPS-30) return(evaluate(l)); 940 //if (pos[l].l_step>maxstep) maxstep=pos[l].l_step; 941 for (int i=pos[l].b_step;i<pos[l].l_step;i++) { 942 if (l==0) depth=depthleft; 943 movestep(l,steps[i]); 944 if (pos[l].w) check=check_w(); else check=check_b(); 945 if (check) { backstep(l,steps[i]); continue; } //if check opens - move restricted 946 pos[l].cur_step=i; 947 movepos(l,steps[i]); 948 steps[ply+l]=steps[i]; 949 if (TRACE>l) { 950 if (l==0) { 951 Serial.print(str_step(steps[i])); Serial.print(" "); 952 } else { 953 Serial.println(); 954 for (int ll=0;ll<l;ll++) Serial.print(" "); 955 Serial.print(String(l+1)+"- "+str_step(steps[i])); 956 } 957 } //TRACE 958 tmp=-alphaBeta(l+1,-beta,-alpha,depthleft-1); 959 backstep(l,steps[i]); 960 if (draw_repeat(l)) tmp=0; 961 if (tmp>score) score=tmp; 962 steps[i].weight=tmp; 963 if (score>alpha&&!halt) { 964 alpha=score; 965 pos[l].best_step=i; 966 pos[l].cut=steps[i]; 967 if (l==0) { 968 if (depthleft<10) Serial.print(" "); 969 if (depth<10) Serial.print(" "); 970 Serial.print(String(depthleft)+"/"+String(depth)+" "); 971 print_best(steps[i]); 972 Serial.println(); 973 } 974 } 975 if (TRACE>l) { 976 if (l==0) { 977 Serial.println(" "+String(tmp)+" "+String(depth)); 978 } else { 979 Serial.print(" = "+String(tmp)); 980 } 981 } 982 if (alpha>=beta) return alpha; 983 if (halt||(l<3&&millis()-starttime>timelimith)) { //time out or stop 984 halt=1; 985 return score; 986 } 987 if (millis()-guitime>100) gui(); 988 } //all moves 989 if (score==-20000) { 990 if (pos[l].check_on_table) { 991 score=-10000+l; steps[pos[l-1].cur_step].typecheck=steps[pos[l-1].cur_step].typecheck|B1000; 992 } else score=0; 993 } 994 return score; 995} 996//**************************** 997//**************************** 998boolean is_draw() { //determines if draw on desk 999 boolean draw=false; 1000 int cn=0,cbw=0,cbb=0,co=0,cb=0,cw=0; 1001 for (int i=0;i<64;i++) { 1002 if (abs(pole[i])==1) co++; 1003 if (abs(pole[i])>3&&abs(pole[i])<6) co++; //calculationg pawns, rooks, queens 1004 if (abs(pole[i])==6) continue; //without kings 1005 if (abs(pole[i])==2) cn++; //number of knights 1006 if (abs(pole[i])==3&&(column[i]+row[i])%2==0) cbb++; //number of whitefields bishops 1007 if (abs(pole[i])==3&&(column[i]+row[i])%2==1) cbw++; //number of blackfields bishops 1008 if (pole[i]==3) cw++; //number of white bishops 1009 if (pole[i]==-3) cb++; /number of black bishops 1010 } 1011 if (cn==1&&co+cbb+cbw==0) draw=true; //one knight only 1012 if (cbb+cbw==1&&co+cn==0) draw=true; //one bishop only 1013 if (co+cn+cbb==0||co+cn+cbw==0) draw=true; // 1014 if (co+cn==0&&cb==1&&cw==1) draw=true; //two bihops diffrent color 1015 if (draw) return draw; 1016 int lastmove=0; 1017 for (int i=0;i<ply;i++) // 1018 if (abs(steps[i].c1)==fp||steps[i].f2!=0||(steps[i].typecheck&B111)!=0) lastmove=i; 1019 if (lastmove<ply-100) return 1; //50 moves rule draw 1020 if (lastmove>ply-11) return 0; // 1021 return 0; //!!!!!!!!!!!!!!!!!!!! 1022 int ply0=ply; 1023 char poleb[64]; // 1024 while (lastmove<ply0-11) { 1025 start_game(); 1026 for (int i=0;i<=lastmove;i++) { // 1027 pos[0].cur_step=i; 1028 movestep(0,steps[i]); 1029 movepos(0,steps[i]); 1030 pos[1].w=!pos[0].w; 1031 pos[0]=pos[1]; 1032 } 1033 for (int i=0;i<64;i++) poleb[i]=pole[i]; // 1034 int repeats=0; 1035 1036 lastmove++; 1037 } 1038 start_game(); 1039 for (int i=0;i<ply0;i++) { // 1040 pos[0].cur_step=i; 1041 movestep(0,steps[i]); 1042 movepos(0,steps[i]); 1043 pos[1].w=!pos[0].w; 1044 pos[0]=pos[1]; 1045 } 1046 ply=ply0; 1047 1048 return draw; 1049} 1050//**************************** 1051boolean is_debute() { 1052 int diff=0; 1053 for (int i=0;i<64;i++) if (pole[i]!=(char) pgm_read_byte(&polestart[i])) diff++; 1054 debute=0; 1055 if (diff<13) debute=1; 1056 return debute; 1057} 1058//**************************** 1059int generate_legal() { 1060 kingpositions(); 1061 generate_steps(0); 1062 int legal=0; 1063 int check; 1064 for (int i=pos[0].b_step;i<pos[0].l_step;i++) { 1065 pos[0].cur_step=i; 1066 movestep(0,steps[i]); 1067 if (pos[0].w) check=check_w(); else check=check_b(); 1068 //pos[0].check_on_table=check; 1069 if (!check) legal++; 1070 if (!check) steps[i].weight=0; else steps[i].weight=-30000; 1071 backstep(0,steps[i]); 1072 } 1073 sort_steps(0); 1074 pos[0].l_step=pos[0].b_step+legal; //illegal moves delete 1075 return(legal); 1076} 1077//**************************** 1078void kingpositions() { 1079 for (int i=0;i<64;i++) { //kings positions definition 1080 if (pole[i]==fk) poswk=i; 1081 if (pole[i]==-fk) posbk=i; 1082 } 1083} 1084//**************************** 1085int solve() { 1086step_t best; 1087 starttime=millis(); 1088 if (is_draw()) { Serial.println(" DRAW!"); return 0; } //draw 1089 kingpositions(); 1090 pos[0].weight_w=0;pos[0].weight_b=0; 1091 for (int i=0;i<64;i++) { //enspile and figures weights definition 1092 if (pole[i]<0) { 1093 pos[0].weight_b+=fig_weight[-pole[i]]; 1094 } else if (pole[i]>0) { 1095 pos[0].weight_w+=fig_weight[pole[i]]; //full start weight 8000 1096 } 1097 } 1098 if (pos[0].weight_w+pos[0].weight_b<3500) endspiel=true; else endspiel=false; //3500? 1099 is_debute(); 1100 //Serial.println(pos[0].weight_w); 1101 //Serial.println(pos[0].weight_b); 1102 pos[0].weight_s=0; 1103 pos[0].cut.f1=0; pos[0].cut.weight=0; 1104 for (int i=0;i<64;i++) { //get statistic estimation 1105 int f=pole[i]; 1106 if (!f) continue; 1107 if (abs(f)==fk&&endspiel) { 1108 if (f<0) 1109 pos[0].weight_s-=(int)pgm_read_word(&stat_weightb[6][i]); 1110 else 1111 pos[0].weight_s+=(int)pgm_read_word(&stat_weightw[6][i]); 1112 } else { 1113 if (f<0) 1114 pos[0].weight_s-=(int)pgm_read_word(&stat_weightb[-f-1][i]); 1115 else 1116 pos[0].weight_s+=(int)pgm_read_word(&stat_weightw[f-1][i]); 1117 } 1118 } 1119 int startscore=evaluate(0); 1120 count=0; //maxstep=0; 1121 for (int i=1;i<MAXDEPTH;i++) { 1122 if (i%2) pos[i].w=!pos[0].w; else pos[i].w=pos[0].w; 1123 pos[i].pp=0; 1124 } 1125 best.f1=0; 1126 int samebest=0; 1127 int legal=generate_legal(); 1128 if (legal==0) 1129 if (pos[0].check_on_table) { Serial.println(" CHECKMATE!"); return -2; } // 1130 else { Serial.println(" PAT!"); return 0; } // 1131 1132 if (legal==1) { //ove answere 1133 pos[0].cut=steps[pos[0].b_step]; 1134 movestep(0,pos[0].cut); 1135 int v=evaluate(0); 1136 backstep(0,pos[0].cut); 1137 pos[0].cut.weight=v; 1138 return 1; 1139 } 1140 1141 halt=0; 1142 BAction.Show("STOP"); 1143 BMenu.Hide(); 1144 randomSeed(millis()); 1145 erasestatus(); 1146 //status_c1=-1; status_c2=-1; 1147 solving=1; 1148 int ALPHA=-20000; 1149 int BETA=20000; 1150 level=2; //2 1151 for (int x=0;x<MAXDEPTH;x++) { 1152 pos[x].cut.f1=0; pos[x].cut.c2=-1; 1153 } // 1154 int score; 1155 while (level<=10) { 1156 if (TRACE>0) { 1157 Serial.print(F("******* LEVEL=")); Serial.print(level); 1158 Serial.println(); 1159 } 1160 for (int x=1;x<MAXDEPTH;x++) { 1161 pos[x].cut.f1=0; pos[x].cut.c2=-1; 1162 } // 0 1163 for (int i=pos[0].b_step;i<pos[0].l_step;i++) { // 1164 pos[0].cur_step=i; 1165 movestep(0,steps[i]); 1166 int check=0; 1167 if (pos[0].w) check=check_b(); else check=check_w(); 1168 if (check) steps[i].typecheck=steps[i].typecheck|B1000; 1169 steps[i].weight+=evaluate(0)+(steps[i].typecheck&B1000)*30; 1170 if (steps[i].f2!=0) steps[i].weight-=steps[i].f1; 1171 backstep(0,steps[i]); 1172 } 1173 steps[pos[0].b_step].weight+=10000; //first - always first 1174 sort_steps(0); 1175 for (int i=pos[0].b_step;i<pos[0].l_step;i++) steps[i].weight=-8000; //weights down 1176 1177// show_steps(0); 1178// delay(100000000000000000000); 1179 1180 score=alphaBeta(0,ALPHA,BETA,level); 1181 unsigned long tim=millis()-starttime; 1182 boolean out=0; 1183 ALPHA=score-100; 1184 BETA=score+100; 1185 if (score>=BETA) { out++; BETA=20000; } 1186 if (score<=ALPHA) { out++; ALPHA=-20000; } 1187 sort_steps(0); // 1188 if (best.f1==steps[pos[0].b_step].f1&&best.c1==steps[pos[0].b_step].c1 1189 &&best.c2==steps[pos[0].b_step].c2&&best.typecheck==steps[pos[0].b_step].typecheck) { 1190 samebest++; 1191 if (samebest>=2&&score>=startscore+200&&tim>timelimith/4) break; 1192 } else { best=steps[pos[0].b_step]; samebest=0; } 1193 if (score>9900||pos[0].cut.weight<-9900||tim>timelimith||halt) break; 1194 1195 if (!out) level++; 1196 } 1197 Serial.print("Move="); 1198 print_best(pos[0].cut); 1199 Serial.println(" count="+String(count)+" nps="+String(1000*count/(millis()-starttime))); 1200 //Serial.println(" maxstep="+String(maxstep)); 1201 halt=1; 1202 show_status(); 1203 solving=0; 1204 if (pos[0].cut.weight<-9900) return -1; 1205 return 1; 1206} 1207//**************************** 1208void wactest() { 1209char w[150]; String ss=""; 1210 timelimith=120000; 1211 TRACE=0; 1212 for (int i=155;i<=300;i++) { 1213 strcpy_P(w, (char*)pgm_read_word(&wacs[i-1])); 1214 ss=w; 1215 new_game(ss); 1216 show_position(); 1217 clearstatus(); 1218 show_board(); 1219 Serial.println(ss); 1220 Serial.println(); 1221 } 1222} 1223//********************************** 1224float getcoeff() { 1225 float coeff=(pos[0].weight_b+pos[0].weight_w+2000)/5000.0; 1226 //Serial.println(coeff,2); 1227 return coeff; 1228} 1229//********************************** 1230void show_status() { 1231 String wei; 1232 1233 if (pos[0].cut.weight>9000) wei="M"+String((10001-pos[0].cut.weight)/2); 1234 else if (pos[0].cut.weight<-9000) wei="-M"+String((10001+pos[0].cut.weight)/2); 1235 else wei=String(getcoeff()*pos[0].cut.weight/100.0,2); 1236 if (pos[0].cut.weight>0) wei="+"+wei; 1237 uint16_t c=GRAY; 1238 if (halt) { 1239 wei=wei+" "+String(1000*count/(millis()-starttime)); 1240 showstatus(get_time((millis()-starttime)/1000)+" "+String(level)+"/"+String(depth),str_step(pos[0].cut),wei,GRAY,WHITE); 1241 } else { 1242 showstatus(get_time((millis()-starttime)/1000)+" "+String(level),str_step(pos[0].cut),wei); 1243 } 1244} 1245//********************************** 1246void closemenu() { 1247 menu=0; 1248 BMenu.Show("MENU"); 1249 BBack.Hide(); 1250 BTime.Hide(); 1251 BNew.Hide(); 1252 BAuto.Hide(); 1253 BRotate.Hide(); 1254 BLoad.Hide(); 1255 BSave.Hide(); 1256 clearmenu(); 1257 show_steps(); 1258 clearstatus(); 1259 BAction.Show("START"); 1260} 1261//********************************** 1262void check_gameend() { 1263 kingpositions(); 1264 String st; 1265 if (is_draw()) { gameover=1; st=F("draw!"); } 1266 else if (generate_legal()==0) 1267 if (pos[0].check_on_table) { gameover=1; st=F("checkmate!"); } // 1268 else { gameover=1; st=F("pat!"); } // 1269 if (gameover) showstatus(statusbuf1,st,statusbuf3,GRAY,RED); 1270} 1271//********************************** 1272void eepromsave() { 1273 EEPROM.put(0,limit); 1274 EEPROM.put(1,autow); 1275 EEPROM.put(2,autob); 1276 EEPROM.put(3,rotate); 1277 EEPROM.put(4,sound); 1278 EEPROM.put(5,ply); 1279 EEPROM.put(10,startpos); 1280 for (int i=0;i<ply;i++) 1281 EEPROM.put(100+i*sizeof(step_t),steps[i]); 1282} 1283//********************************** 1284void eepromload() { 1285 EEPROM.get(0,limit); 1286 EEPROM.get(1,autow); 1287 EEPROM.get(2,autob); 1288 EEPROM.get(3,rotate); 1289 EEPROM.get(4,sound); 1290 EEPROM.get(10,startpos); 1291 start_game(); 1292 EEPROM.get(5,ply); 1293 for (int i=0;i<ply;i++) 1294 EEPROM.get(100+i*sizeof(step_t),steps[i]); 1295 int pl=ply; 1296 for (int i=0;i<pl;i++) { 1297 pos[0].cur_step=i; 1298 if (pos[0].w==1) pos[1].w=1; else pos[1].w=0; 1299 if (steps[i].f1!=0) { 1300 movestep(0,steps[i]); 1301 movepos(0,steps[i]); 1302 } 1303 pos[0]=pos[1]; 1304 } 1305 ply=pl; 1306 if (ply%2==0) pos[0].w=1; else pos[0].w=0; 1307} 1308//********************************** 1309void gui() { 1310char w[150]; 1311 if (Serial.available()) { 1312 String s=""; 1313 while (Serial.available()) s=s+char(Serial.read()); 1314 s.trim(); 1315 if (solving) { 1316 if (!halt) { 1317 s.toUpperCase(); 1318 if (s=="STOP") { halt=1; Serial.println("STOPPED"); } 1319 } 1320 } else { //!solving 1321 if (s.indexOf("TIME")==0||s.indexOf("time")==0) { 1322 long tim=s.substring(4).toInt(); 1323 if (tim!=0) timelimith=tim*1000; 1324 if (timelimith/60000>0) { 1325 Serial.print("timelimith = "+String(timelimith/60000)+" min "); 1326 int sec=(timelimith%60000)/1000; 1327 if (sec>0) Serial.println(String(sec)+" sec"); else Serial.println(); 1328 } else Serial.println("timelimith = "+String(timelimith/1000)+" sec"); 1329 } else { 1330 if (s.indexOf("/")==-1) { 1331 int n=s.toInt(); 1332 if (n>0&&n<=300) { 1333 strcpy_P(w, (char*)pgm_read_word(&wacs[n-1])); 1334 s=w; 1335 } else if (s=="0") s=F("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -"); 1336 else return; 1337 } 1338 new_game(s); 1339 gameover=0; 1340 if (pos[0].w) { autow=1; autob=0; } else { autob=1; autow=0; } 1341 initboard(); 1342 show_position(); 1343 clearstatus(); 1344 show_board(); 1345 Serial.println(s); 1346 } 1347 } 1348 Serial.println(F("Command:")); 1349 } //serial 1350 if (gettouch()) { 1351 if (solving) { 1352 if (BAction.IsPressed()) { //calculation stop 1353 beep(100); 1354 if (!halt) { 1355 halt=1; 1356 pause=1; 1357 BAction.Hide(); 1358 } 1359 } 1360 } else { //solving 1361 if (BAction.IsPressed()) { 1362 beep(100); 1363 if (status_c1!=-1&&status_c2!=-1) { //player move try 1364 generate_legal(); 1365 int g=0, gn=-1; 1366 for (int i=pos[0].b_step;i<pos[0].l_step;i++) { 1367 if (steps[i].c1==status_c1&&steps[i].c2==status_c2) { g++; gn=i; } 1368 } 1369 if (!g) { 1370 beep(300); 1371 erasestatus(); 1372 } else { 1373 pos[0].cur_step=gn; 1374 movestep(0,steps[gn]); 1375 movepos(0,steps[gn]); 1376 steps[ply]=steps[gn]; 1377 pos[1].w=!pos[0].w; 1378 pos[0]=pos[1]; 1379 ply++; 1380 //show_position(); 1381 show_board(); 1382 show_steps(); 1383 erasestatus(); 1384 check_gameend(); 1385 BAction.Show("START"); 1386 BMenu.Show("MENU"); 1387 pause=0; 1388 } 1389 } else { 1390 pause=0; 1391 BAction.Show("START"); 1392 } 1393 } else if (BMenu.IsPressed()) { 1394 beep(100); 1395 if (!menu) { 1396 menu=1; 1397 BAction.Hide(); 1398 erasestatus(); 1399 clearmenu(); 1400 BMenu.Show("EXIT"); 1401 if (ply>1) BBack.Show("BACK"); else BBack.Hide(); 1402 BTime.Show(limitstrings[limit]); 1403 BNew.Show("NEW"); 1404 String sa=""; 1405 if (autow) sa="W"; 1406 if (autob) sa=sa+"B"; 1407 if (sa=="") sa="-"; 1408 sa="AUTO:"+sa; 1409 BAuto.Show(sa); 1410 BRotate.Show("ROTATE"); 1411 BLoad.Show(); 1412 BSave.Show(); 1413 } else { //menu 1414 closemenu(); 1415 } 1416 } else if (BTime.IsPressed()) { 1417 beep(100); 1418 limit+=1; if (limit>9) limit=0; 1419 timelimith=limits[limit]*1000; 1420 //Serial.println(timelimith); 1421 BTime.Show(limitstrings[limit]); 1422 } else if (BBack.IsPressed()) { 1423 beep(100); 1424 int pl=ply-2; 1425 if (pl<0) pl=0; 1426 start_game(); 1427 for (int i=0;i<pl;i++) { 1428 pos[0].cur_step=i; 1429 if (pos[0].w==1) pos[1].w=1; else pos[1].w=0; 1430 if (steps[i].f1!=0) { 1431 movestep(0,steps[i]); 1432 movepos(0,steps[i]); 1433 } 1434 pos[0]=pos[1]; 1435 } 1436 ply=pl; 1437 if (ply%2==0) pos[0].w=1; else pos[0].w=0; 1438 closemenu(); 1439 erasestatus(); 1440 show_board(); 1441 show_color(); 1442 show_steps(); 1443 } else if (BNew.IsPressed()) { 1444 beep(100); 1445 new_game(); 1446 cleardisplayboard(); 1447 show_board(); 1448 border(); 1449 closemenu(); 1450 erasestatus(); 1451 gameover=0; 1452 } else if (BAuto.IsPressed()) { 1453 beep(100); 1454 if (!autow&&!autob) autob=1; 1455 else if (!autow&&autob) { autow=1; autob=0; } 1456 else if (autow&&!autob) { autow=1; autob=1; } 1457 else { autow=0; autob=0; } 1458 String sa=""; 1459 if (autow) sa="W"; 1460 if (autob) sa=sa+"B"; 1461 if (sa=="") sa="-"; 1462 sa="AUTO:"+sa; 1463 BAuto.Show(sa); 1464 show_color(); 1465 } else if (BRotate.IsPressed()) { 1466 beep(100); 1467 BRotate.Show(); 1468 if (rotate) rotate=0; else rotate=1; 1469 erasestatus(); 1470 border(); 1471 cleardisplayboard(); 1472 show_board(); 1473 show_color(); 1474 } else if (BSave.IsPressed()) { 1475 beep(100); 1476 eepromsave(); 1477 BSave.Show(); 1478 closemenu(); 1479 erasestatus(); 1480 } else if (BLoad.IsPressed()) { 1481 beep(100); 1482 eepromload(); 1483 BLoad.Show(); 1484 closemenu(); 1485 erasestatus(); 1486 cleardisplayboard(); 1487 show_board(); 1488 show_color(); 1489 show_steps(); 1490 gameover=0; 1491 } else { 1492 signed char c=field_pressed(); 1493 if (!menu&&c!=-1) { 1494 if (status_c1==-1) { 1495 status_c1=c; status_step(status_c1,1,getColor(220,0,0)); 1496 } else if (status_c2==-1) { 1497 status_c2=c; status_step(status_c2,1,getColor(0,180,0)); 1498 } 1499 if (status_c1!=-1&&status_c2!=-1&&c!=status_c2) erasestatus(); 1500 } 1501 } 1502 1503 } //solving 1504 } //gettouch 1505 if (solving&&millis()-statustime>999) { show_status(); statustime=millis(); } 1506 if (!pause&&!menu&&!solving&&!gameover) { 1507 if (pos[0].w&&autow||!pos[0].w&&autob) { 1508 halt=0; 1509 TRACE=0; 1510 gameover=0; 1511 int res=solve(); 1512 //Serial.println(res); 1513 if (res==1) { 1514 movestep(0,pos[0].cut); 1515 movepos(0,pos[0].cut); 1516 steps[ply]=pos[0].cut; 1517 pos[0]=pos[1]; 1518 ply++; 1519 //show_position(); 1520 show_board(); 1521 show_steps(); 1522 erasestatus(); 1523 check_gameend(); 1524 } else { 1525 String st=F("draw!"); 1526 if (res==-1) st=F("give up!"); 1527 else if (res==-2) st=F("checkmate!"); 1528 for (int k=0;k<11;k++) statusbuf2[k]='-'; 1529 showstatus(statusbuf1,st,statusbuf3,GRAY,RED); 1530 gameover=1; 1531 } 1532 BAction.Show("START"); 1533 BMenu.Show("MENU"); 1534 } else { // 1535 } 1536 } 1537 guitime=millis(); 1538} 1539//**************************** 1540void loop() { 1541 gui(); 1542 delay(100); 1543} 1544//**************************** 1545
logic.h
h
1const signed char fp=1; //pawn 2const signed char fn=2; //knight 3const signed char fb=3; //bishop 4const signed char fr=4; //rook 5const signed char fq=5; //queen 6const signed char fk=6; //king 7const int fig_weight[]={0,100,320,330,500,900,0}; 8const char fig_symb[]=" NBRQK"; 9const char fig_symb1[]=" pNBRQK"; 10 11char pole[64]; // 12 13const byte column[64] ={ 14 1, 2, 3, 4, 5, 6, 7, 8, 15 1, 2, 3, 4, 5, 6, 7, 8, 16 1, 2, 3, 4, 5, 6, 7, 8, 17 1, 2, 3, 4, 5, 6, 7, 8, 18 1, 2, 3, 4, 5, 6, 7, 8, 19 1, 2, 3, 4, 5, 6, 7, 8, 20 1, 2, 3, 4, 5, 6, 7, 8, 21 1, 2, 3, 4, 5, 6, 7, 8 22}; 23const byte row[64] = { 24 8, 8, 8, 8, 8, 8, 8, 8, 25 7, 7, 7, 7, 7, 7, 7, 7, 26 6, 6, 6, 6, 6, 6, 6, 6, 27 5, 5, 5, 5, 5, 5, 5, 5, 28 4, 4, 4, 4, 4, 4, 4, 4, 29 3, 3, 3, 3, 3, 3, 3, 3, 30 2, 2, 2, 2, 2, 2, 2, 2, 31 1, 1, 1, 1, 1, 1, 1, 1 32}; 33const byte diag1[64] ={ 34 1, 2, 3, 4, 5, 6, 7, 8, 35 2, 3, 4, 5, 6, 7, 8, 9, 36 3, 4, 5, 6, 7, 8, 9,10, 37 4, 5, 6, 7, 8, 9,10,11, 38 5, 6, 7, 8, 9,10,11,12, 39 6, 7, 8, 9,10,11,12,13, 40 7, 8, 9,10,11,12,13,14, 41 8, 9,10,11,12,13,14,15 42}; 43const byte diag2[64] ={ 44 8, 7, 6, 5, 4, 3, 2, 1, 45 9, 8, 7, 6, 5, 4, 3, 2, 46 10, 9, 8, 7, 6, 5, 4, 3, 47 11,10, 9, 8, 7, 6, 5, 4, 48 12,11,10, 9, 8, 7, 6, 5, 49 13,12,11,10, 9, 8, 7, 6, 50 14,13,12,11,10, 9, 8, 7, 51 15,14,13,12,11,10, 9, 8 52}; 53 54const char polestart[64] PROGMEM={ 55 -fr,-fn,-fb,-fq,-fk,-fb,-fn,-fr, 56 -fp,-fp,-fp,-fp,-fp,-fp,-fp,-fp, 57 0, 0, 0, 0, 0, 0, 0, 0, 58 0, 0, 0, 0, 0, 0, 0, 0, 59 0, 0, 0, 0, 0, 0, 0, 0, 60 0, 0, 0, 0, 0, 0, 0, 0, 61 fp, fp, fp, fp, fp, fp, fp, fp, 62 fr, fn, fb, fq, fk, fb, fn, fr 63}; 64 65const short stat_weightw[7][64] PROGMEM={ 66 { 0, 0, 0, 0, 0, 0, 0, 0, //pawn 67 100,100,100,100,100,100,100,100, // 50, 50, 50, 50, 50, 50, 50, 50, 68 20, 30, 40, 50, 50, 40, 30, 20, // 10, 10, 20, 30, 30, 20, 10, 10, 69 5, 5, 10, 25, 25, 10, 5, 5, 70 0, 0, 0, 20, 20, 0, 0, 0, 71 5, -5,-10, 0, 0,-10, -5, 5, 72 5, 10, 10,-20,-20, 10, 10, 5, // 5, 10, 10,-20,-20, 10, 10, 5, 73 0, 0, 0, 0, 0, 0, 0, 0}, 74 75 {-50,-40,-30,-30,-30,-30,-40,-50, //knife 76 -40,-20, 0, 0, 0, 0,-20,-40, 77 -30, 0, 10, 15, 15, 10, 0,-30, 78 -30, 5, 15, 20, 20, 15, 5,-30, 79 -30, 0, 15, 20, 20, 15, 0,-30, 80 -30, 5, 10, 15, 15, 10, 5,-30, 81 -40,-20, 0, 5, 5, 0,-20,-40, 82 -50,-40,-30,-30,-30,-30,-40,-50}, 83 84 {-20,-10,-10,-10,-10,-10,-10,-20, //bishop 85 -10, 0, 0, 0, 0, 0, 0,-10, 86 -10, 0, 5, 10, 10, 5, 0,-10, 87 -10, 5, 5, 10, 10, 5, 5,-10, 88 -10, 0, 10, 10, 10, 10, 0,-10, 89 -10, 10, 10, 10, 10, 10, 10,-10, 90 -10, 5, 0, 0, 0, 0, 5,-10, 91 -20,-10,-10,-10,-10,-10,-10,-20}, 92 93 { 0, 0, 0, 0, 0, 0, 0, 0, //rook 94 5, 10, 10, 10, 10, 10, 10, 5, 95 -5, 0, 0, 0, 0, 0, 0, -5, 96 -5, 0, 0, 0, 0, 0, 0, -5, 97 -5, 0, 0, 0, 0, 0, 0, -5, 98 -5, 0, 0, 0, 0, 0, 0, -5, 99 -5, 0, 0, 0, 0, 0, 0, -5, 100 0, 0, 0, 5, 5, 0, 0, 0}, 101 102 {-20,-10,-10, -5, -5,-10,-10,-20, //queen 103 -10, 0, 0, 0, 0, 0, 0,-10, 104 -10, 0, 5, 5, 5, 5, 0,-10, 105 -5, 0, 5, 5, 5, 5, 0, -5, 106 0, 0, 5, 5, 5, 5, 0, -5, 107 -10, 5, 5, 5, 5, 5, 0,-10, 108 -10, 0, 5, 0, 0, 0, 0,-10, 109 -20,-10,-10, -5, -5,-10,-10,-20}, 110 111 {-30,-40,-40,-50,-50,-40,-40,-30, //kingw 112 -30,-40,-40,-50,-50,-40,-40,-30, 113 -30,-40,-40,-50,-50,-40,-40,-30, 114 -30,-40,-40,-50,-50,-40,-40,-30, 115 -20,-30,-30,-40,-40,-30,-30,-20, 116 -10,-20,-20,-20,-20,-20,-20,-10, 117 10, 10,-10,-10,-10,-10, 10, 10, 118 10, 40, 30, 0, 0, 0, 50, 10}, 119 120 {-50,-40,-30,-20,-20,-30,-40,-50, //king endspiel 121 -30,-20,-10, 0, 0,-10,-20,-30, 122 -30,-10, 20, 30, 30, 20,-10,-30, 123 -30,-10, 30, 40, 40, 30,-10,-30, 124 -30,-10, 30, 40, 40, 30,-10,-30, 125 -30,-10, 20, 30, 30, 20,-10,-30, 126 -30,-30, 0, 0, 0, 0,-30,-30, 127 -50,-30,-30,-30,-30,-30,-30,-50} 128}; 129 130const short stat_weightb[7][64] PROGMEM={ 131 { 0, 0, 0, 0, 0, 0, 0, 0, //pawn 132 5, 10, 10,-20,-20, 10, 10, 5, 133 5, -5,-10, 0, 0,-10, -5, 5, 134 0, 0, 0, 20, 20, 0, 0, 0, 135 5, 5, 10, 25, 25, 10, 5, 5, 136 20, 30, 40, 50, 50, 40, 30, 20, 137 100,100,100,100,100,100,100,100, 138 0, 0, 0, 0, 0, 0, 0, 0}, 139 140 {-50,-40,-30,-30,-30,-30,-40,-50, //knife 141 -40,-20, 0, 0, 0, 0,-20,-40, 142 -30, 5, 10, 15, 15, 10, 5,-30, 143 -30, 0, 15, 20, 20, 15, 0,-30, 144 -30, 5, 15, 20, 20, 15, 5,-30, 145 -30, 0, 10, 15, 15, 10, 0,-30, 146 -40,-20, 0, 5, 5, 0,-20,-40, 147 -50,-40,-30,-30,-30,-30,-40,-50}, 148 149 {-20,-10,-10,-10,-10,-10,-10,-20, //bishop 150 -10, 5, 0, 0, 0, 0, 5,-10, 151 -10, 10, 10, 10, 10, 10, 10,-10, 152 -10, 0, 10, 10, 10, 10, 0,-10, 153 -10, 5, 5, 10, 10, 5, 5,-10, 154 -10, 0, 5, 10, 10, 5, 0,-10, 155 -10, 0, 0, 0, 0, 0, 0,-10, 156 -20,-10,-10,-10,-10,-10,-10,-20}, 157 158 { 0, 0, 0, 5, 5, 0, 0, 0, //rook 159 -5, 0, 0, 0, 0, 0, 0, -5, 160 -5, 0, 0, 0, 0, 0, 0, -5, 161 -5, 0, 0, 0, 0, 0, 0, -5, 162 -5, 0, 0, 0, 0, 0, 0, -5, 163 -5, 0, 0, 0, 0, 0, 0, -5, 164 5, 10, 10, 10, 10, 10, 10, 5, 165 0, 0, 0, 0, 0, 0, 0, 0}, 166 167 {-20,-10,-10, -5, -5,-10,-10,-20, //queen 168 -10, 0, 5, 0, 0, 0, 0,-10, 169 -10, 5, 5, 5, 5, 5, 0,-10, 170 0, 0, 5, 5, 5, 5, 0, -5, 171 -5, 0, 5, 5, 5, 5, 0, -5, 172 -10, 0, 5, 5, 5, 5, 0,-10, 173 -10, 0, 0, 0, 0, 0, 0,-10, 174 -20,-10,-10, -5, -5,-10,-10,-20}, 175 176 { 10, 40, 30, 0, 0, 0, 50, 10, //kingb 177 10, 10,-10,-10,-10,-10, 10, 10, 178 -10,-20,-20,-20,-20,-20,-20,-10, 179 -20,-30,-30,-40,-40,-30,-30,-20, 180 -30,-40,-40,-50,-50,-40,-40,-30, 181 -30,-40,-40,-50,-50,-40,-40,-30, 182 -30,-40,-40,-50,-50,-40,-40,-30, 183 -30,-40,-40,-50,-50,-40,-40,-30}, 184 185 {-50,-30,-30,-30,-30,-30,-30,-50, //kingb endspiel 186 -30,-30, 0, 0, 0, 0,-30,-30, 187 -30,-10, 20, 30, 30, 20,-10,-30, 188 -30,-10, 30, 40, 40, 30,-10,-30, 189 -30,-10, 30, 40, 40, 30,-10,-30, 190 -30,-10, 20, 30, 30, 20,-10,-30, 191 -30,-20,-10, 0, 0,-10,-20,-30, 192 -50,-40,-30,-20,-20,-30,-40,-50} 193}; 194 195//88 - end of raw 196//99 - end of all 197const byte diag_step[64][17] PROGMEM={ 198 {9,18,27,36,45,54,63,99}, //0 199 {10,19,28,37,46,55,88,8,99}, //1 200 {11,20,29,38,47,88,9,16,99}, //2 201 {12,21,30,39,88,10,17,24,99}, //3 202 {13,22,31,88,11,18,25,32,99}, //4 203 {14,23,88,12,19,26,33,40,99}, //5 204 {15,88,13,20,27,34,41,48,99}, //6 205 {14,21,28,35,42,49,56,99}, //7 206 {17,26,35,44,53,62,88,1,99}, //8 207 {18,27,36,45,54,63,88,16,88,0,88,2,99}, //9 208 {19,28,37,46,55,88,17,24,88,1,88,3,99}, //10 209 {20,29,38,47,88,18,25,32,88,2,88,4,99}, //11 210 {21,30,39,88,19,26,33,40,88,3,88,5,99}, //12 211 {22,31,88,20,27,34,41,48,88,4,88,6,99}, //13 212 {23,88,21,28,35,42,49,56,88,5,88,7,99}, //14 213 {22,29,36,43,50,57,88,6,99}, //15 214 {25,34,43,52,61,88,9,2,99}, //16 215 {26,35,44,53,62,88,24,88,8,88,10,3,99}, //17 216 {27,36,45,54,63,88,25,32,88,9,0,88,11,4,99}, //18 217 {28,37,46,55,88,26,33,40,88,10,1,88,12,5,99}, //19 218 {29,38,47,88,27,34,41,48,88,11,2,88,13,6,99}, //20 219 {30,39,88,28,35,42,49,56,88,12,3,88,14,7,99}, //21 220 {31,88,29,36,43,50,57,88,13,4,88,15,99}, //22 221 {30,37,44,51,58,88,14,5,99}, //23 222 {33,42,51,60,88,17,10,3,99}, //24 223 {34,43,52,61,88,32,88,16,88,18,11,4,99}, //25 224 {35,44,53,62,88,33,40,88,17,8,88,19,12,5,99}, //26 225 {36,45,54,63,88,34,41,48,88,18,9,0,88,20,13,6,99}, //27 226 {37,46,55,88,35,42,49,56,88,19,10,1,88,21,14,7,99}, //28 227 {38,47,88,36,43,50,57,88,20,11,2,88,22,15,99}, //29 228 {39,88,37,44,51,58,88,21,12,3,88,23,99}, //30 229 {38,45,52,59,88,22,13,4,99}, //31 230 {41,50,59,88,25,18,11,4,99}, //32 231 {42,51,60,88,40,88,24,88,26,19,12,5,99}, //33 232 {43,52,61,88,41,48,88,25,16,88,27,20,13,6,99}, //34 233 {44,53,62,88,42,49,56,88,26,17,8,88,28,21,14,7,99}, //35 234 {45,54,63,88,43,50,57,88,27,18,9,0,88,29,22,15,99}, //36 235 {46,55,88,44,51,58,88,28,19,10,1,88,30,23,99}, //37 236 {47,88,45,52,59,88,29,20,11,2,88,31,99}, //38 237 {46,53,60,88,30,21,12,3,99}, //39 238 {49,58,88,33,26,19,12,5,99}, //40 239 {50,59,88,48,88,32,88,34,27,20,13,6,99}, //41 240 {51,60,88,49,56,88,33,24,88,35,28,21,14,7,99}, //42 241 {52,61,88,50,57,88,34,25,16,88,36,29,22,15,99}, //43 242 {53,62,88,51,58,88,35,26,17,8,88,37,30,23,99}, //44 243 {54,63,88,52,59,88,36,27,18,9,0,88,38,31,99}, //45 244 {55,88,53,60,88,37,28,19,10,1,88,39,99}, //46 245 {54,61,88,38,29,20,11,2,99}, //47 246 {57,88,41,34,27,20,13,6,99}, //48 247 {58,88,56,88,40,88,42,35,28,21,14,7,99}, //49 248 {59,88,57,88,41,32,88,43,36,29,22,15,99}, //50 249 {60,88,58,88,42,33,24,88,44,37,30,23,99}, //51 250 {61,88,59,88,43,34,25,16,88,45,38,31,99}, //52 251 {62,88,60,88,44,35,26,17,8,88,46,39,99}, //53 252 {63,88,61,88,45,36,27,18,9,0,88,47,99}, //54 253 {62,88,46,37,28,19,10,1,99}, //55 254 {49,42,35,28,21,14,7,99}, //56 255 {48,88,50,43,36,29,22,15,99}, //57 256 {49,40,88,51,44,37,30,23,99}, //58 257 {50,41,32,88,52,45,38,31,99}, //59 258 {51,42,33,24,88,53,46,39,99}, //60 259 {52,43,34,25,16,88,54,47,99}, //61 260 {53,44,35,26,17,8,88,55,99}, //62 261 {54,45,36,27,18,9,0,99} //63 ++++++ 262}; 263 264const byte stra_step[64][18] PROGMEM={ 265 {1,2,3,4,5,6,7,88,8,16,24,32,40,48,56,99}, //0 266 {2,3,4,5,6,7,88,9,17,25,33,41,49,57,88,0,99}, //1 267 {3,4,5,6,7,88,10,18,26,34,42,50,58,88,1,0,99}, //2 268 {4,5,6,7,88,11,19,27,35,43,51,59,88,2,1,0,99}, //3 269 {5,6,7,88,12,20,28,36,44,52,60,88,3,2,1,0,99}, //4 270 {6,7,88,13,21,29,37,45,53,61,88,4,3,2,1,0,99}, //5 271 {7,88,14,22,30,38,46,54,62,88,5,4,3,2,1,0,99}, //6 272 {15,23,31,39,47,55,63,88,6,5,4,3,2,1,0,99}, //7 273 {9,10,11,12,13,14,15,88,16,24,32,40,48,56,88,0,99}, //8 274 {10,11,12,13,14,15,88,17,25,33,41,49,57,88,8,88,1,99}, //9 275 {11,12,13,14,15,88,18,26,34,42,50,58,88,9,8,88,2,99}, //10 276 {12,13,14,15,88,19,27,35,43,51,59,88,10,9,8,88,3,99}, //11 277 {13,14,15,88,20,28,36,44,52,60,88,11,10,9,8,88,4,99}, //12 278 {14,15,88,21,29,37,45,53,61,88,12,11,10,9,8,88,5,99}, //13 279 {15,88,22,30,38,46,54,62,88,13,12,11,10,9,8,88,6,99}, //14 280 {23,31,39,47,55,63,88,14,13,12,11,10,9,8,88,7,99}, //15 281 {17,18,19,20,21,22,23,88,24,32,40,48,56,88,8,0,99}, //16 282 {18,19,20,21,22,23,88,25,33,41,49,57,88,16,88,9,1,99}, //17 283 {19,20,21,22,23,88,26,34,42,50,58,88,17,16,88,10,2,99}, //18 284 {20,21,22,23,88,27,35,43,51,59,88,18,17,16,88,11,3,99}, //19 285 {21,22,23,88,28,36,44,52,60,88,19,18,17,16,88,12,4,99}, //20 286 {22,23,88,29,37,45,53,61,88,20,19,18,17,16,88,13,5,99}, //21 287 {23,88,30,38,46,54,62,88,21,20,19,18,17,16,88,14,6,99}, //22 288 {31,39,47,55,63,88,22,21,20,19,18,17,16,88,15,7,99}, //23 289 {25,26,27,28,29,30,31,88,32,40,48,56,88,16,8,0,99}, //24 290 {26,27,28,29,30,31,88,33,41,49,57,88,24,88,17,9,1,99}, //25 291 {27,28,29,30,31,88,34,42,50,58,88,25,24,88,18,10,2,99}, //26 292 {28,29,30,31,88,35,43,51,59,88,26,25,24,88,19,11,3,99}, //27 293 {29,30,31,88,36,44,52,60,88,27,26,25,24,88,20,12,4,99}, //28 294 {30,31,88,37,45,53,61,88,28,27,26,25,24,88,21,13,5,99}, //29 295 {31,88,38,46,54,62,88,29,28,27,26,25,24,88,22,14,6,99}, //30 296 {39,47,55,63,88,30,29,28,27,26,25,24,88,23,15,7,99}, //31 297 {33,34,35,36,37,38,39,88,40,48,56,88,24,16,8,0,99}, //32 298 {34,35,36,37,38,39,88,41,49,57,88,32,88,25,17,9,1,99}, //33 299 {35,36,37,38,39,88,42,50,58,88,33,32,88,26,18,10,2,99}, //34 300 {36,37,38,39,88,43,51,59,88,34,33,32,88,27,19,11,3,99}, //35 301 {37,38,39,88,44,52,60,88,35,34,33,32,88,28,20,12,4,99}, //36 302 {38,39,88,45,53,61,88,36,35,34,33,32,88,29,21,13,5,99}, //37 303 {39,88,46,54,62,88,37,36,35,34,33,32,88,30,22,14,6,99}, //38 304 {47,55,63,88,38,37,36,35,34,33,32,88,31,23,15,7,99}, //39 305 {41,42,43,44,45,46,47,88,48,56,88,32,24,16,8,0,99}, //40 306 {42,43,44,45,46,47,88,49,57,88,40,88,33,25,17,9,1,99}, //41 307 {43,44,45,46,47,88,50,58,88,41,40,88,34,26,18,10,2,99}, //42 308 {44,45,46,47,88,51,59,88,42,41,40,88,35,27,19,11,3,99}, //43 309 {45,46,47,88,52,60,88,43,42,41,40,88,36,28,20,12,4,99}, //44 310 {46,47,88,53,61,88,44,43,42,41,40,88,37,29,21,13,5,99}, //45 311 {47,88,54,62,88,45,44,43,42,41,40,88,38,30,22,14,6,99}, //46 312 {55,63,88,46,45,44,43,42,41,40,88,39,31,23,15,7,99}, //47 313 {49,50,51,52,53,54,55,88,56,88,40,32,24,16,8,0,99}, //48 314 {50,51,52,53,54,55,88,57,88,48,88,41,33,25,17,9,1,99}, //49 315 {51,52,53,54,55,88,58,88,49,48,88,42,34,26,18,10,2,99}, //50 316 {52,53,54,55,88,59,88,50,49,48,88,43,35,27,19,11,3,99}, //51 317 {53,54,55,88,60,88,51,50,49,48,88,44,36,28,20,12,4,99}, //52 318 {54,55,88,61,88,52,51,50,49,48,88,45,37,29,21,13,5,99}, //53 319 {55,88,62,88,53,52,51,50,49,48,88,46,38,30,22,14,6,99}, //54 320 {63,88,54,53,52,51,50,49,48,88,47,39,31,23,15,7,99}, //55 321 {57,58,59,60,61,62,63,88,48,40,32,24,16,8,0,99}, //56 322 {58,59,60,61,62,63,88,56,88,49,41,33,25,17,9,1,99}, //57 323 {59,60,61,62,63,88,57,56,88,50,42,34,26,18,10,2,99}, //58 324 {60,61,62,63,88,58,57,56,88,51,43,35,27,19,11,3,99}, //59 325 {61,62,63,88,59,58,57,56,88,52,44,36,28,20,12,4,99}, //60 326 {62,63,88,60,59,58,57,56,88,53,45,37,29,21,13,5,99}, //61 327 {63,88,61,60,59,58,57,56,88,54,46,38,30,22,14,6,99}, //62 328 {62,61,60,59,58,57,56,88,55,47,39,31,23,15,7,99} //63 329}; 330 331const byte knight_step[64][9] PROGMEM={ 332 {10,17,99}, //0 333 {11,18,16,99}, //1 334 {12,19,17,8,99}, //2 335 {13,20,18,9,99}, //3 336 {14,21,19,10,99}, //4 337 {15,22,20,11,99}, //5 338 {23,21,12,99}, //6 339 {22,13,99}, //7 340 {2,18,25,99}, //8 341 {3,19,26,24,99}, //9 342 {4,20,27,25,16,0,99}, //10 343 {5,21,28,26,17,1,99}, //11 344 {6,22,29,27,18,2,99}, //12 345 {7,23,30,28,19,3,99}, //13 346 {31,29,20,4,99}, //14 347 {30,21,5,99}, //15 348 {1,10,26,33,99}, //16 349 {2,11,27,34,32,0,99}, //17 350 {3,12,28,35,33,24,8,1,99}, //18 351 {4,13,29,36,34,25,9,2,99}, //19 352 {5,14,30,37,35,26,10,3,99}, //20 353 {6,15,31,38,36,27,11,4,99}, //21 354 {7,39,37,28,12,5,99}, //22 355 {38,29,13,6,99}, //23 356 {9,18,34,41,99}, //24 357 {10,19,35,42,40,8,99}, //25 358 {11,20,36,43,41,32,16,9,99}, //26 359 {12,21,37,44,42,33,17,10,99}, //27 360 {13,22,38,45,43,34,18,11,99}, //28 361 {14,23,39,46,44,35,19,12,99}, //29 362 {15,47,45,36,20,13,99}, //30 363 {46,37,21,14,99}, //31 364 {17,26,42,49,99}, //32 365 {18,27,43,50,48,16,99}, //33 366 {19,28,44,51,49,40,24,17,99}, //34 367 {20,29,45,52,50,41,25,18,99}, //35 368 {21,30,46,53,51,42,26,19,99}, //36 369 {22,31,47,54,52,43,27,20,99}, //37 370 {23,55,53,44,28,21,99}, //38 371 {54,45,29,22,99}, //39 372 {25,34,50,57,99}, //40 373 {26,35,51,58,56,24,99}, //41 374 {27,36,52,59,57,48,32,25,99}, //42 375 {28,37,53,60,58,49,33,26,99}, //43 376 {29,38,54,61,59,50,34,27,99}, //44 377 {30,39,55,62,60,51,35,28,99}, //45 378 {31,63,61,52,36,29,99}, //46 379 {62,53,37,30,99}, //47 380 {33,42,58,99}, //48 381 {34,43,59,32,99}, //49 382 {35,44,60,56,40,33,99}, //50 383 {36,45,61,57,41,34,99}, //51 384 {37,46,62,58,42,35,99}, //52 385 {38,47,63,59,43,36,99}, //53 386 {39,60,44,37,99}, //54 387 {61,45,38,99}, //55 388 {41,50,99}, //56 389 {40,42,51,99}, //57 390 {43,52,48,41,99}, //58 391 {44,53,49,42,99}, //59 392 {45,54,50,43,99}, //60 393 {46,55,51,44,99}, //61 394 {47,52,45,99}, //62 395 {53,46,99} //63 +++++ 396}; 397 398const byte king_step[64][9] PROGMEM={ 399 {1,9,8,99}, //0 400 {2,10,9,8,0,99}, //1 401 {3,11,10,9,1,99}, //2 402 {4,12,11,10,2,99}, //3 403 {5,13,12,11,3,99}, //4 404 {6,14,13,12,4,99}, //5 405 {7,15,14,13,5,99}, //6 406 {15,14,6,99}, //7 407 {1,9,17,16,0,99}, //8 408 {2,10,18,17,16,8,0,1,99}, //9 409 {3,11,19,18,17,9,1,2,99}, //10 410 {4,12,20,19,18,10,2,3,99}, //11 411 {5,13,21,20,19,11,3,4,99}, //12 412 {6,14,22,21,20,12,4,5,99}, //13 413 {7,15,23,22,21,13,5,6,99}, //14 414 {23,22,14,6,7,99}, //15 415 {9,17,25,24,8,99}, //16 416 {10,18,26,25,24,16,8,9,99}, //17 417 {11,19,27,26,25,17,9,10,99}, //18 418 {12,20,28,27,26,18,10,11,99}, //19 419 {13,21,29,28,27,19,11,12,99}, //20 420 {14,22,30,29,28,20,12,13,99}, //21 421 {15,23,31,30,29,21,13,14,99}, //22 422 {31,30,22,14,15,99}, //23 423 {17,25,33,32,16,99 }, //24 424 {18,26,34,33,32,24,16,17,99}, //25 425 {19,27,35,34,33,25,17,18,99}, //26 426 {20,28,36,35,34,26,18,19,99}, //27 427 {21,29,37,36,35,27,19,20,99}, //28 428 {22,30,38,37,36,28,20,21,99}, //29 429 {23,31,39,38,37,29,21,22,99}, //30 430 {39,38,30,22,23,99}, //31 431 {25,33,41,40,24,99}, //32 432 {26,34,42,41,40,32,24,25,99}, //33 433 {27,35,43,42,41,33,25,26,99}, //34 434 {28,36,44,43,42,34,26,27,99}, //35 435 {29,37,45,44,43,35,27,28,99}, //36 436 {30,38,46,45,44,36,28,29,99}, //37 437 {31,39,47,46,45,37,29,30,99}, //38 438 {47,46,38,30,31,99}, //39 439 {33,41,49,48,32,99}, //40 440 {34,42,50,49,48,40,32,33,99}, //41 441 {35,43,51,50,49,41,33,34,99}, //42 442 {36,44,52,51,50,42,34,35,99}, //43 443 {37,45,53,52,51,43,35,36,99}, //44 444 {38,46,54,53,52,44,36,37,99}, //45 445 {39,47,55,54,53,45,37,38,99}, //46 446 {55,54,46,38,39,99}, //47 447 {41,49,57,56,40,99}, //48 448 {42,50,58,57,56,48,40,41,99}, //49 449 {43,51,59,58,57,49,41,42,99}, //50 450 {44,52,60,59,58,50,42,43,99}, //51 451 {45,53,61,60,59,51,43,44,99}, //52 452 {46,54,62,61,60,52,44,45,99}, //53 453 {47,55,63,62,61,53,45,46,99}, //54 454 {63,62,54,46,47,99}, //55 455 {49,57,48,99}, //56 456 {50,58,56,48,49,99}, //57 457 {51,59,57,49,50,99}, //58 458 {52,60,58,50,51,99}, //59 459 {53,61,59,51,52,99}, //60 460 {54,62,60,52,53,99}, //61 461 {55,63,61,53,54,99}, //62 462 {62,54,55,99} //63 +++++ 463}; 464
wac.h
h
1const char wac1[] PROGMEM= "2rr3k/pp3pp1/1nnqbN1p/3pN3/2pP4/2P3Q1/PPB4P/R4RK1 2 w - - bm Qg6; id ""WAC.001""; d5+m2"; 3const char wac2[] PROGMEM="8/7p/5k2/5p2/p1p2P2/Pr1pPK2/1P1R3P/8 4 b - - bm Rxb2; id ""WAC.002""; d18+4"; 5const char wac3[] PROGMEM="5rk1/1ppb3p/p1pb4/6q1/3P1p1r/2P1R2P/PP1BQ1P1/5RKN 6 w - - bm Rg3; id ""WAC.003""; d5+3"; 7const char wac4[] PROGMEM="r1bq2rk/pp3pbp/2p1p1pQ/7P/3P4/2PB1N2/PP3PPR/2KR4 8 w - - bm Qxh7+; id ""WAC.004""; d5+m2"; 9const char wac5[] PROGMEM="5k2/6pp/p1qN4/1p1p4/3P4/2PKP2Q/PP3r2/3R4 10 b - - bm Qc4+; id ""WAC.005""; d5+m2"; 11const char wac6[] PROGMEM="7k/p7/1R5K/6r1/6p1/6P1/8/8 12 w - - bm Rb7; id ""WAC.006""; d5+7"; 13const char wac7[] PROGMEM="rnbqkb1r/pppp1ppp/8/4P3/6n1/7P/PPPNPPP1/R1BQKBNR 14 b KQkq - bm Ne3; id ""WAC.007""; d5+3"; 15const char wac8[] PROGMEM="r4q1k/p2bR1rp/2p2Q1N/5p2/5p2/2P5/PP3PPP/R5K1 16 w - - bm Rf7; id ""WAC.008""; d5+7 d11+m8"; 17const char wac9[] PROGMEM="3q1rk1/p4pp1/2pb3p/3p4/6Pr/1PNQ4/P1PB1PP1/4RRK1 18 b - - bm Bh2+; id ""WAC.009""; d5+m5"; 19const char wac10[] PROGMEM="2br2k1/2q3rn/p2NppQ1/2p1P3/Pp5R/4P3/1P3PPP/3R2K1 20 w - - bm Rxh7; id ""WAC.010""; d5+4"; 21const char wac11[] PROGMEM="r1b1kb1r/3q1ppp/pBp1pn2/8/Np3P2/5B2/PPP3PP/R2Q1RK1 22 w kq - bm Bxc6; id ""WAC.011""; d5+3"; 23const char wac12[] PROGMEM="4k1r1/2p3r1/1pR1p3/3pP2p/3P2qP/P4N2/1PQ4P/5R1K 24 b - - bm Qxf3+; id ""WAC.012""; d5+m2"; 25const char wac13[] PROGMEM="5rk1/pp4p1/2n1p2p/2Npq3/2p5/6P1/P3P1BP/R4Q1K 26 w - - bm Qxf8+; id ""WAC.013""; d5+1.5"; 27const char wac14[] PROGMEM="r2rb1k1/pp1q1p1p/2n1p1p1/2bp4/5P2/PP1BPR1Q/1BPN2PP/R5K1 28 w - - bm Qxh7+; id ""WAC.014""; d5+m4"; 29const char wac15[] PROGMEM="1R6/1brk2p1/4p2p/p1P1Pp2/P7/6P1/1P4P1/2R3K1 30 w - - bm Rxb7; id ""WAC.015""; d5+7"; 31const char wac16[] PROGMEM="r4rk1/ppp2ppp/2n5/2bqp3/8/P2PB3/1PP1NPPP/R2Q1RK1 32 w - - bm Nc3; id ""WAC.016""; d5+2"; 33const char wac17[] PROGMEM="1k5r/pppbn1pp/4q1r1/1P3p2/2NPp3/1QP5/P4PPP/R1B1R1K1 34 w - - bm Ne5; id ""WAC.017""; d5+1"; 35const char wac18[] PROGMEM="R7/P4k2/8/8/8/8/r7/6K1 36 w - - bm Rh8; id ""WAC.018""; d6+6"; 37const char wac19[] PROGMEM="r1b2rk1/ppbn1ppp/4p3/1QP4q/3P4/N4N2/5PPP/R1B2RK1 38 w - - bm c6; id ""WAC.019""; d6+0.7"; 39const char wac20[] PROGMEM="r2qkb1r/1ppb1ppp/p7/4p3/P1Q1P3/2P5/5PPP/R1B2KNR 40 b kq - bm Bb5; id ""WAC.020""; d6+7"; 41const char wac21[] PROGMEM="5rk1/1b3p1p/pp3p2/3n1N2/1P6/P1qB1PP1/3Q3P/4R1K1 42 w - - bm Qh6; id ""WAC.021""; d5+6"; 43const char wac22[] PROGMEM="r1bqk2r/ppp1nppp/4p3/n5N1/2BPp3/P1P5/2P2PPP/R1BQK2R 44 w KQkq - bm Ba2 Nxf7; id ""WAC.022""; Nxf7 d5+0.5"; 45const char wac23[] PROGMEM="r3nrk1/2p2p1p/p1p1b1p1/2NpPq2/3R4/P1N1Q3/1PP2PPP/4R1K1 46 w - - bm g4; id ""WAC.023""; d5+4"; 47const char wac24[] PROGMEM="6k1/1b1nqpbp/pp4p1/5P2/1PN5/4Q3/P5PP/1B2B1K1 48 b - - bm Bd4; id ""WAC.024""; d5+7"; 49const char wac25[] PROGMEM="3R1rk1/8/5Qpp/2p5/2P1p1q1/P3P3/1P2PK2/8 50 b - - bm Qh4+; id ""WAC.025""; d5+12"; 51const char wac26[] PROGMEM="3r2k1/1p1b1pp1/pq5p/8/3NR3/2PQ3P/PP3PP1/6K1 52 b - - bm Bf5; id ""WAC.026""; d5+1.2"; 53const char wac27[] PROGMEM="7k/pp4np/2p3p1/3pN1q1/3P4/Q7/1r3rPP/2R2RK1 54 w - - bm Qf8+; id ""WAC.027""; d5+m2"; 55const char wac28[] PROGMEM="1r1r2k1/4pp1p/2p1b1p1/p3R3/RqBP4/4P3/1PQ2PPP/6K1 56 b - - bm Qe1+; id ""WAC.028""; d5+3"; 57const char wac29[] PROGMEM="r2q2k1/pp1rbppp/4pn2/2P5/1P3B2/6P1/P3QPBP/1R3RK1 58 w - - bm c6; id ""WAC.029""; d5+1"; 59const char wac30[] PROGMEM="1r3r2/4q1kp/b1pp2p1/5p2/pPn1N3/6P1/P3PPBP/2QRR1K1 60 w - - bm Nxd6; id ""WAC.030""; d7+0.7"; 61const char wac31[] PROGMEM="rb3qk1/pQ3ppp/4p3/3P4/8/1P3N2/1P3PPP/3R2K1 62 w - - bm Qxa8 d6 dxe6 g3; id ""WAC.031""; d6 d5+3 g3 d10+3.3"; 63const char 64 wac32[] PROGMEM="6k1/p4p1p/1p3np1/2q5/4p3/4P1N1/PP3PPP/3Q2K1 w - - bm Qd8+; id 65 ""WAC.032""; d5+1.7"; 66const char wac33[] PROGMEM="8/p1q2pkp/2Pr2p1/8/P3Q3/6P1/5P1P/2R3K1 67 w - - bm Qe5+ Qf4; id ""WAC.033""; d6+5"; 68const char wac34[] PROGMEM="7k/1b1r2p1/p6p/1p2qN2/3bP3/3Q4/P5PP/1B1R3K 69 b - - bm Bg1; id ""WAC.034""; d5+2.7"; 70const char wac35[] PROGMEM="r3r2k/2R3pp/pp1q1p2/8/3P3R/7P/PP3PP1/3Q2K1 71 w - - bm Rxh7+; id ""WAC.035""; d5+m4"; 72const char wac36[] PROGMEM="3r4/2p1rk2/1pQq1pp1/7p/1P1P4/P4P2/6PP/R1R3K1 73 b - - bm Re1+; id ""WAC.036""; d5+4"; 74const char wac37[] PROGMEM="2r5/2rk2pp/1pn1pb2/pN1p4/P2P4/1N2B3/nPR1KPPP/3R4 75 b - - bm Nxd4+; id ""WAC.037""; d5+1"; 76const char wac38[] PROGMEM="4k3/p4prp/1p6/2b5/8/2Q3P1/P2R1PKP/4q3 77 w - - bm Qd3 Rd8+; id ""WAC.038""; Rd8+ 5+1.5 Qd3 13+1.8"; 78const char wac39[] 79 PROGMEM="r1br2k1/pp2bppp/2nppn2/8/2P1PB2/2N2P2/PqN1B1PP/R2Q1R1K w - - bm Na4; id 80 ""WAC.039""; d5+2.3"; 81const char wac40[] PROGMEM="3r1r1k/1p4pp/p4p2/8/1PQR4/6Pq/P3PP2/2R3K1 82 b - - bm Rc8; id ""WAC.040""; d5+3.8"; 83const char wac41[] PROGMEM="1k6/5RP1/1P6/1K6/6r1/8/8/8 84 w - - bm Ka5 Kc5 b7; id ""WAC.041""; Ka5 d6+16"; 85const char wac42[] PROGMEM="r1b1r1k1/pp1n1pbp/1qp3p1/3p4/1B1P4/Q3PN2/PP2BPPP/R4RK1 86 w - - bm Ba5; id ""WAC.042""; d5+3"; 87const char wac43[] PROGMEM="r2q3k/p2P3p/1p3p2/3QP1r1/8/B7/P5PP/2R3K1 88 w - - bm Be7 Qxa8; id ""WAC.043""; Be7 d6+12"; 89const char wac44[] PROGMEM="3rb1k1/pq3pbp/4n1p1/3p4/2N5/2P2QB1/PP3PPP/1B1R2K1 90 b - - bm dxc4; id ""WAC.044""; d6+2"; 91const char wac45[] PROGMEM="7k/2p1b1pp/8/1p2P3/1P3r2/2P3Q1/1P5P/R4qBK 92 b - - bm Qxa1; id ""WAC.045""; d6+5"; 93const char wac46[] PROGMEM="r1bqr1k1/pp1nb1p1/4p2p/3p1p2/3P4/P1N1PNP1/1PQ2PP1/3RKB1R 94 w K - bm Nb5; id ""WAC.046""; d5+0.5"; 95const char wac47[] PROGMEM="r1b2rk1/pp2bppp/2n1pn2/q5B1/2BP4/2N2N2/PP2QPPP/2R2RK1 96 b - - bm Nxd4; id ""WAC.047""; d5+0.3"; 97const char wac48[] PROGMEM="1rbq1rk1/p1p1bppp/2p2n2/8/Q1BP4/2N5/PP3PPP/R1B2RK1 98 b - - bm Rb4; id ""WAC.048""; d5+1.7"; 99const char wac49[] PROGMEM="2b3k1/4rrpp/p2p4/2pP2RQ/1pP1Pp1N/1P3P1P/1q6/6RK 100 w - - bm Qxh7+; id ""WAC.049""; d7+m6"; 101const char wac50[] PROGMEM="k4r2/1R4pb/1pQp1n1p/3P4/5p1P/3P2P1/r1q1R2K/8 102 w - - bm Rxb6+; id ""WAC.050""; d5+m3"; 103const char wac51[] PROGMEM="r1bq1r2/pp4k1/4p2p/3pPp1Q/3N1R1P/2PB4/6P1/6K1 104 w - - bm Rg4+; id ""WAC.051""; d5+9 d11+m8"; 105const char wac52[] PROGMEM="r1k5/1p3q2/1Qpb4/3N1p2/5Pp1/3P2Pp/PPPK3P/4R3 106 w - - bm Re7 c4; id ""WAC.052""; Re7 d5+4"; 107const char wac53[] PROGMEM="6k1/6p1/p7/3Pn3/5p2/4rBqP/P4RP1/5QK1 108 b - - bm Re1; id ""WAC.053""; d5+4"; 109const char wac54[] PROGMEM="r3kr2/1pp4p/1p1p4/7q/4P1n1/2PP2Q1/PP4P1/R1BB2K1 110 b q - bm Qh1+; id ""WAC.054"";"; 111const char wac55[] PROGMEM="r3r1k1/pp1q1pp1/4b1p1/3p2B1/3Q1R2/8/PPP3PP/4R1K1 112 w - - bm Qxg7+; id ""WAC.055""; d8+m4"; 113const char wac56[] PROGMEM="r1bqk2r/pppp1ppp/5n2/2b1n3/4P3/1BP3Q1/PP3PPP/RNB1K1NR 114 b KQkq - bm Bxf2+; id ""WAC.056""; d5+4"; 115const char wac57[] PROGMEM="r3q1kr/ppp5/3p2pQ/8/3PP1b1/5R2/PPP3P1/5RK1 116 w - - bm Rf8+; id ""WAC.057""; d5+m3"; 117const char wac58[] PROGMEM="8/8/2R5/1p2qp1k/1P2r3/2PQ2P1/5K2/8 118 w - - bm Qd1+; id ""WAC.058""; d5+7"; 119const char wac59[] PROGMEM="r1b2rk1/2p1qnbp/p1pp2p1/5p2/2PQP3/1PN2N1P/PB3PP1/3R1RK1 120 w - - bm Nd5; id ""WAC.059""; d5+4"; 121const char wac60[] PROGMEM="rn1qr1k1/1p2np2/2p3p1/8/1pPb4/7Q/PB1P1PP1/2KR1B1R 122 w - - bm Qh8+; id ""WAC.060""; d5+m2"; 123const char wac61[] PROGMEM="3qrbk1/ppp1r2n/3pP2p/3P4/2P4P/1P3Q2/PB6/R4R1K 124 w - - bm Qf7+; id ""WAC.061""; d5+m2"; 125const char wac62[] PROGMEM="6r1/3Pn1qk/p1p1P1rp/2Q2p2/2P5/1P4P1/P3R2P/5RK1 126 b - - bm Rxg3+; id ""WAC.062""; d6+0"; 127const char wac63[] PROGMEM="r1brnbk1/ppq2pp1/4p2p/4N3/3P4/P1PB1Q2/3B1PPP/R3R1K1 128 w - - bm Nxf7; id ""WAC.063""; d5+2"; 129const char wac64[] PROGMEM="8/6pp/3q1p2/3n1k2/1P6/3NQ2P/5PP1/6K1 130 w - - bm g4+; id ""WAC.064""; d5+m2"; 131const char wac65[] PROGMEM="1r1r1qk1/p2n1p1p/bp1Pn1pQ/2pNp3/2P2P1N/1P5B/P6P/3R1RK1 132 w - - bm Ne7+; id ""WAC.065""; d5+9"; 133const char wac66[] PROGMEM="1k1r2r1/ppq5/1bp4p/3pQ3/8/2P2N2/PP4P1/R4R1K 134 b - - bm Qxe5; id ""WAC.066""; d5+4"; 135const char wac67[] PROGMEM="3r2k1/p2q4/1p4p1/3rRp1p/5P1P/6PK/P3R3/3Q4 136 w - - bm Rxd5; id ""WAC.067""; d5+4"; 137const char wac68[] PROGMEM="6k1/5ppp/1q6/2b5/8/2R1pPP1/1P2Q2P/7K 138 w - - bm Qxe3; id ""WAC.068""; d5+6"; 139const char wac69[] PROGMEM="2k5/pppr4/4R3/4Q3/2pp2q1/8/PPP2PPP/6K1 140 w - - bm f3 h3; id ""WAC.069""; f3 d7+6"; 141const char wac70[] PROGMEM="2kr3r/pppq1ppp/3p1n2/bQ2p3/1n1PP3/1PN1BN1P/1PP2PP1/2KR3R 142 b - - bm Na2+; id ""WAC.070""; d5+4"; 143const char wac71[] PROGMEM="2kr3r/pp1q1ppp/5n2/1Nb5/2Pp1B2/7Q/P4PPP/1R3RK1 144 w - - bm Nxa7+; id ""WAC.071""; d8+3"; 145const char wac72[] PROGMEM="r3r1k1/pp1n1ppp/2p5/4Pb2/2B2P2/B1P5/P5PP/R2R2K1 146 w - - bm e6; id ""WAC.072""; d5+2"; 147const char wac73[] PROGMEM="r1q3rk/1ppbb1p1/4Np1p/p3pP2/P3P3/2N4R/1PP1Q1PP/3R2K1 148 w - - bm Qd2; id ""WAC.073""; d5+3.5"; 149const char wac74[] PROGMEM="5r1k/pp4pp/2p5/2b1P3/4Pq2/1PB1p3/P3Q1PP/3N2K1 150 b - - bm Qf1+; id ""WAC.074""; d5+7"; 151const char wac75[] PROGMEM="r3r1k1/pppq1ppp/8/8/1Q4n1/7P/PPP2PP1/RNB1R1K1 152 b - - bm Qd6; id ""WAC.075""; d5+4"; 153const char wac76[] PROGMEM="r1b1qrk1/2p2ppp/pb1pnn2/1p2pNB1/3PP3/1BP5/PP2QPPP/RN1R2K1 154 w - - bm Bxf6; id ""WAC.076""; d5+2"; 155const char wac77[] PROGMEM="3r2k1/ppp2ppp/6q1/b4n2/3nQB2/2p5/P4PPP/RN3RK1 156 b - - bm Ng3; id ""WAC.077""; d5+8"; 157const char wac78[] PROGMEM="r2q3r/ppp2k2/4nbp1/5Q1p/2P1NB2/8/PP3P1P/3RR1K1 158 w - - bm Ng5+; id ""WAC.078""; d5+4.5"; 159const char wac79[] PROGMEM="r3k2r/pbp2pp1/3b1n2/1p6/3P3p/1B2N1Pq/PP1PQP1P/R1B2RK1 160 b kq - bm Qxh2+; id ""WAC.079""; d5+m3"; 161const char wac80[] PROGMEM="r4rk1/p1B1bpp1/1p2pn1p/8/2PP4/3B1P2/qP2QP1P/3R1RK1 162 w - - bm Ra1; id ""WAC.080""; d9+3"; 163const char wac81[] PROGMEM="r4rk1/1bR1bppp/4pn2/1p2N3/1P6/P3P3/4BPPP/3R2K1 164 b - - bm Bd6; id ""WAC.081""; d5+0.5"; 165const char wac82[] PROGMEM="3rr1k1/pp3pp1/4b3/8/2P1B2R/6QP/P3q1P1/5R1K 166 w - - bm Bh7+; id ""WAC.082""; d5+8"; 167const char wac83[] PROGMEM="3rr1k1/ppqbRppp/2p5/8/3Q1n2/2P3N1/PPB2PPP/3R2K1 168 w - - bm Qxd7; id ""WAC.083""; d5+3.5"; 169const char wac84[] PROGMEM="r2q1r1k/2p1b1pp/p1n5/1p1Q1bN1/4n3/1BP1B3/PP3PPP/R4RK1 170 w - - bm Qg8+; id ""WAC.084""; d5+m2"; 171const char wac85[] PROGMEM="kr2R3/p4r2/2pq4/2N2p1p/3P2p1/Q5P1/5P1P/5BK1 172 w - - bm Na6; id ""WAC.085""; d5+6 d7+10"; 173const char wac86[] PROGMEM="8/p7/1ppk1n2/5ppp/P1PP4/2P1K1P1/5N1P/8 174 b - - bm Ng4+; id ""WAC.086""; d5+0.5"; 175const char wac87[] PROGMEM="8/p3k1p1/4r3/2ppNpp1/PP1P4/2P3KP/5P2/8 176 b - - bm Rxe5; id ""WAC.087""; d8+6"; 177const char wac88[] PROGMEM="r6k/p1Q4p/2p1b1rq/4p3/B3P3/4P3/PPP3P1/4RRK1 178 b - - bm Rxg2+; id ""WAC.088""; d5+m5"; 179const char wac89[] PROGMEM="1r3b1k/p4rpp/4pp2/3q4/2ppbPPQ/6RK/PP5P/2B1NR2 180 b - - bm g5; id ""WAC.089""; d5+7"; 181const char wac90[] PROGMEM="3qrrk1/1pp2pp1/1p2bn1p/5N2/2P5/P1P3B1/1P4PP/2Q1RRK1 182 w - - bm Nxg7; id ""WAC.090""; d5+2.5"; 183const char wac91[] PROGMEM="2qr2k1/4b1p1/2p2p1p/1pP1p3/p2nP3/PbQNB1PP/1P3PK1/4RB2 184 b - - bm Be6; id ""WAC.091""; d6+1"; 185const char wac92[] PROGMEM="r4rk1/1p2ppbp/p2pbnp1/q7/3BPPP1/2N2B2/PPP4P/R2Q1RK1 186 b - - bm Bxg4; id ""WAC.092""; d9+0.7"; 187const char wac93[] PROGMEM="r1b1k1nr/pp3pQp/4pq2/3pn3/8/P1P5/2P2PPP/R1B1KBNR 188 w KQkq - bm Bh6; id ""WAC.093""; d5+1"; 189const char wac94[] PROGMEM="8/k7/p7/3Qp2P/n1P5/3KP3/1q6/8 190 b - - bm e4+; id ""WAC.094""; d5+9"; 191const char wac95[] PROGMEM="2r5/1r6/4pNpk/3pP1qp/8/2P1QP2/5PK1/R7 192 w - - bm Ng4+; id ""WAC.095""; d5+9"; 193const char wac96[] PROGMEM="r1b4k/ppp2Bb1/6Pp/3pP3/1qnP1p1Q/8/PPP3P1/1K1R3R 194 w - - bm Qd8+ b3; id ""WAC.096""; d5+2 d14+m9"; 195const char wac97[] PROGMEM="6k1/5p2/p5np/4B3/3P4/1PP1q3/P3r1QP/6RK 196 w - - bm Qa8+; id ""WAC.097"";"; 197const char wac98[] PROGMEM="1r3rk1/5pb1/p2p2p1/Q1n1q2p/1NP1P3/3p1P1B/PP1R3P/1K2R3 198 b - - bm Nxe4; id ""WAC.098""; d5+5"; 199const char wac99[] PROGMEM="r1bq1r1k/1pp1Np1p/p2p2pQ/4R3/n7/8/PPPP1PPP/R1B3K1 200 w - - bm Rh5; id ""WAC.099""; d5+m2"; 201const char wac100[] PROGMEM="8/k1b5/P4p2/1Pp2p1p/K1P2P1P/8/3B4/8 202 w - - bm Be3 b6+; id ""WAC.100""; Be3 d14+2.6 b6+ d17+4"; 203const char wac101[] 204 PROGMEM="5rk1/p5pp/8/8/2Pbp3/1P4P1/7P/4RN1K b - - bm Bc3; id ""WAC.101""; d10+1.5"; 205const 206 char wac102[] PROGMEM="2Q2n2/2R4p/1p1qpp1k/8/3P3P/3B2P1/5PK1/r7 w - - bm Qxf8+; 207 id ""WAC.102""; d5+m3"; 208const char wac103[] PROGMEM="6k1/2pb1r1p/3p1PpQ/p1nPp3/1q2P3/2N2P2/PrB5/2K3RR 209 w - - bm Qxg6+; id ""WAC.103""; d5+m4"; 210const char wac104[] PROGMEM="b4r1k/pq2rp2/1p1bpn1p/3PN2n/2P2P2/P2B3K/1B2Q2N/3R2R1 211 w - - bm Qxh5; id ""WAC.104""; d5+m3"; 212const char wac105[] PROGMEM="r2r2k1/pb3ppp/1p1bp3/7q/3n2nP/PP1B2P1/1B1N1P2/RQ2NRK1 213 b - - bm Bxg3 Qxh4; id ""WAC.105""; Qxh4 d7+m8 d8+m6"; 214const char wac106[] 215 PROGMEM="4rrk1/pppb4/7p/3P2pq/3Qn3/P5P1/1PP4P/R3RNNK b - - bm Nf2+; id ""WAC.106""; 216 d5+9"; 217const char wac107[] PROGMEM="5n2/pRrk2p1/P4p1p/4p3/3N4/5P2/6PP/6K1 w 218 - - bm Nb5; id ""WAC.107""; d5+3"; 219const char wac108[] PROGMEM="r5k1/1q4pp/2p5/p1Q5/2P5/5R2/4RKPP/r7 220 w - - bm Qe5; id ""WAC.108""; d5+3"; 221const char wac109[] PROGMEM="rn2k1nr/pbp2ppp/3q4/1p2N3/2p5/QP6/PB1PPPPP/R3KB1R 222 b KQkq - bm c3; id ""WAC.109""; d7+0.5"; 223const char wac110[] PROGMEM="2kr4/bp3p2/p2p2b1/P7/2q5/1N4B1/1PPQ2P1/2KR4 224 b - - bm Be3; id ""WAC.110""; d5+7"; 225const char wac111[] PROGMEM="6k1/p5p1/5p2/2P2Q2/3pN2p/3PbK1P/7P/6q1 226 b - - bm Qf1+; id ""WAC.111""; d5+10"; 227const char wac112[] PROGMEM="r4kr1/ppp5/4bq1b/7B/2PR1Q1p/2N3P1/PP3P1P/2K1R3 228 w - - bm Rxe6; id ""WAC.112""; d5+2.5"; 229const char wac113[] PROGMEM="rnbqkb1r/1p3ppp/5N2/1p2p1B1/2P5/8/PP2PPPP/R2QKB1R 230 b KQkq - bm Qxf6; id ""WAC.113""; d5+1"; 231const char wac114[] PROGMEM="r1b1rnk1/1p4pp/p1p2p2/3pN2n/3P1PPq/2NBPR1P/PPQ5/2R3K1 232 w - - bm Bxh7+; id ""WAC.114""; d5+2.5"; 233const char wac115[] PROGMEM="4N2k/5rpp/1Q6/p3q3/8/P5P1/1P3P1P/5K2 234 w - - bm Nd6; id ""WAC.115""; d5+2.5"; 235const char wac116[] PROGMEM="r2r2k1/2p2ppp/p7/1p2P1n1/P6q/5P2/1PB1QP1P/R5RK 236 b - - bm Rd2; id ""WAC.116""; d8+2"; 237const char wac117[] PROGMEM="3r1rk1/q4ppp/p1Rnp3/8/1p6/1N3P2/PP3QPP/3R2K1 238 b - - bm Ne4; id ""WAC.117""; d5+6"; 239const char wac118[] PROGMEM="r5k1/pb2rpp1/1p6/2p4q/5R2/2PB2Q1/P1P3PP/5R1K 240 w - - bm Rh4; id ""WAC.118""; d5+4"; 241const char wac119[] PROGMEM="r2qr1k1/p1p2ppp/2p5/2b5/4nPQ1/3B4/PPP3PP/R1B2R1K 242 b - - bm Qxd3; id ""WAC.119""; d5+4"; 243const char wac120[] PROGMEM="r4rk1/1bn2qnp/3p1B1Q/p2P1pP1/1pp5/5N1P/PPB2P2/2KR3R 244 w - - bm Rhg1 g6; id ""WAC.120""; g6 d7+3"; 245const char wac121[] PROGMEM="6k1/5p1p/2bP2pb/4p3/2P5/1p1pNPPP/1P1Q1BK1/1q6 246 b - - bm Bxf3+; id ""WAC.121""; d5+11"; 247const char wac122[] PROGMEM="1k6/ppp4p/1n2pq2/1N2Rb2/2P2Q2/8/P4KPP/3r1B2 248 b - - bm Rxf1+; id ""WAC.122""; d5+12"; 249const char wac123[] PROGMEM="6k1/1b2rp2/1p4p1/3P4/PQ4P1/2N2q2/5P2/3R2K1 250 b - - bm Bxd5 Rc7 Re6; id ""WAC.123""; Rc7 d5+2 Bxd5 d10+4 Re6 d17+6"; 251const 252 char wac124[] PROGMEM="6k1/3r4/2R5/P5P1/1P4p1/8/4rB2/6K1 b - - bm g3; id ""WAC.124""; 253 d5+2"; 254const char wac125[] PROGMEM="r1bqr1k1/pp3ppp/1bp5/3n4/3B4/2N2P1P/PPP1B1P1/R2Q1RK1 255 b - - bm Bxd4+; id ""WAC.125""; d5+3"; 256const char wac126[] PROGMEM="r5r1/pQ5p/1qp2R2/2k1p3/4P3/2PP4/P1P3PP/6K1 257 w - - bm Rxc6+; id ""WAC.126""; d5+4"; 258const char wac127[] PROGMEM="2k4r/1pr1n3/p1p1q2p/5pp1/3P1P2/P1P1P3/1R2Q1PP/1RB3K1 259 w - - bm Rxb7; id ""WAC.127""; d5+3"; 260const char wac128[] PROGMEM="6rk/1pp2Qrp/3p1B2/1pb1p2R/3n1q2/3P4/PPP3PP/R6K 261 w - - bm Qg6; id ""WAC.128""; d5+2"; 262const char wac129[] PROGMEM="3r1r1k/1b2b1p1/1p5p/2p1Pp2/q1B2P2/4P2P/1BR1Q2K/6R1 263 b - - bm Bf3; id ""WAC.129""; d5+1.3"; 264const char wac130[] PROGMEM="6k1/1pp3q1/5r2/1PPp4/3P1pP1/3Qn2P/3B4/4R1K1 265 b - - bm Qh6 Qh8; id ""WAC.130""; Qh6 d5+1"; 266const char wac131[] PROGMEM="2rq1bk1/p4p1p/1p4p1/3b4/3B1Q2/8/P4PpP/3RR1K1 267 w - - bm Re8; id ""WAC.131""; d6+2"; 268const char wac132[] PROGMEM="4r1k1/5bpp/2p5/3pr3/8/1B3pPq/PPR2P2/2R2QK1 269 b - - bm Re1; id ""WAC.132""; d5+m3"; 270const char wac133[] PROGMEM="r1b1k2r/1pp1q2p/p1n3p1/3QPp2/8/1BP3B1/P5PP/3R1RK1 271 w kq - bm Bh4; id ""WAC.133""; d5+3"; 272const char wac134[] PROGMEM="3r2k1/p6p/2Q3p1/4q3/2P1p3/P3Pb2/1P3P1P/2K2BR1 273 b - - bm Rd1+; id ""WAC.134""; d5+m4"; 274const char wac135[] PROGMEM="3r1r1k/N2qn1pp/1p2np2/2p5/2Q1P2N/3P4/PP4PP/3R1RK1 275 b - - bm Nd4; id ""WAC.135""; d5+1.3"; 276const char wac136[] PROGMEM="6kr/1q2r1p1/1p2N1Q1/5p2/1P1p4/6R1/7P/2R3K1 277 w - - bm Rc8+; id ""WAC.136""; Qf6 d6+m6 Rc8+ d8+m3"; 278const char wac137[] 279 PROGMEM="3b1rk1/1bq3pp/5pn1/1p2rN2/2p1p3/2P1B2Q/1PB2PPP/R2R2K1 w - - bm Rd7; id 280 ""WAC.137""; d5+2"; 281const char wac138[] PROGMEM="r1bq3r/ppppR1p1/5n1k/3P4/6pP/3Q4/PP1N1PP1/5K1R 282 w - - bm h5; id ""WAC.138""; d5+m7 d8+m5"; 283const char wac139[] PROGMEM="rnb3kr/ppp2ppp/1b6/3q4/3pN3/Q4N2/PPP2KPP/R1B1R3 284 w - - bm Nf6+; id ""WAC.139""; d5+m4"; 285const char wac140[] PROGMEM="r2b1rk1/pq4p1/4ppQP/3pB1p1/3P4/2R5/PP3PP1/5RK1 286 w - - bm Bc7 Rc7; id ""WAC.140""; Rc7 d5+9"; 287const char wac141[] PROGMEM="4r1k1/p1qr1p2/2pb1Bp1/1p5p/3P1n1R/1B3P2/PP3PK1/2Q4R 288 w - - bm Qxf4; id ""WAC.141""; d10+19 d12+m6"; 289const char wac142[] PROGMEM="r2q3n/ppp2pk1/3p4/5Pr1/2NP1Qp1/2P2pP1/PP3K2/4R2R 290 w - - bm Re8 f6+; id ""WAC.142""; f6+ d5+3"; 291const char wac143[] PROGMEM="5b2/pp2r1pk/2pp1pRp/4rP1N/2P1P3/1P4QP/P3q1P1/5R1K 292 w - - bm Rxh6+; id ""WAC.143""; d5+m3"; 293const char wac144[] PROGMEM="r2q1rk1/pp3ppp/2p2b2/8/B2pPPb1/7P/PPP1N1P1/R2Q1RK1 294 b - - bm d3; id ""WAC.144""; d5+1.6"; 295const char wac145[] PROGMEM="r1bq4/1p4kp/3p1n2/p4pB1/2pQ4/8/1P4PP/4RRK1 296 w - - bm Re8; id ""WAC.145""; d8+15"; 297const char wac146[] PROGMEM="8/8/2Kp4/3P1B2/2P2k2/5p2/8/8 298 w - - bm Bc8 Bd3 Bh3; id ""WAC.146""; Bc8 d5+2"; 299const char wac147[] PROGMEM="r2r2k1/ppqbppbp/2n2np1/2pp4/6P1/1P1PPNNP/PBP2PB1/R2QK2R 300 b KQ - bm Nxg4; id ""WAC.147""; d5+1.7"; 301const char wac148[] PROGMEM="2r1k3/6pr/p1nBP3/1p3p1p/2q5/2P5/P1R4P/K2Q2R1 302 w - - bm Rxg7; id ""WAC.148""; d5+9"; 303const char wac149[] PROGMEM="6k1/6p1/2p4p/4Pp2/4b1qP/2Br4/1P2RQPK/8 304 b - - bm Bxg2; id ""WAC.149""; d5+2"; 305const char wac150[] PROGMEM="r3r1k1/5p2/pQ1b2pB/1p6/4p3/6P1/Pq2BP1P/2R3K1 306 b - - bm Ba3 Be5 Bf8 e3; c0 ""All win but e3 is best.""; id ""WAC.150""; 307 e3 d3+3.5"; 308const char wac151[] PROGMEM="8/3b2kp/4p1p1/pr1n4/N1N4P/1P4P1/1K3P2/3R4 309 w - - bm Nc3; id ""WAC.151""; d5+1"; 310const char wac152[] PROGMEM="1br2rk1/1pqb1ppp/p3pn2/8/1P6/P1N1PN1P/1B3PP1/1QRR2K1 311 w - - bm Ne4; id ""WAC.152""; d5+2"; 312const char wac153[] PROGMEM="2r3k1/q4ppp/p3p3/pnNp4/2rP4/2P2P2/4R1PP/2R1Q1K1 313 b - - bm Nxd4; id ""WAC.153""; d5+2"; 314const char wac154[] PROGMEM="r1b2rk1/2p2ppp/p7/1p6/3P3q/1BP3bP/PP3QP1/RNB1R1K1 315 w - - bm Qxf7+; id ""WAC.154""; d5+m2"; 316const char wac155[] PROGMEM="5bk1/1rQ4p/5pp1/2pP4/3n1PP1/7P/1q3BB1/4R1K1 317 w - - bm d6; id ""WAC.155""; d5+2.5"; 318const char wac156[] PROGMEM="r1b1qN1k/1pp3p1/p2p3n/4p1B1/8/1BP4Q/PP3KPP/8 319 w - - bm Qxh6+; id ""WAC.156""; d5+m2"; 320const char wac157[] PROGMEM="5rk1/p4ppp/2p1b3/3Nq3/4P1n1/1p1B2QP/1PPr2P1/1K2R2R 321 w - - bm Ne7+; id ""WAC.157""; d7+1.5"; 322const char wac158[] PROGMEM="5rk1/n1p1R1bp/p2p4/1qpP1QB1/7P/2P3P1/PP3P2/6K1 323 w - - bm Rxg7+; id ""WAC.158""; d5+m3"; 324const char wac159[] PROGMEM="r1b2r2/5P1p/ppn3pk/2p1p1Nq/1bP1PQ2/3P4/PB4BP/1R3RK1 325 w - - bm Ne6+; id ""WAC.159""; d5+6"; 326const char wac160[] PROGMEM="qn1kr2r/1pRbb3/pP5p/P2pP1pP/3N1pQ1/3B4/3B1PP1/R5K1 327 w - - bm Qxd7+; id ""WAC.160""; d5+m2"; 328const char wac161[] PROGMEM="3r3k/3r1P1p/pp1Nn3/2pp4/7Q/6R1/Pq4PP/5RK1 329 w - - bm Qxd8+; id ""WAC.161""; d5+m4"; 330const char wac162[] PROGMEM="r3kbnr/p4ppp/2p1p3/8/Q1B3b1/2N1B3/PP3PqP/R3K2R 331 w KQkq - bm Bd5; id ""WAC.162""; d5+1.2"; 332const char wac163[] PROGMEM="5rk1/2p4p/2p4r/3P4/4p1b1/1Q2NqPp/PP3P1K/R4R2 333 b - - bm Qg2+; id ""WAC.163""; d12+m11"; 334const char wac164[] PROGMEM="8/6pp/4p3/1p1n4/1NbkN1P1/P4P1P/1PR3K1/r7 335 w - - bm Rxc4+; id ""WAC.164""; d5+3.5"; 336const char wac165[] PROGMEM="1r5k/p1p3pp/8/8/4p3/P1P1R3/1P1Q1qr1/2KR4 337 w - - bm Re2; id ""WAC.165""; d5+3.5"; 338const char wac166[] PROGMEM="r3r1k1/5pp1/p1p4p/2Pp4/8/q1NQP1BP/5PP1/4K2R 339 b K - bm d4; id ""WAC.166""; d5+2"; 340const char wac167[] PROGMEM="7Q/ppp2q2/3p2k1/P2Ppr1N/1PP5/7R/5rP1/6K1 341 b - - bm Rxg2+; id ""WAC.167""; d5+m5"; 342const char wac168[] PROGMEM="r3k2r/pb1q1p2/8/2p1pP2/4p1p1/B1P1Q1P1/P1P3K1/R4R2 343 b kq - bm Qd2+; id ""WAC.168""; d5+17 d9+m11 d11+m8"; 344const char wac169[] 345 PROGMEM="5rk1/1pp3bp/3p2p1/2PPp3/1P2P3/2Q1B3/4q1PP/R5K1 b - - bm Bh6; id ""WAC.169""; 346 d7+4"; 347const char wac170[] PROGMEM="5r1k/6Rp/1p2p3/p2pBp2/1qnP4/4P3/Q4PPP/6K1 348 w - - bm Qxc4; id ""WAC.170""; d5+4"; 349const char wac171[] PROGMEM="2rq4/1b2b1kp/p3p1p1/1p1nNp2/7P/1B2B1Q1/PP3PP1/3R2K1 350 w - - bm Bh6+; id ""WAC.171""; d5+1.8"; 351const char wac172[] PROGMEM="5r1k/p5pp/8/1P1pq3/P1p2nR1/Q7/5BPP/6K1 352 b - - bm Qe1+; id ""WAC.172""; d5+m3"; 353const char wac173[] PROGMEM="2r1b3/1pp1qrk1/p1n1P1p1/7R/2B1p3/4Q1P1/PP3PP1/3R2K1 354 w - - bm Qh6+; id ""WAC.173""; d5+m3"; 355const char wac174[] PROGMEM="2r2rk1/6p1/p3pq1p/1p1b1p2/3P1n2/PP3N2/3N1PPP/1Q2RR1K 356 b - - bm Nxg2; id ""WAC.174""; d5+2"; 357const char wac175[] PROGMEM="r5k1/pppb3p/2np1n2/8/3PqNpP/3Q2P1/PPP5/R4RK1 358 w - - bm Nh5; id ""WAC.175""; d5+1.7"; 359const char wac176[] PROGMEM="r1bq3r/ppp2pk1/3p1pp1/8/2BbPQ2/2NP2P1/PPP4P/R4R1K 360 b - - bm Rxh2+; id ""WAC.176""; d5+2"; 361const char wac177[] PROGMEM="r1b3r1/4qk2/1nn1p1p1/3pPp1P/p4P2/1p3BQN/PKPBN3/3R3R 362 b - - bm Qa3+; id ""WAC.177""; d5+m3"; 363const char wac178[] PROGMEM="3r2k1/p1rn1p1p/1p2pp2/6q1/3PQNP1/5P2/P1P4R/R5K1 364 w - - bm Nxe6; id ""WAC.178""; d6+1"; 365const char wac179[] PROGMEM="r1b2r1k/pp4pp/3p4/3B4/8/1QN3Pn/PP3q1P/R3R2K 366 b - - bm Qg1+; id ""WAC.179""; d5+m3"; 367const char wac180[] PROGMEM="r1q2rk1/p3bppb/3p1n1p/2nPp3/1p2P1P1/6NP/PP2QPB1/R1BNK2R 368 b KQ - bm Nxd5; id ""WAC.180""; d5+1"; 369const char wac181[] PROGMEM="r3k2r/2p2p2/p2p1n2/1p2p3/4P2p/1PPPPp1q/1P5P/R1N2QRK 370 b kq - bm Ng4; id ""WAC.181""; d5+5.5"; 371const char wac182[] PROGMEM="r1b2rk1/ppqn1p1p/2n1p1p1/2b3N1/2N5/PP1BP3/1B3PPP/R2QK2R 372 w KQ - bm Qh5; id ""WAC.182""; d5+m7 d11+m6"; 373const char wac183[] PROGMEM="1r2k1r1/5p2/b3p3/1p2b1B1/3p3P/3B4/PP2KP2/2R3R1 374 w - - bm Bf6; id ""WAC.183""; d5+1.7"; 375const char wac184[] PROGMEM="4kn2/r4p1r/p3bQ2/q1nNP1Np/1p5P/8/PPP3P1/2KR3R 376 w - - bm Qe7+; id ""WAC.184""; d5+m2"; 377const char wac185[] PROGMEM="1r1rb1k1/2p3pp/p2q1p2/3PpP1Q/Pp1bP2N/1B5R/1P4PP/2B4K 378 w - - bm Qxh7+; id ""WAC.185""; d6+4"; 379const char wac186[] PROGMEM="r5r1/p1q2p1k/1p1R2pB/3pP3/6bQ/2p5/P1P1NPPP/6K1 380 w - - bm Bf8+; id ""WAC.186""; d5+m3"; 381const char wac187[] PROGMEM="6k1/5p2/p3p3/1p3qp1/2p1Qn2/2P1R3/PP1r1PPP/4R1K1 382 b - - bm Nh3+; id ""WAC.187""; d5+6"; 383const char wac188[] PROGMEM="3RNbk1/pp3p2/4rQpp/8/1qr5/7P/P4P2/3R2K1 384 w - - bm Qg7+; id ""WAC.188""; d5+m2"; 385const char wac189[] PROGMEM="3r1k2/1ppPR1n1/p2p1rP1/3P3p/4Rp1N/5K2/P1P2P2/8 386 w - - bm Re8+; id ""WAC.189""; d6+7"; 387const char wac190[] PROGMEM="8/p2b2kp/1q1p2p1/1P1Pp3/4P3/3B2P1/P2Q3P/2Nn3K 388 b - - bm Bh3; id ""WAC.190""; d5+6"; 389const char wac191[] PROGMEM="2r1Rn1k/1p1q2pp/p7/5p2/3P4/1B4P1/P1P1QP1P/6K1 390 w - - bm Qc4; id ""WAC.191""; d5+m3"; 391const char wac192[] PROGMEM="r3k3/ppp2Npp/4Bn2/2b5/1n1pp3/N4P2/PPP3qP/R2QKR2 392 b Qq - bm Nd3+; id ""WAC.192""; d5+6"; 393const char wac193[] PROGMEM="5bk1/p4ppp/Qp6/4B3/1P6/Pq2P1P1/2rr1P1P/R4RK1 394 b - - bm Qxe3; id ""WAC.193""; d6+8 d11+m8"; 395const char wac194[] PROGMEM="5rk1/ppq2ppp/2p5/4bN2/4P3/6Q1/PPP2PPP/3R2K1 396 w - - bm Nh6+; id ""WAC.194""; d6+5"; 397const char wac195[] PROGMEM="3r1rk1/1p3p2/p3pnnp/2p3p1/2P2q2/1P5P/PB2QPPN/3RR1K1 398 w - - bm g3; id ""WAC.195""; d5+2"; 399const char wac196[] PROGMEM="rr4k1/p1pq2pp/Q1n1pn2/2bpp3/4P3/2PP1NN1/PP3PPP/R1B1K2R 400 b KQ - bm Nb4; id ""WAC.196""; d8+1"; 401const char wac197[] PROGMEM="7k/1p4p1/7p/3P1n2/4Q3/2P2P2/PP3qRP/7K 402 b - - bm Qf1+; id ""WAC.197""; d5+m3"; 403const char wac198[] PROGMEM="2br2k1/ppp2p1p/4p1p1/4P2q/2P1Bn2/2Q5/PP3P1P/4R1RK 404 b - - bm Rd3; id ""WAC.198""; d5+3.5"; 405const char wac199[] PROGMEM="r1br2k1/pp2nppp/2n5/1B1q4/Q7/4BN2/PP3PPP/2R2RK1 406 w - - bm Bxc6 Rcd1 Rfd1; id ""WAC.199""; Rfd1 d5+3"; 407const char wac200[] 408 PROGMEM="2rqrn1k/pb4pp/1p2pp2/n2P4/2P3N1/P2B2Q1/1B3PPP/2R1R1K1 w - - bm Bxf6; id 409 ""WAC.200""; d5+2.5"; 410const char wac201[] PROGMEM="2b2r1k/4q2p/3p2pQ/2pBp3/8/6P1/1PP2P1P/R5K1 411 w - - bm Ra7; id ""WAC.201""; d5+m6"; 412const char wac202[] PROGMEM="QR2rq1k/2p3p1/3p1pPp/8/4P3/8/P1r3PP/1R4K1 413 b - - bm Rxa2; id ""WAC.202""; d5+0.3"; 414const char wac203[] PROGMEM="r4rk1/5ppp/p3q1n1/2p2NQ1/4n3/P3P3/1B3PPP/1R3RK1 415 w - - bm Qh6; id ""WAC.203""; d5+m3"; 416const char wac204[] PROGMEM="r1b1qrk1/1p3ppp/p1p5/3Nb3/5N2/P7/1P4PQ/K1R1R3 417 w - - bm Rxe5; id ""WAC.204""; d5+0.4"; 418const char wac205[] PROGMEM="r3rnk1/1pq2bb1/p4p2/3p1Pp1/3B2P1/1NP4R/P1PQB3/2K4R 419 w - - bm Qxg5; id ""WAC.205""; d6+3"; 420const char wac206[] PROGMEM="1Qq5/2P1p1kp/3r1pp1/8/8/7P/p4PP1/2R3K1 421 b - - bm Rc6; id ""WAC.206""; d5+1.5"; 422const char wac207[] PROGMEM="r1bq2kr/p1pp1ppp/1pn1p3/4P3/2Pb2Q1/BR6/P4PPP/3K1BNR 423 w - - bm Qxg7+; id ""WAC.207""; d5+2"; 424const char wac208[] PROGMEM="3r1bk1/ppq3pp/2p5/2P2Q1B/8/1P4P1/P6P/5RK1 425 w - - bm Bf7+; id ""WAC.208""; d5+10"; 426const char wac209[] PROGMEM="4kb1r/2q2p2/r2p4/pppBn1B1/P6P/6Q1/1PP5/2KRR3 427 w k - bm Rxe5+; id ""WAC.209""; d6+8"; 428const char wac210[] PROGMEM="3r1rk1/pp1q1ppp/3pn3/2pN4/5PP1/P5PQ/1PP1B3/1K1R4 429 w - - bm Rh1; id ""WAC.210""; d7+3"; 430const char wac211[] PROGMEM="r1bqrk2/pp1n1n1p/3p1p2/P1pP1P1Q/2PpP1NP/6R1/2PB4/4RBK1 431 w - - bm Qxf7+; id ""WAC.211""; d5+m5"; 432const char wac212[] PROGMEM="rn1qr2Q/pbppk1p1/1p2pb2/4N3/3P4/2N5/PPP3PP/R4RK1 433 w - - bm Qxg7+; id ""WAC.212""; d5+m5"; 434const char wac213[] PROGMEM="3r1r1k/1b4pp/ppn1p3/4Pp1R/Pn5P/3P4/4QP2/1qB1NKR1 435 w - - bm Rxh7+ Rxg7+; id ""WAC.213""; d7+0"; 436const char wac214[] PROGMEM="r2r2k1/1p2qpp1/1np1p1p1/p3N3/2PPN3/bP5R/4QPPP/4R1K1 437 w - - bm Ng5; id ""WAC.214""; d5+3"; 438const char wac215[] PROGMEM="3r2k1/pb1q1pp1/1p2pb1p/8/3N4/P2QB3/1P3PPP/1Br1R1K1 439 w - - bm Qh7+; id ""WAC.215""; d5+m4"; 440const char wac216[] PROGMEM="r2qr1k1/1b1nbppp/p3pn2/1p1pN3/3P1B2/2PB1N2/PP2QPPP/R4RK1 441 w - - bm Nxf7 a4; id ""WAC.216""; d5+1.5"; 442const char wac217[] PROGMEM="r3kb1r/1pp3p1/p3bp1p/5q2/3QN3/1P6/PBP3P1/3RR1K1 443 w kq - bm Qd7+; id ""WAC.217""; d7+m5"; 444const char wac218[] PROGMEM="6k1/pp5p/2p3q1/6BP/2nPr1Q1/8/PP3R1K/8 445 w - - bm Bh6; id ""WAC.218""; d7+m6"; 446const char wac219[] PROGMEM="7k/p4q1p/1pb5/2p5/4B2Q/2P1B3/P6P/7K 447 b - - bm Qf1+; id ""WAC.219""; d5+m3"; 448const char wac220[] PROGMEM="3rr1k1/ppp2ppp/8/5Q2/4n3/1B5R/PPP1qPP1/5RK1 449 b - - bm Qxf1+; id ""WAC.220""; d6+6"; 450const char wac221[] PROGMEM="r3k3/P5bp/2N1bp2/4p3/2p5/6NP/1PP2PP1/3R2K1 451 w q - bm Rd8+; id ""WAC.221""; d5+5"; 452const char wac222[] PROGMEM="2r1r2k/1q3ppp/p2Rp3/2p1P3/6QB/p3P3/bP3PPP/3R2K1 453 w - - bm Bf6; id ""WAC.222""; d9+m6"; 454const char wac223[] PROGMEM="r1bqk2r/pp3ppp/5n2/8/1b1npB2/2N5/PP1Q2PP/1K2RBNR 455 w kq - bm Nxe4; id ""WAC.223""; d7+0.7"; 456const char wac224[] PROGMEM="5rk1/p1q3pp/1p1r4/2p1pp1Q/1PPn1P2/3B3P/P2R2P1/3R2K1 457 b - - bm Rh6 e4; id ""WAC.224""; Rh6 d6+3 e4 d9+4"; 458const char wac225[] 459 PROGMEM="4R3/4q1kp/6p1/1Q3b2/1P1b1P2/6KP/8/8 b - - bm Qh4+; id ""WAC.225""; 460 d5+m3"; 461const char wac226[] PROGMEM="2b2rk1/p1p4p/2p1p1p1/br2N1Q1/1p2q3/8/PB3PPP/3R1RK1 462 w - - bm Nf7; id ""WAC.226""; d7+3.5 "; 463const char wac227[] PROGMEM="2k1rb1r/ppp3pp/2np1q2/5b2/2B2P2/2P1BQ2/PP1N1P1P/2KR3R 464 b - - bm d5; id ""WAC.227""; d5+2.5"; 465const char wac228[] PROGMEM="r4rk1/1bq1bp1p/4p1p1/p2p4/3BnP2/1N1B3R/PPP3PP/R2Q2K1 466 w - - bm Bxe4; id ""WAC.228""; d6+1.5"; 467const char wac229[] PROGMEM="8/8/8/1p5r/p1p1k1pN/P2pBpP1/1P1K1P2/8 468 b - - bm Rxh4 b4; id ""WAC.229""; b4 d14+4.5"; 469const char wac230[] PROGMEM="2b5/1r6/2kBp1p1/p2pP1P1/2pP4/1pP3K1/1R3P2/8 470 b - - bm Rb4; id ""WAC.230""; ??? Rh7d5+2.5"; 471const char wac231[] PROGMEM="r4rk1/1b1nqp1p/p5p1/1p2PQ2/2p5/5N2/PP3PPP/R1BR2K1 472 w - - bm Bg5; id ""WAC.231""; d5+0.5"; 473const char wac232[] PROGMEM="1R2rq1k/2p3p1/Q2p1pPp/8/4P3/8/P1r3PP/1R4K1 474 w - - bm Qb5 Rxe8; id ""WAC.232""; Rxe8 d8+3 Qb5 d14+7"; 475const char wac233[] 476 PROGMEM="5rk1/p1p2r1p/2pp2p1/4p3/PPPnP3/3Pq1P1/1Q1R1R1P/4NK2 b - - bm Nb3; id ""WAC.233""; 477 d7+6"; 478const char wac234[] PROGMEM="2kr1r2/p6p/5Pp1/2p5/1qp2Q1P/7R/PP6/1KR5 479 w - - bm Rb3; id ""WAC.234""; d5+5"; 480const char wac235[] PROGMEM="5r2/1p1RRrk1/4Qq1p/1PP3p1/8/4B3/1b3P1P/6K1 481 w - - bm Qe4 Qxf7+ Rxf7+; id ""WAC.235""; Qe4 d5+3 Rxf7 13+5"; 482const char 483 wac236[] PROGMEM="1R6/p5pk/4p2p/4P3/8/2r3qP/P3R1b1/4Q1K1 b - - bm Rc1; id ""WAC.236""; 484 d5+0.8"; 485const char wac237[] PROGMEM="r5k1/pQp2qpp/8/4pbN1/3P4/6P1/PPr4P/1K1R3R 486 b - - bm Rc1+; id ""WAC.237""; d12+15"; 487const char wac238[] PROGMEM="1k1r4/pp1r1pp1/4n1p1/2R5/2Pp1qP1/3P2QP/P4PB1/1R4K1 488 w - - bm Bxb7; id ""WAC.238""; d5+4"; 489const char wac239[] PROGMEM="8/6k1/5pp1/Q6p/5P2/6PK/P4q1P/8 490 b - - bm Qf1+; id ""WAC.239""; d10+13"; 491const char wac240[] PROGMEM="2b4k/p1b2p2/2p2q2/3p1PNp/3P2R1/3B4/P1Q2PKP/4r3 492 w - - bm Qxc6; id ""WAC.240""; d6+5"; 493const char wac241[] PROGMEM="2rq1rk1/pp3ppp/2n2b2/4NR2/3P4/PB5Q/1P4PP/3R2K1 494 w - - bm Qxh7+; id ""WAC.241""; d11+m6"; 495const char wac242[] PROGMEM="r1b1r1k1/pp1nqp2/2p1p1pp/8/4N3/P1Q1P3/1P3PPP/1BRR2K1 496 w - - bm Rxd7; id ""WAC.242""; d5+3.5"; 497const char wac243[] PROGMEM="1r3r1k/3p4/1p1Nn1R1/4Pp1q/pP3P1p/P7/5Q1P/6RK 498 w - - bm Qe2; id ""WAC.243""; d7+1.5"; 499const char wac244[] PROGMEM="r6r/pp3ppp/3k1b2/2pb4/B4Pq1/2P1Q3/P5PP/1RBR2K1 500 w - - bm Qxc5+; id ""WAC.244""; d5+m4"; 501const char wac245[] PROGMEM="4rrn1/ppq3bk/3pPnpp/2p5/2PB4/2NQ1RPB/PP5P/5R1K 502 w - - bm Qxg6+; id ""WAC.245""; d7+4"; 503const char wac246[] PROGMEM="6R1/4qp1p/ppr1n1pk/8/1P2P1QP/6N1/P4PP1/6K1 504 w - - bm Qh5+; id ""WAC.246""; d5+m2"; 505const char wac247[] PROGMEM="2k1r3/1p2Bq2/p2Qp3/Pb1p1p1P/2pP1P2/2P5/2P2KP1/1R6 506 w - - bm Rxb5; id ""WAC.247""; d8+7"; 507const char wac248[] PROGMEM="5r1k/1p4pp/3q4/3Pp1R1/8/8/PP4PP/4Q1K1 508 b - - bm Qc5+; id ""WAC.248""; d6+0.5"; 509const char wac249[] PROGMEM="r4rk1/pbq2pp1/1ppbpn1p/8/2PP4/1P1Q1N2/PBB2PPP/R3R1K1 510 w - - bm c5 d5; id ""WAC.249""; d5 d5+9 c5 d10+1.7"; 511const char wac250[] 512 PROGMEM="1b5k/7P/p1p2np1/2P2p2/PP3P2/4RQ1R/q2r3P/6K1 w - - bm Re8+; id ""WAC.250""; 513 d5+m8"; 514const char wac251[] PROGMEM="k7/p4p2/P1q1b1p1/3p3p/3Q4/7P/5PP1/1R4K1 515 w - - bm Qe5 Qf4; id ""WAC.251""; d8+m6"; 516const char wac252[] PROGMEM="1rb1r1k1/p1p2ppp/5n2/2pP4/5P2/2QB4/qNP3PP/2KRB2R 517 b - - bm Bg4 Re2; c0 ""Bg4 wins, but Re2 is far better.""; id ""WAC.252""; 518 Bg4 +3 Re2 d7+m7 d8+m5"; 519const char wac253[] PROGMEM="k5r1/p4b2/2P5/5p2/3P1P2/4QBrq/P5P1/4R1K1 520 w - - bm Qe8+; id ""WAC.253""; d5+m4"; 521const char wac254[] PROGMEM="r6k/pp3p1p/2p1bp1q/b3p3/4Pnr1/2PP2NP/PP1Q1PPN/R2B2RK 522 b - - bm Nxh3; id ""WAC.254""; d5+2.5"; 523const char wac255[] PROGMEM="3r3r/p4pk1/5Rp1/3q4/1p1P2RQ/5N2/P1P4P/2b4K 524 w - - bm Rfxg6+; id ""WAC.255""; d5+4"; 525const char wac256[] PROGMEM="3r1rk1/1pb1qp1p/2p3p1/p7/P2Np2R/1P5P/1BP2PP1/3Q1BK1 526 w - - bm Nf5; id ""WAC.256""; d9+3"; 527const char wac257[] PROGMEM="4r1k1/pq3p1p/2p1r1p1/2Q1p3/3nN1P1/1P6/P1P2P1P/3RR1K1 528 w - - bm Rxd4; id ""WAC.257""; d5+3"; 529const char wac258[] PROGMEM="r3brkn/1p5p/2p2Ppq/2Pp3B/3Pp2Q/4P1R1/6PP/5R1K 530 w - - bm Bxg6; id ""WAC.258""; d5+0.2"; 531const char wac259[] PROGMEM="r1bq1rk1/ppp2ppp/2np4/2bN1PN1/2B1P3/3p4/PPP2nPP/R1BQ1K1R 532 w - - bm Qh5; id ""WAC.259""; d5-1.5"; 533const char wac260[] PROGMEM="2r2b1r/p1Nk2pp/3p1p2/N2Qn3/4P3/q6P/P4PP1/1R3K1R 534 w - - bm Qe6+; id ""WAC.260""; d5+m5"; 535const char wac261[] PROGMEM="r5k1/1bp3pp/p2p4/1p6/5p2/1PBP1nqP/1PP3Q1/R4R1K 536 b - - bm Nd4; id ""WAC.261""; d6+9"; 537const char wac262[] PROGMEM="6k1/p1B1b2p/2b3r1/2p5/4p3/1PP1N1Pq/P2R1P2/3Q2K1 538 b - - bm Rh6; id ""WAC.262""; d5+1.2"; 539const char wac263[] PROGMEM="rnbqr2k/pppp1Qpp/8/b2NN3/2B1n3/8/PPPP1PPP/R1B1K2R 540 w KQ - bm Qg8+; id ""WAC.263""; d6+m4"; 541const char wac264[] PROGMEM="r2r2k1/1R2qp2/p5pp/2P5/b1PN1b2/P7/1Q3PPP/1B1R2K1 542 b - - bm Qe5 Rab8; id ""WAC.264""; Rab8 d5+2"; 543const char wac265[] PROGMEM="2r1k2r/2pn1pp1/1p3n1p/p3PP2/4q2B/P1P5/2Q1N1PP/R4RK1 544 w k - bm exf6; id ""WAC.265""; d10+2"; 545const char wac266[] PROGMEM="r3q2r/2p1k1p1/p5p1/1p2Nb2/1P2nB2/P7/2PNQbPP/R2R3K 546 b - - bm Rxh2+; id ""WAC.266""; d5+m6"; 547const char wac267[] PROGMEM="2r1kb1r/pp3ppp/2n1b3/1q1N2B1/1P2Q3/8/P4PPP/3RK1NR 548 w Kk - bm Nc7+; id ""WAC.267""; d5+m5"; 549const char wac268[] PROGMEM="2r3kr/ppp2n1p/7B/5q1N/1bp5/2Pp4/PP2RPPP/R2Q2K1 550 w - - bm Re8+; id ""WAC.268""; d5+11"; 551const char wac269[] PROGMEM="2kr2nr/pp1n1ppp/2p1p3/q7/1b1P1B2/P1N2Q1P/1PP1BPP1/R3K2R 552 w KQ - bm axb4; id ""WAC.269""; d8+3"; 553const char wac270[] PROGMEM="2r1r1k1/pp1q1ppp/3p1b2/3P4/3Q4/5N2/PP2RPPP/4R1K1 554 w - - bm Qg4; id ""WAC.270""; d8+0.7"; 555const char wac271[] PROGMEM="2kr4/ppp3Pp/4RP1B/2r5/5P2/1P6/P2p4/3K4 556 w - - bm Rd6; id ""WAC.271""; d6+0"; 557const char wac272[] PROGMEM="nrq4r/2k1p3/1p1pPnp1/pRpP1p2/P1P2P2/2P1BB2/1R2Q1P1/6K1 558 w - - bm Bxc5; id ""WAC.272""; d5+2"; 559const char wac273[] PROGMEM="2k4B/bpp1qp2/p1b5/7p/1PN1n1p1/2Pr4/P5PP/R3QR1K 560 b - - bm Ng3+ g3; id ""WAC.273""; Ng3+ d6+6"; 561const char wac274[] PROGMEM="8/1p6/p5R1/k7/Prpp4/K7/1NP5/8 562 w - - am Rd6; bm Rb6 Rg5+; id ""WAC.274""; Rb6 d6+2.5"; 563const char wac275[] 564 PROGMEM="r1b2rk1/1p1n1ppp/p1p2q2/4p3/P1B1Pn2/1QN2N2/1P3PPP/3R1RK1 b - - bm Nc5 565 Nxg2 b5; id ""WAC.275""; b5 d5+1.3"; 566const char wac276[] PROGMEM="r5k1/pp1RR1pp/1b6/6r1/2p5/B6P/P4qPK/3Q4 567 w - - bm Qd5+; id ""WAC.276""; d5+9"; 568const char wac277[] PROGMEM="1r4r1/p2kb2p/bq2p3/3p1p2/5P2/2BB3Q/PP4PP/3RKR2 569 b - - bm Rg3 Rxg2; id ""WAC.277""; Rg3 d5+1.3"; 570const char wac278[] PROGMEM="r2qkb1r/pppb2pp/2np1n2/5pN1/2BQP3/2N5/PPP2PPP/R1B1K2R 571 w KQkq - bm Bf7+; id ""WAC.278""; d5+m5"; 572const char wac279[] PROGMEM="r7/4b3/2p1r1k1/1p1pPp1q/1P1P1P1p/PR2NRpP/2Q3K1/8 573 w - - bm Nxf5 Rc3; id ""WAC.279""; d5+1.6"; 574const char wac280[] PROGMEM="r1r2bk1/5p1p/pn4p1/N2b4/3Pp3/B3P3/2q1BPPP/RQ3RK1 575 b - - bm Bxa3; id ""WAC.280""; d6+2"; 576const char wac281[] PROGMEM="2R5/2R4p/5p1k/6n1/8/1P2QPPq/r7/6K1 577 w - - bm Rxh7+; id ""WAC.281""; d5+6"; 578const char wac282[] PROGMEM="6k1/2p3p1/1p1p1nN1/1B1P4/4PK2/8/2r3b1/7R 579 w - - bm Rh8+; id ""WAC.282""; d5+m4"; 580const char wac283[] PROGMEM="3q1rk1/4bp1p/1n2P2Q/3p1p2/6r1/Pp2R2N/1B4PP/7K 581 w - - bm Ng5; id ""WAC.283""; d5+m4"; 582const char wac284[] PROGMEM="3r3k/pp4pp/8/1P6/3N4/Pn2P1qb/1B1Q2B1/2R3K1 583 w - - bm Nf5; id ""WAC.284""; d6+3.5"; 584const char wac285[] PROGMEM="2rr3k/1b2bppP/p2p1n2/R7/3P4/1qB2P2/1P4Q1/1K5R 585 w - - bm Qxg7+; id ""WAC.285""; d5+m5"; 586const char wac286[] PROGMEM="3r1k2/1p6/p4P2/2pP2Qb/8/1P1KB3/P6r/8 587 b - - bm Rxd5+; id ""WAC.286""; d5+3"; 588const char wac287[] PROGMEM="rn3k1r/pp2bBpp/2p2n2/q5N1/3P4/1P6/P1P3PP/R1BQ1RK1 589 w - - bm Qg4 Qh5; id ""WAC.287""; Qh5 d5+4"; 590const char wac288[] PROGMEM="r1b2rk1/p4ppp/1p1Qp3/4P2N/1P6/8/P3qPPP/3R1RK1 591 w - - bm Nf6+; id ""WAC.288""; d5+3.5"; 592const char wac289[] PROGMEM="2r3k1/5p1p/p3q1p1/2n3P1/1p1QP2P/1P4N1/PK6/2R5 593 b - - bm Qe5; id ""WAC.289""; d5+3.5"; 594const char wac290[] PROGMEM="2k2r2/2p5/1pq5/p1p1n3/P1P2n1B/1R4Pp/2QR4/6K1 595 b - - bm Ne2+; id ""WAC.290""; d5+m4"; 596const char wac291[] PROGMEM="5r1k/3b2p1/p6p/1pRpR3/1P1P2q1/P4pP1/5QnP/1B4K1 597 w - - bm h3; id ""WAC.291""; d7+3"; 598const char wac292[] PROGMEM="4r3/1Q1qk2p/p4pp1/3Pb3/P7/6PP/5P2/4R1K1 599 w - - bm d6+; id ""WAC.292""; d5+2.5"; 600const char wac293[] PROGMEM="1nbq1r1k/3rbp1p/p1p1pp1Q/1p6/P1pPN3/5NP1/1P2PPBP/R4RK1 601 w - - bm Nfg5; id ""WAC.293""; d9+m4"; 602const char wac294[] PROGMEM="3r3k/1r3p1p/p1pB1p2/8/p1qNP1Q1/P6P/1P4P1/3R3K 603 w - - bm Bf8 Nf5 Qf4; id ""WAC.294""; Qf4 d5+4 Bf8 d6+7"; 604const char wac295[] 605 PROGMEM="4r3/p4r1p/R1p2pp1/1p1bk3/4pNPP/2P1K3/2P2P2/3R4 w - - bm Rxd5+; id ""WAC.295""; 606 d5+m3"; 607const char wac296[] PROGMEM="3r4/1p2k2p/p1b1p1p1/4Q1Pn/2B3KP/4pP2/PP2R1N1/6q1 608 b - - bm Rd4+ Rf8; id ""WAC.296""; Rf8 d5+5 Rd4+ d9+9"; 609const char wac297[] 610 PROGMEM="3r1rk1/p3qp1p/2bb2p1/2p5/3P4/1P6/PBQN1PPP/2R2RK1 b - - bm Bxg2 Bxh2+; 611 id ""WAC.297""; Bxg2 d8+1.6"; 612const char wac298[] PROGMEM="3Q4/p3b1k1/2p2rPp/2q5/4B3/P2P4/7P/6RK 613 w - - bm Qh8+; id ""WAC.298""; d6+m4"; 614const char wac299[] PROGMEM="1n2rr2/1pk3pp/pNn2p2/2N1p3/8/6P1/PP2PPKP/2RR4 615 w - - bm Nca4; id ""WAC.299""; d5+5"; 616const char wac300[] PROGMEM="b2b1r1k/3R1ppp/4qP2/4p1PQ/4P3/5B2/4N1K1/8 617 w - - bm g6; id ""WAC.300""; d5+2"; 618 619const char * const wacs[] PROGMEM 620 = { 621 wac1,wac2,wac3,wac4,wac5,wac6,wac7,wac8,wac9,wac10, 622 wac11,wac12,wac13,wac14,wac15,wac16,wac17,wac18,wac19,wac20, 623 624 wac21,wac22,wac23,wac24,wac25,wac26,wac27,wac28,wac29,wac30, 625 wac31,wac32,wac33,wac34,wac35,wac36,wac37,wac38,wac39,wac40, 626 627 wac41,wac42,wac43,wac44,wac45,wac46,wac47,wac48,wac49,wac50, 628 wac51,wac52,wac53,wac54,wac55,wac56,wac57,wac58,wac59,wac60, 629 630 wac61,wac62,wac63,wac64,wac65,wac66,wac67,wac68,wac69,wac70, 631 wac71,wac72,wac73,wac74,wac75,wac76,wac77,wac78,wac79,wac80, 632 633 wac81,wac82,wac83,wac84,wac85,wac86,wac87,wac88,wac89,wac90, 634 wac91,wac92,wac93,wac94,wac95,wac96,wac97,wac98,wac99,wac100, 635 636 wac101,wac102,wac103,wac104,wac105,wac106,wac107,wac108,wac109,wac110, 637 wac111,wac112,wac113,wac114,wac115,wac116,wac117,wac118,wac119,wac120, 638 639 wac121,wac122,wac123,wac124,wac125,wac126,wac127,wac128,wac129,wac130, 640 wac131,wac132,wac133,wac134,wac135,wac136,wac137,wac138,wac139,wac140, 641 642 wac141,wac142,wac143,wac144,wac145,wac146,wac147,wac148,wac149,wac150, 643 wac151,wac152,wac153,wac154,wac155,wac156,wac157,wac158,wac159,wac160, 644 645 wac161,wac162,wac163,wac164,wac165,wac166,wac167,wac168,wac169,wac170, 646 wac171,wac172,wac173,wac174,wac175,wac176,wac177,wac178,wac179,wac180, 647 648 wac181,wac182,wac183,wac184,wac185,wac186,wac187,wac188,wac189,wac190, 649 wac191,wac192,wac193,wac194,wac195,wac196,wac197,wac198,wac199,wac200, 650 651 wac201,wac202,wac203,wac204,wac205,wac206,wac207,wac208,wac209,wac210, 652 wac211,wac212,wac213,wac214,wac215,wac216,wac217,wac218,wac219,wac220, 653 654 wac221,wac222,wac223,wac224,wac225,wac226,wac227,wac228,wac229,wac230, 655 wac231,wac232,wac233,wac234,wac235,wac236,wac237,wac238,wac239,wac240, 656 657 wac241,wac242,wac243,wac244,wac245,wac246,wac247,wac248,wac249,wac250, 658 wac251,wac252,wac253,wac254,wac255,wac256,wac257,wac258,wac259,wac260, 659 660 wac261,wac262,wac263,wac264,wac265,wac266,wac267,wac268,wac269,wac270, 661 wac271,wac272,wac273,wac274,wac275,wac276,wac277,wac278,wac279,wac280, 662 663 wac281,wac282,wac283,wac284,wac285,wac286,wac287,wac288,wac289,wac290, 664 wac291,wac292,wac293,wac294,wac295,wac296,wac297,wac298,wac299,wac300 665 666 }; 667 668 669
gui.h
h
1#define mcufriend480 2//#define adafruit320 3 4#ifdef mcufriend480 5 //(MCUFRIEND screen 480x320) 6 #include <UTFTGLUE.h> 7 MCUFRIEND_kbv tft; 8 #define screen_width 480 9 #define screen_height 320 10 #define mapx1 980 11 #define mapx2 110 12 #define mapy1 145 13 #define mapy2 902 14#endif 15 16#ifdef adafruit320 17 //(screen 320x240) 18 #include <Adafruit_TFTLCD.h> 19 Adafruit_TFTLCD tft; 20 #define screen_width 320 21 #define screen_height 240 22 #define mapx1 930 23 #define mapx2 170 24 #define mapy1 145 25 #define mapy2 914 26#endif 27 28#include "TouchScreen.h" 29int XP = 6, YP = A1, XM = A2, YM = 7; 30TouchScreen ts(XP, YP, XM, YM, 300); 31TSPoint tp; 32 33int touchx,touchy,touched; 34#define MINPRESSURE 10 35#define MAXPRESSURE 1000 36#define PinBuzz 44 37 38boolean rotate=0; 39boolean sound=0; 40boolean menu=0; 41boolean pause=0; 42unsigned long guitime=0; 43unsigned long statustime=0; 44 45char poledisp[64]; // 46char statusbuf1[11],statusbuf2[11],statusbuf3[11]; 47char status_c1, status_c2; 48 49const uint8_t fig24[6][72] PROGMEM={ 50{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1E, 0x0, 0x0, 0x3F, 0x0, 0x80, 0x7F, 0x0, 0x80, 0x7F, 0x0, 510x80, 0x7F, 0x0, 0x0, 0x3F, 0x0, 0x0, 0x1C, 0x0, 0x0, 0x1C, 0x0, 0x80, 0xFF, 0x0, 0x80, 0xFF, 0x0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0x40, 0x0, 0x2, 0x20, 0x18, 0x4, 860x10, 0x18, 0x8, 0x10, 0x18, 0x8, 0x10, 0x18, 0x8, 0x90, 0xFF, 0x9, 0x90, 0xFF, 0x9, 0x10, 0x18, 0x8, 0x10, 0x18, 0x8, 0x10, 0x18, 0x8, 870x10, 0x18, 0x8, 0x20, 0x18, 0x4, 0x40, 0x18, 0x2, 0x88, 0x0, 0x11, 0x14, 0x81, 0x28, 0xE2, 0xC3, 0x47, 0x1, 0x0, 0x80, 0xFF, 0xFF, 0xFF 88}, //bishop 89{0xF8, 0x7E, 0x1F, 0x8, 0xC3, 0x10, 0x8, 0xC3, 0x10, 0x8, 0x0, 0x10, 0x10, 0x0, 0x8, 0xE0, 0xFF, 0x7, 0x20, 0x0, 0x4, 0x20, 0x0, 0x4, 900x20, 0x0, 0x4, 0x20, 0x0, 0x4, 0x20, 0x0, 0x4, 0x20, 0x0, 0x4, 0x20, 0x0, 0x4, 0x20, 0x0, 0x4, 0x20, 0x0, 0x4, 0x20, 0x0, 0x4, 910x20, 0x0, 0x4, 0x20, 0x0, 0x4, 0x20, 0x0, 0x4, 0xE0, 0xFF, 0x7, 0x10, 0x0, 0x8, 0x8, 0x0, 0x10, 0x8, 0x0, 0x10, 0xF8, 0xFF, 0x1F 92}, //rook 93{0xEF, 0xBD, 0xF7, 0x11, 0x42, 0x88, 0x11, 0x42, 0x88, 0x29, 0xA5, 0x94, 0x29, 0xA5, 0x94, 0x29, 0xA5, 0x94, 0x32, 0xA5, 0x4C, 0x32, 0xA5, 0x4C, 940x32, 0xA5, 0x4C, 0x32, 0xA5, 0x4C, 0x32, 0xA5, 0x4C, 0x64, 0x66, 0x26, 0x64, 0x66, 0x26, 0x64, 0x66, 0x26, 0x64, 0x66, 0x26, 0x64, 0x66, 0x26, 950xC8, 0x0, 0x13, 0x48, 0x0, 0x12, 0x8, 0x0, 0x10, 0x10, 0x0, 0x8, 0xF0, 0xFF, 0xF, 0x8, 0x0, 0x10, 0x8, 0x0,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0x80, 0x0, 0x0, 0x1, 1930x80, 0x0, 0x0, 0x1, 0x80, 0x0, 0x0, 0x1, 0x80, 0x0, 0x0, 0x1, 0x80, 0x0, 0x0, 0x1, 1940x40, 0xFE, 0x7F, 0x2, 0x20, 0x0, 0x0, 0x4, 0x10, 0x0, 0x0, 0x8, 0x8, 0x0, 0x0, 0x10, 1950xE8, 0xFF, 0xFF, 0x17, 0x8, 0x0, 0x0, 0x10, 0x8, 0x0, 0x0, 0x10, 0xF8, 0xFF, 0xFF, 0x1F 196}, { 1970x0, 0x80, 0x1, 0x0, 0x0, 0x46, 0x62, 0x0, 0x0, 0x29, 0x94, 0x0, 0x8C, 0x30, 0xC, 0x31, 1980x92, 0x50, 0xA, 0x49, 0x21, 0x49, 0x92, 0x84, 0x21, 0x29, 0x94, 0x84, 0x92, 0x30, 0xC, 0x49, 1990x92, 0x30, 0xC, 0x49, 0xA1, 0x30, 0xC, 0x85, 0xA1, 0x30, 0xC, 0x85, 0xA2, 0x30, 0xC, 0x45, 2000x42, 0x51, 0x8A, 0x42, 0x42, 0x31, 0x8C, 0x42, 0x44, 0x11, 0x88, 0x22, 0x44, 0x1, 0x80, 0x21, 2010xC4, 0x0, 0x0, 0x21, 0x84, 0x0, 0x0, 0x21, 0x8, 0xE0, 0x7, 0x10, 0x8, 0x1E, 0x78, 0x10, 2020xC8, 0x1, 0x80, 0x13, 0x8, 0x80, 0x1, 0x10, 0x8, 0xC2, 0x43, 0x8, 0x10, 0x87, 0xE1, 0x8, 2030x20, 0x2, 0x40, 0x4, 0x20, 0x0, 0x0, 0x4, 0x40, 0x0, 0x0, 0x2, 0x80, 0x0, 0x0, 0x1, 2040x80, 0xFE, 0x7F, 0x1, 0x40, 0x0, 0x0, 0x2, 0x40, 0x0, 0x0, 0x2, 0xC0, 0xFF, 0xFF, 0x3 205}, { 206 0x0, 0x80, 0x1, 0x0, 0x0, 0x40, 0x2, 0x0, 0x0, 0x20, 0x4, 0x0, 0xE0, 0x21, 0x84, 0x7, 2070x18, 0x46, 0x62, 0x18, 0x4, 0x48, 0x12, 0x20, 0x2, 0x30, 0xC, 0x40, 0x1, 0x30, 0xC, 0x80, 2080x1, 0x60, 0x6, 0x80, 0x1, 0xC0, 0x3, 0x80, 0x1, 0x80, 0x1, 0x80, 0x1, 0x80, 0x1, 0x80, 2090x1, 0x80, 0x1, 0x80, 0x1, 0x80, 0x1, 0x80, 0x1, 0x80, 0x1, 0x80, 0x1, 0x80, 0x1, 0x80, 2100x1, 0x80, 0x1, 0x80, 0x1, 0x80, 0x1, 0x80, 0x2, 0x80, 0x1, 0x40, 0x4, 0x80, 0x1, 0x20, 2110x4, 0x80, 0x1, 0x20, 0x8, 0xE0, 0x7, 0x10, 0x8, 0x1C, 0x38, 0x10, 0xD0, 0x3, 0xC0, 0xB, 2120x20, 0x80, 0x1, 0x4, 0x20, 0xC6, 0x63, 0x4, 0x40, 0x80, 0x1, 0x2, 0x80, 0x0, 0x0, 0x1, 2130x80, 0xFE, 0x5F, 0x1, 0x40, 0x0, 0x0, 0x2, 0x40, 0x0, 0x0, 0x2, 0xC0, 0xFF, 0xFF, 0x3 214} 215}; 216 217uint16_t BLACK,BLUE,RED,GREEN,CYAN,MAGENTA,YELLOW,WHITE,GRAY,DARK,GRAY2,BLACKF,WHITEF; 218 219//********************************** 220class Button { 221public: 222int bx,by,bw,bh,bshift; 223String bs; 224const uint8_t* bp; 225 Button(int x,int y,int w,int h,int x1,int y1,int w1,int h1,String s,const uint8_t* p, int shift); 226 void Show(int shift); 227 void Show(String s); 228 void Hide(); 229 boolean IsPressed(); 230private: 231boolean active; 232 void ishow(uint16_t textcolor,uint16_t backcolor); 233}; 234Button::Button(int x,int y,int w,int h,int x1,int y1,int w1,int h1,String s,const uint8_t* p=NULL, int shift=0) { 235 if (screen_height==320) { 236 bx=x; by=y; bw=w; bh=h; 237 } else { 238 bx=x1; by=y1; bw=w1; bh=h1; 239 } 240 bs=s; bp=p; bshift=shift; 241}; 242void Button::Show(int shift=0) { 243 bshift=shift; 244 active=true; 245 ishow(WHITE,DARK); 246}; 247void Button::Show(String s) { 248 bs=s; 249 active=true; 250 ishow(WHITE,DARK); 251}; 252void Button::Hide() { 253 active=false; 254 ishow(GRAY,DARK); 255}; 256boolean Button::IsPressed() { 257 if (active&&abs(bx+bw/2-touchx)<bw/2&&abs(by+bh/2-touchy)<bh/2) { 258 ishow(WHITE,GRAY); 259 touchx=0; touchy=0; 260 return true; 261 } 262 return false; 263}; 264void Button::ishow(uint16_t textcolor,uint16_t backcolor) { 265 tft.fillRoundRect(bx+2,by+2,bw,bh,3,GRAY2); 266 tft.fillRoundRect(bx,by,bw,bh,3,backcolor); 267 tft.setTextColor(textcolor); 268 if (screen_height==320) { 269 tft.setTextSize(2); 270 tft.setCursor(bx+(bw-bs.length()*12)/2,by+(bh-12)/2); 271 } else { 272 tft.setTextSize(1); 273 tft.setCursor(bx+(bw-bs.length()*6)/2,by+(bh-8)/2); 274 } 275 if (bp!=NULL) { 276 tft.drawBitmap(1+bx+(bw-16)/2, by+(bh-16)/2, bp+bshift*32, 16, 16,textcolor); 277 } 278 else tft.print(bs); 279} 280 281Button BAction(354, 280, 100, 30, 252, 210, 60, 20, "START"); 282Button BMenu(354, 20, 100, 30, 252, 20, 60, 20, "MENU"); 283Button BBack(354, 58, 100, 30, 252, 47, 60, 20, "BACK"); 284Button BTime(354, 96, 100, 30, 252, 74, 60, 20, "5 s"); 285Button BNew(354, 134, 100, 30, 252, 101, 60, 20, "NEW"); 286Button BAuto(354, 172, 100, 30, 252, 128, 60, 20, "AUTO:B"); 287Button BRotate(354, 210, 100, 30, 252, 155, 60, 20, "ROTATE"); 288Button BSave(354, 248, 100, 30, 252, 182, 60, 20, "SAVE"); 289Button BLoad(354, 286, 100, 30, 252, 209, 60, 20, "LOAD"); 290 291//********************************** 292void drawBitmap(int16_t x, int16_t y, 293 const uint8_t *bitmap, int16_t w, int16_t h, 294 uint16_t color) { 295 int16_t i, j, byteWidth = (w + 7) / 8; 296 for(j=0; j<h; j++) { 297 for(i=0; i<w; i++ ) { 298 if(pgm_read_byte(bitmap + j * byteWidth + i / 8) & (1 << (i % 8))) { 299 tft.drawPixel(x+i, y+j, color); 300 } 301 } 302 } 303} 304//**************************** 305uint16_t getColor(uint8_t red, uint8_t green, uint8_t blue) 306{ 307 red >>= 3; 308 green >>= 2; 309 blue >>= 3; 310 return (red << 11) | (green << 5) | blue; 311} 312//**************************** 313void show_fig(int c) { 314uint16_t colorf,color,color_cont; 315 colorf=BLACKF; 316 int i=column[c]-1; 317 int j=8-row[c]; 318 if ((i+j+2)%2==0) colorf=WHITEF; 319 int jj=j, ii=i; 320 if (rotate) { jj=7-j; ii=7-i; } 321 color=BLACK; color_cont=getColor(128,128,100); 322 if (pole[c]>0) { color=WHITE; color_cont=BLACK; } 323 if (screen_height==320) { 324 tft.fillRect(ii*39+10,jj*39,39,39,colorf); 325 tft.drawRect(ii*39+10,jj*39,39,39,GRAY); 326 if (pole[c]!=0) { 327 drawBitmap(ii*39+14, jj*39+5,&fig32[abs(pole[c])-1][0], 32, 32,color); 328 drawBitmap(ii*39+14, jj*39+5,&fig32_cont[abs(pole[c])-1][0], 32, 32,color_cont); 329 } 330 } else { //height 240 331 tft.fillRect(ii*28+12,jj*28,29,29,colorf); 332 tft.drawRect(ii*28+12,jj*28,29,29,GRAY); 333 if (pole[c]!=0) { 334 drawBitmap(ii*28+14, jj*28+3,&fig24[abs(pole[c])-1][0], 24, 24,color); 335 drawBitmap(ii*28+14, jj*28+3,&fig24_cont[abs(pole[c])-1][0], 24, 24,color_cont); 336 } 337 } 338} 339//**************************** 340void show_color() { 341int posx, posyw, posyb, rad; 342if (screen_height==320) { 343 posx=334; posyw=290; posyb=24; rad=5; 344 } else { //240 345 posx=244; posyw=214; posyb=20; rad=4; 346 } 347 if (rotate) { int r=posyb; posyb=posyw; posyw=r; } 348 tft.fillCircle(posx,posyb,rad,BLACK); tft.fillCircle(posx,posyw,rad,BLACK); 349 if (pos[0].w) tft.fillCircle(posx,posyw,rad,GRAY); else tft.drawCircle(posx,posyb,rad,GRAY); 350 uint16_t col=BLACK; 351 int r2=rad*2; 352 if (autow) col=DARK; 353 tft.drawRect(posx-rad,posyw+r2,r2,r2,col); 354 col=BLACK; 355 if (autob) col=DARK; 356 tft.drawRect(posx-rad,posyb+r2,r2,r2,col); 357} 358//**************************** 359void show_board() { 360 for (int i=0;i<64;i++) { 361 if (poledisp[i]!=pole[i]) show_fig(i); 362 poledisp[i]=pole[i]; 363 } 364 show_color(); 365} 366//**************************** 367void border() { 368 tft.setTextColor(GRAY,BLACK); 369 tft.setTextSize(1); 370 if (screen_height==320) { 371 for (int j=1;j<9;j++) { 372 tft.setCursor(1,j*39-22); 373 if (rotate) tft.print(j); else tft.print(9-j); 374 } 375 for (byte i=1;i<9;i++) { 376 tft.setCursor(i*39-11,312); 377 if (rotate) tft.print(char(96+9-i)); else tft.print(char(96+i)); 378 } 379 } else { //240 380 for (int j=1;j<9;j++) { 381 tft.setCursor(2,j*28-15); 382 if (rotate) tft.print(j); else tft.print(9-j); 383 } 384 for (byte i=1;i<9;i++) { 385 tft.setCursor(i*28-1,228); 386 if (rotate) tft.print(char(96+9-i)); else tft.print(char(96+i)); 387 } 388 } 389} 390//**************************** 391void cleardisplayboard() { 392 for (int i=0;i<64;i++) poledisp[i]=-100; // 393} 394//**************************** 395void initboard() { 396 cleardisplayboard(); 397 tft.fillScreen(BLACK); 398 border(); 399 tft.setTextSize(1); 400 if (screen_height==320) { 401 tft.setCursor(337,1); tft.setTextColor(WHITE); 402 tft.print(F("Arduino Mega Chess II")); 403 } else { //240 404 tft.setCursor(242,1); tft.setTextColor(WHITE); 405 tft.print(F("Arduino Mega")); 406 tft.setCursor(252,10); 407 tft.print(F("Chess II")); 408 } 409} 410//**************************** 411void show_steps() { 412 if (screen_height==320) { 413 tft.fillRect(330,56,135,150,GRAY2); 414 } 415 else { 416 tft.fillRect(240,44,74,114,GRAY2); 417 } 418 tft.setTextColor(GRAY); 419 tft.setTextSize(2); 420 int st=0; 421 if (ply>8) st=ply-8; 422 if (st<0) st=0; 423 for (int i=st;i<ply;i++) { 424 if (i%2==0) { 425 tft.setTextSize(1); 426 if (screen_height==320) 427 tft.setCursor(332,(i-st)*18+64); 428 else 429 tft.setCursor(244,(i-st)*14+48); 430 tft.print(String(i/2+1)+"."); 431 } 432 if (screen_height==320) { 433 tft.setTextSize(2); 434 tft.setCursor(360,(i-st)*18+60); 435 } else { 436 tft.setTextSize(1); 437 tft.setCursor(268,(i-st)*14+48); 438 } 439 tft.print(str_step(steps[i])); 440 } 441 442 443 444} 445//**************************** 446void definecolors() { 447 BLACK =0x0000; 448 BLUE =0x07FF; //0x001F; 449 RED =0xF800; 450 GREEN =0x07E0; 451 CYAN =0x07FF; 452 MAGENTA=0xF81F; 453 YELLOW =0xFFE0; 454 WHITE =0xFFFF; 455 GRAY =0x7BEF; 456 DARK =getColor(32,32,32); 457 GRAY2 =getColor(16,16,16); 458 BLACKF =getColor(94,58,0); 459 WHITEF =getColor(180,114,0); 460} 461//**************************** 462void beep(int leng) { 463 analogWrite(PinBuzz, 20); 464 delay(2); 465 if (!sound) analogWrite(PinBuzz, 0); 466 delay(leng); 467 analogWrite(PinBuzz, 0); 468} 469//**************************** 470void guistart() { 471 tft.reset(); 472 tft.begin(tft.readID()); 473 tft.setRotation(1); 474 definecolors(); 475 initboard(); 476 BAction.Show("START"); 477 BMenu.Show("MENU"); 478 show_board(); 479} 480//**************************** 481String get_time(int tim) { 482 char sz[10]; 483 //sprintf(sz, "%02d:%02d:%02d", tim/3600,(tim%3600)/60,tim%60); 484 sprintf(sz, "%d:%02d",tim/60,tim%60); 485 String s=sz; s.trim(); 486 return String(sz); 487} 488//**************************** 489void clearstatus() { 490 if (screen_height==320) { 491 tft.fillRect(330,210,135,60,GRAY2); 492 } else { 493 tft.fillRect(242,169,70,36,GRAY2); 494 } 495 for (int j=0;j<11;j++) { statusbuf1[j]=' '; statusbuf2[j]=' '; statusbuf3[j]=' '; } 496 guitime=millis(); 497 statustime=guitime; 498 status_c1=-1; 499 status_c2=-1; 500} 501//**************************** 502void print_changed(String s, char* b, uint16_t c) { 503 for (int i=0;i<11;i++) { 504 if (b[i]!=s[i]) { 505 tft.setTextColor(c,GRAY2); 506 tft.print(s[i]); 507 } else { 508 tft.setTextColor(GRAY2,GRAY2); 509 tft.print(" "); 510 } 511 b[i]=s[i]; 512 } 513} 514//**************************** 515void status_step(char c,byte show,uint16_t col=0) { 516uint16_t color,color2; 517 if (c<0||c>63) return; 518 color=BLACKF; 519 int i=column[c]-1; 520 int j=8-row[c]; 521 if ((i+j+2)%2==0) color=WHITEF; 522 color2=GRAY; 523 if (show) { color=col; color2=color; } 524 int jj=j, ii=i; 525 if (rotate) { jj=7-j; ii=7-i; } 526 if (screen_height==320) { 527 tft.drawRect(ii*39+10,jj*39,39,39,color2); 528 tft.drawRect(ii*39+11,jj*39+1,37,37,color); 529 } else { //height 240 530 tft.drawRect(ii*28+12,jj*28,29,29,color2); 531 tft.drawRect(ii*28+13,jj*28+1,27,27,color); 532 } 533} 534//**************************** 535void showstatus(String s1, String s2, String s3, uint16_t c1=GRAY, uint16_t c2=GRAY, uint16_t c3=GRAY) { 536 tft.setTextWrap(1); 537 tft.setTextColor(GRAY); 538 if (screen_height==320) { 539 tft.setTextSize(2); 540 tft.setCursor(334,213); print_changed(s1,statusbuf1,c1); 541 tft.setCursor(334,233); print_changed(s2,statusbuf2,c2); 542 tft.setCursor(334,253); print_changed(s3,statusbuf3,c3); 543 } else { 544 tft.setTextSize(1); 545 tft.setCursor(244,172); print_changed(s1,statusbuf1,c1); 546 tft.setCursor(244,184); print_changed(s2,statusbuf2,c2); 547 tft.setCursor(244,196); print_changed(s3,statusbuf3,c3); 548 } 549 if (status_c1!=pos[0].cut.c1||status_c2!=pos[0].cut.c2) { 550 if (status_c1!=-1) { status_step(status_c1,0); status_step(status_c2,0); } 551 status_c1=pos[0].cut.c1; 552 status_c2=pos[0].cut.c2; 553 status_step(status_c1,1,getColor(220,0,0)); 554 status_step(status_c2,1,getColor(0,180,0)); 555 } 556} 557//**************************** 558boolean gettouch() { 559 //digitalWrite(13, HIGH); 560 tp = ts.getPoint(); 561 //digitalWrite(13, LOW); 562 // if sharing pins, you'll need to fix the directions of the touchscreen pins 563 pinMode(XM, OUTPUT); 564 pinMode(YP, OUTPUT); 565 int x=map(tp.y,mapx1,mapx2,0,screen_width-1); 566 int y=map(tp.x,mapy1,mapy2,0,screen_height-1); 567 touched=0; 568 if ((abs(x-touchx)>5||abs(y-touchy)>5)&&tp.z>MINPRESSURE&&tp.z<MAXPRESSURE) { 569 touched=1; 570 touchx=x; 571 touchy=y; 572 //tft.drawPixel(x,y,GREEN); 573 //Serial.println(tp.y); 574 //Serial.println(tp.x); 575 } 576 return touched; 577} 578//**************************** 579void erasestatus() { 580 if (status_c1>-1) status_step(status_c1,0); 581 if (status_c2>-1) status_step(status_c2,0); 582 status_c1=-1; 583 status_c2=-1; 584} 585//********************************** 586signed char field_pressed() { 587 signed char c; 588 if (screen_height==320) { 589 c=(touchx-10)/39+8*(touchy/39); 590 } else { 591 c=(touchx-10)/28+8*(touchy/28); 592 } 593 if (c<0||c>63) c=-1; else if (rotate) c=63-c; 594 if (c!=-1&&status_c1==-1) 595 if ((pos[0].w&&pole[c]<=0)||(!pos[0].w&&pole[c]>=0)) c=-1; 596 if (c!=-1&&status_c1!=-1&&c==status_c1) c=-1; 597 //Serial.println(c); 598 return c; 599} 600//**************************** 601void clearmenu() { 602 if (screen_height==320) { 603 tft.fillRect(330,56,135,220,BLACK); 604 tft.fillRect(350,276,115,43,BLACK); 605 } else { 606 tft.fillRect(240,40,80,166,BLACK); 607 tft.fillRect(250,206,69,33,BLACK); 608 } 609} 610//**************************** 611
logic.h
h
1const signed char fp=1; //pawn 2const signed char fn=2; //knight 3const signed char fb=3; //bishop 4const signed char fr=4; //rook 5const signed char fq=5; //queen 6const signed char fk=6; //king 7const int fig_weight[]={0,100,320,330,500,900,0}; 8const char fig_symb[]=" NBRQK"; 9const char fig_symb1[]=" pNBRQK"; 10 11char pole[64]; // 12 13const byte column[64] ={ 14 1, 2, 3, 4, 5, 6, 7, 8, 15 1, 2, 3, 4, 5, 6, 7, 8, 16 1, 2, 3, 4, 5, 6, 7, 8, 17 1, 2, 3, 4, 5, 6, 7, 8, 18 1, 2, 3, 4, 5, 6, 7, 8, 19 1, 2, 3, 4, 5, 6, 7, 8, 20 1, 2, 3, 4, 5, 6, 7, 8, 21 1, 2, 3, 4, 5, 6, 7, 8 22}; 23const byte row[64] = { 24 8, 8, 8, 8, 8, 8, 8, 8, 25 7, 7, 7, 7, 7, 7, 7, 7, 26 6, 6, 6, 6, 6, 6, 6, 6, 27 5, 5, 5, 5, 5, 5, 5, 5, 28 4, 4, 4, 4, 4, 4, 4, 4, 29 3, 3, 3, 3, 3, 3, 3, 3, 30 2, 2, 2, 2, 2, 2, 2, 2, 31 1, 1, 1, 1, 1, 1, 1, 1 32}; 33const byte diag1[64] ={ 34 1, 2, 3, 4, 5, 6, 7, 8, 35 2, 3, 4, 5, 6, 7, 8, 9, 36 3, 4, 5, 6, 7, 8, 9,10, 37 4, 5, 6, 7, 8, 9,10,11, 38 5, 6, 7, 8, 9,10,11,12, 39 6, 7, 8, 9,10,11,12,13, 40 7, 8, 9,10,11,12,13,14, 41 8, 9,10,11,12,13,14,15 42}; 43const byte diag2[64] ={ 44 8, 7, 6, 5, 4, 3, 2, 1, 45 9, 8, 7, 6, 5, 4, 3, 2, 46 10, 9, 8, 7, 6, 5, 4, 3, 47 11,10, 9, 8, 7, 6, 5, 4, 48 12,11,10, 9, 8, 7, 6, 5, 49 13,12,11,10, 9, 8, 7, 6, 50 14,13,12,11,10, 9, 8, 7, 51 15,14,13,12,11,10, 9, 8 52}; 53 54const char polestart[64] PROGMEM={ 55 -fr,-fn,-fb,-fq,-fk,-fb,-fn,-fr, 56 -fp,-fp,-fp,-fp,-fp,-fp,-fp,-fp, 57 0, 0, 0, 0, 0, 0, 0, 0, 58 0, 0, 0, 0, 0, 0, 0, 0, 59 0, 0, 0, 0, 0, 0, 0, 0, 60 0, 0, 0, 0, 0, 0, 0, 0, 61 fp, fp, fp, fp, fp, fp, fp, fp, 62 fr, fn, fb, fq, fk, fb, fn, fr 63}; 64 65const short stat_weightw[7][64] PROGMEM={ 66 { 0, 0, 0, 0, 0, 0, 0, 0, //pawn 67 100,100,100,100,100,100,100,100, // 50, 50, 50, 50, 50, 50, 50, 50, 68 20, 30, 40, 50, 50, 40, 30, 20, // 10, 10, 20, 30, 30, 20, 10, 10, 69 5, 5, 10, 25, 25, 10, 5, 5, 70 0, 0, 0, 20, 20, 0, 0, 0, 71 5, -5,-10, 0, 0,-10, -5, 5, 72 5, 10, 10,-20,-20, 10, 10, 5, // 5, 10, 10,-20,-20, 10, 10, 5, 73 0, 0, 0, 0, 0, 0, 0, 0}, 74 75 {-50,-40,-30,-30,-30,-30,-40,-50, //knife 76 -40,-20, 0, 0, 0, 0,-20,-40, 77 -30, 0, 10, 15, 15, 10, 0,-30, 78 -30, 5, 15, 20, 20, 15, 5,-30, 79 -30, 0, 15, 20, 20, 15, 0,-30, 80 -30, 5, 10, 15, 15, 10, 5,-30, 81 -40,-20, 0, 5, 5, 0,-20,-40, 82 -50,-40,-30,-30,-30,-30,-40,-50}, 83 84 {-20,-10,-10,-10,-10,-10,-10,-20, //bishop 85 -10, 0, 0, 0, 0, 0, 0,-10, 86 -10, 0, 5, 10, 10, 5, 0,-10, 87 -10, 5, 5, 10, 10, 5, 5,-10, 88 -10, 0, 10, 10, 10, 10, 0,-10, 89 -10, 10, 10, 10, 10, 10, 10,-10, 90 -10, 5, 0, 0, 0, 0, 5,-10, 91 -20,-10,-10,-10,-10,-10,-10,-20}, 92 93 { 0, 0, 0, 0, 0, 0, 0, 0, //rook 94 5, 10, 10, 10, 10, 10, 10, 5, 95 -5, 0, 0, 0, 0, 0, 0, -5, 96 -5, 0, 0, 0, 0, 0, 0, -5, 97 -5, 0, 0, 0, 0, 0, 0, -5, 98 -5, 0, 0, 0, 0, 0, 0, -5, 99 -5, 0, 0, 0, 0, 0, 0, -5, 100 0, 0, 0, 5, 5, 0, 0, 0}, 101 102 {-20,-10,-10, -5, -5,-10,-10,-20, //queen 103 -10, 0, 0, 0, 0, 0, 0,-10, 104 -10, 0, 5, 5, 5, 5, 0,-10, 105 -5, 0, 5, 5, 5, 5, 0, -5, 106 0, 0, 5, 5, 5, 5, 0, -5, 107 -10, 5, 5, 5, 5, 5, 0,-10, 108 -10, 0, 5, 0, 0, 0, 0,-10, 109 -20,-10,-10, -5, -5,-10,-10,-20}, 110 111 {-30,-40,-40,-50,-50,-40,-40,-30, //kingw 112 -30,-40,-40,-50,-50,-40,-40,-30, 113 -30,-40,-40,-50,-50,-40,-40,-30, 114 -30,-40,-40,-50,-50,-40,-40,-30, 115 -20,-30,-30,-40,-40,-30,-30,-20, 116 -10,-20,-20,-20,-20,-20,-20,-10, 117 10, 10,-10,-10,-10,-10, 10, 10, 118 10, 40, 30, 0, 0, 0, 50, 10}, 119 120 {-50,-40,-30,-20,-20,-30,-40,-50, //king endspiel 121 -30,-20,-10, 0, 0,-10,-20,-30, 122 -30,-10, 20, 30, 30, 20,-10,-30, 123 -30,-10, 30, 40, 40, 30,-10,-30, 124 -30,-10, 30, 40, 40, 30,-10,-30, 125 -30,-10, 20, 30, 30, 20,-10,-30, 126 -30,-30, 0, 0, 0, 0,-30,-30, 127 -50,-30,-30,-30,-30,-30,-30,-50} 128}; 129 130const short stat_weightb[7][64] PROGMEM={ 131 { 0, 0, 0, 0, 0, 0, 0, 0, //pawn 132 5, 10, 10,-20,-20, 10, 10, 5, 133 5, -5,-10, 0, 0,-10, -5, 5, 134 0, 0, 0, 20, 20, 0, 0, 0, 135 5, 5, 10, 25, 25, 10, 5, 5, 136 20, 30, 40, 50, 50, 40, 30, 20, 137 100,100,100,100,100,100,100,100, 138 0, 0, 0, 0, 0, 0, 0, 0}, 139 140 {-50,-40,-30,-30,-30,-30,-40,-50, //knife 141 -40,-20, 0, 0, 0, 0,-20,-40, 142 -30, 5, 10, 15, 15, 10, 5,-30, 143 -30, 0, 15, 20, 20, 15, 0,-30, 144 -30, 5, 15, 20, 20, 15, 5,-30, 145 -30, 0, 10, 15, 15, 10, 0,-30, 146 -40,-20, 0, 5, 5, 0,-20,-40, 147 -50,-40,-30,-30,-30,-30,-40,-50}, 148 149 {-20,-10,-10,-10,-10,-10,-10,-20, //bishop 150 -10, 5, 0, 0, 0, 0, 5,-10, 151 -10, 10, 10, 10, 10, 10, 10,-10, 152 -10, 0, 10, 10, 10, 10, 0,-10, 153 -10, 5, 5, 10, 10, 5, 5,-10, 154 -10, 0, 5, 10, 10, 5, 0,-10, 155 -10, 0, 0, 0, 0, 0, 0,-10, 156 -20,-10,-10,-10,-10,-10,-10,-20}, 157 158 { 0, 0, 0, 5, 5, 0, 0, 0, //rook 159 -5, 0, 0, 0, 0, 0, 0, -5, 160 -5, 0, 0, 0, 0, 0, 0, -5, 161 -5, 0, 0, 0, 0, 0, 0, -5, 162 -5, 0, 0, 0, 0, 0, 0, -5, 163 -5, 0, 0, 0, 0, 0, 0, -5, 164 5, 10, 10, 10, 10, 10, 10, 5, 165 0, 0, 0, 0, 0, 0, 0, 0}, 166 167 {-20,-10,-10, -5, -5,-10,-10,-20, //queen 168 -10, 0, 5, 0, 0, 0, 0,-10, 169 -10, 5, 5, 5, 5, 5, 0,-10, 170 0, 0, 5, 5, 5, 5, 0, -5, 171 -5, 0, 5, 5, 5, 5, 0, -5, 172 -10, 0, 5, 5, 5, 5, 0,-10, 173 -10, 0, 0, 0, 0, 0, 0,-10, 174 -20,-10,-10, -5, -5,-10,-10,-20}, 175 176 { 10, 40, 30, 0, 0, 0, 50, 10, //kingb 177 10, 10,-10,-10,-10,-10, 10, 10, 178 -10,-20,-20,-20,-20,-20,-20,-10, 179 -20,-30,-30,-40,-40,-30,-30,-20, 180 -30,-40,-40,-50,-50,-40,-40,-30, 181 -30,-40,-40,-50,-50,-40,-40,-30, 182 -30,-40,-40,-50,-50,-40,-40,-30, 183 -30,-40,-40,-50,-50,-40,-40,-30}, 184 185 {-50,-30,-30,-30,-30,-30,-30,-50, //kingb endspiel 186 -30,-30, 0, 0, 0, 0,-30,-30, 187 -30,-10, 20, 30, 30, 20,-10,-30, 188 -30,-10, 30, 40, 40, 30,-10,-30, 189 -30,-10, 30, 40, 40, 30,-10,-30, 190 -30,-10, 20, 30, 30, 20,-10,-30, 191 -30,-20,-10, 0, 0,-10,-20,-30, 192 -50,-40,-30,-20,-20,-30,-40,-50} 193}; 194 195//88 - end of raw 196//99 - end of all 197const byte diag_step[64][17] PROGMEM={ 198 {9,18,27,36,45,54,63,99}, //0 199 {10,19,28,37,46,55,88,8,99}, //1 200 {11,20,29,38,47,88,9,16,99}, //2 201 {12,21,30,39,88,10,17,24,99}, //3 202 {13,22,31,88,11,18,25,32,99}, //4 203 {14,23,88,12,19,26,33,40,99}, //5 204 {15,88,13,20,27,34,41,48,99}, //6 205 {14,21,28,35,42,49,56,99}, //7 206 {17,26,35,44,53,62,88,1,99}, //8 207 {18,27,36,45,54,63,88,16,88,0,88,2,99}, //9 208 {19,28,37,46,55,88,17,24,88,1,88,3,99}, //10 209 {20,29,38,47,88,18,25,32,88,2,88,4,99}, //11 210 {21,30,39,88,19,26,33,40,88,3,88,5,99}, //12 211 {22,31,88,20,27,34,41,48,88,4,88,6,99}, //13 212 {23,88,21,28,35,42,49,56,88,5,88,7,99}, //14 213 {22,29,36,43,50,57,88,6,99}, //15 214 {25,34,43,52,61,88,9,2,99}, //16 215 {26,35,44,53,62,88,24,88,8,88,10,3,99}, //17 216 {27,36,45,54,63,88,25,32,88,9,0,88,11,4,99}, //18 217 {28,37,46,55,88,26,33,40,88,10,1,88,12,5,99}, //19 218 {29,38,47,88,27,34,41,48,88,11,2,88,13,6,99}, //20 219 {30,39,88,28,35,42,49,56,88,12,3,88,14,7,99}, //21 220 {31,88,29,36,43,50,57,88,13,4,88,15,99}, //22 221 {30,37,44,51,58,88,14,5,99}, //23 222 {33,42,51,60,88,17,10,3,99}, //24 223 {34,43,52,61,88,32,88,16,88,18,11,4,99}, //25 224 {35,44,53,62,88,33,40,88,17,8,88,19,12,5,99}, //26 225 {36,45,54,63,88,34,41,48,88,18,9,0,88,20,13,6,99}, //27 226 {37,46,55,88,35,42,49,56,88,19,10,1,88,21,14,7,99}, //28 227 {38,47,88,36,43,50,57,88,20,11,2,88,22,15,99}, //29 228 {39,88,37,44,51,58,88,21,12,3,88,23,99}, //30 229 {38,45,52,59,88,22,13,4,99}, //31 230 {41,50,59,88,25,18,11,4,99}, //32 231 {42,51,60,88,40,88,24,88,26,19,12,5,99}, //33 232 {43,52,61,88,41,48,88,25,16,88,27,20,13,6,99}, //34 233 {44,53,62,88,42,49,56,88,26,17,8,88,28,21,14,7,99}, //35 234 {45,54,63,88,43,50,57,88,27,18,9,0,88,29,22,15,99}, //36 235 {46,55,88,44,51,58,88,28,19,10,1,88,30,23,99}, //37 236 {47,88,45,52,59,88,29,20,11,2,88,31,99}, //38 237 {46,53,60,88,30,21,12,3,99}, //39 238 {49,58,88,33,26,19,12,5,99}, //40 239 {50,59,88,48,88,32,88,34,27,20,13,6,99}, //41 240 {51,60,88,49,56,88,33,24,88,35,28,21,14,7,99}, //42 241 {52,61,88,50,57,88,34,25,16,88,36,29,22,15,99}, //43 242 {53,62,88,51,58,88,35,26,17,8,88,37,30,23,99}, //44 243 {54,63,88,52,59,88,36,27,18,9,0,88,38,31,99}, //45 244 {55,88,53,60,88,37,28,19,10,1,88,39,99}, //46 245 {54,61,88,38,29,20,11,2,99}, //47 246 {57,88,41,34,27,20,13,6,99}, //48 247 {58,88,56,88,40,88,42,35,28,21,14,7,99}, //49 248 {59,88,57,88,41,32,88,43,36,29,22,15,99}, //50 249 {60,88,58,88,42,33,24,88,44,37,30,23,99}, //51 250 {61,88,59,88,43,34,25,16,88,45,38,31,99}, //52 251 {62,88,60,88,44,35,26,17,8,88,46,39,99}, //53 252 {63,88,61,88,45,36,27,18,9,0,88,47,99}, //54 253 {62,88,46,37,28,19,10,1,99}, //55 254 {49,42,35,28,21,14,7,99}, //56 255 {48,88,50,43,36,29,22,15,99}, //57 256 {49,40,88,51,44,37,30,23,99}, //58 257 {50,41,32,88,52,45,38,31,99}, //59 258 {51,42,33,24,88,53,46,39,99}, //60 259 {52,43,34,25,16,88,54,47,99}, //61 260 {53,44,35,26,17,8,88,55,99}, //62 261 {54,45,36,27,18,9,0,99} //63 ++++++ 262}; 263 264const byte stra_step[64][18] PROGMEM={ 265 {1,2,3,4,5,6,7,88,8,16,24,32,40,48,56,99}, //0 266 {2,3,4,5,6,7,88,9,17,25,33,41,49,57,88,0,99}, //1 267 {3,4,5,6,7,88,10,18,26,34,42,50,58,88,1,0,99}, //2 268 {4,5,6,7,88,11,19,27,35,43,51,59,88,2,1,0,99}, //3 269 {5,6,7,88,12,20,28,36,44,52,60,88,3,2,1,0,99}, //4 270 {6,7,88,13,21,29,37,45,53,61,88,4,3,2,1,0,99}, //5 271 {7,88,14,22,30,38,46,54,62,88,5,4,3,2,1,0,99}, //6 272 {15,23,31,39,47,55,63,88,6,5,4,3,2,1,0,99}, //7 273 {9,10,11,12,13,14,15,88,16,24,32,40,48,56,88,0,99}, //8 274 {10,11,12,13,14,15,88,17,25,33,41,49,57,88,8,88,1,99}, //9 275 {11,12,13,14,15,88,18,26,34,42,50,58,88,9,8,88,2,99}, //10 276 {12,13,14,15,88,19,27,35,43,51,59,88,10,9,8,88,3,99}, //11 277 {13,14,15,88,20,28,36,44,52,60,88,11,10,9,8,88,4,99}, //12 278 {14,15,88,21,29,37,45,53,61,88,12,11,10,9,8,88,5,99}, //13 279 {15,88,22,30,38,46,54,62,88,13,12,11,10,9,8,88,6,99}, //14 280 {23,31,39,47,55,63,88,14,13,12,11,10,9,8,88,7,99}, //15 281 {17,18,19,20,21,22,23,88,24,32,40,48,56,88,8,0,99}, //16 282 {18,19,20,21,22,23,88,25,33,41,49,57,88,16,88,9,1,99}, //17 283 {19,20,21,22,23,88,26,34,42,50,58,88,17,16,88,10,2,99}, //18 284 {20,21,22,23,88,27,35,43,51,59,88,18,17,16,88,11,3,99}, //19 285 {21,22,23,88,28,36,44,52,60,88,19,18,17,16,88,12,4,99}, //20 286 {22,23,88,29,37,45,53,61,88,20,19,18,17,16,88,13,5,99}, //21 287 {23,88,30,38,46,54,62,88,21,20,19,18,17,16,88,14,6,99}, //22 288 {31,39,47,55,63,88,22,21,20,19,18,17,16,88,15,7,99}, //23 289 {25,26,27,28,29,30,31,88,32,40,48,56,88,16,8,0,99}, //24 290 {26,27,28,29,30,31,88,33,41,49,57,88,24,88,17,9,1,99}, //25 291 {27,28,29,30,31,88,34,42,50,58,88,25,24,88,18,10,2,99}, //26 292 {28,29,30,31,88,35,43,51,59,88,26,25,24,88,19,11,3,99}, //27 293 {29,30,31,88,36,44,52,60,88,27,26,25,24,88,20,12,4,99}, //28 294 {30,31,88,37,45,53,61,88,28,27,26,25,24,88,21,13,5,99}, //29 295 {31,88,38,46,54,62,88,29,28,27,26,25,24,88,22,14,6,99}, //30 296 {39,47,55,63,88,30,29,28,27,26,25,24,88,23,15,7,99}, //31 297 {33,34,35,36,37,38,39,88,40,48,56,88,24,16,8,0,99}, //32 298 {34,35,36,37,38,39,88,41,49,57,88,32,88,25,17,9,1,99}, //33 299 {35,36,37,38,39,88,42,50,58,88,33,32,88,26,18,10,2,99}, //34 300 {36,37,38,39,88,43,51,59,88,34,33,32,88,27,19,11,3,99}, //35 301 {37,38,39,88,44,52,60,88,35,34,33,32,88,28,20,12,4,99}, //36 302 {38,39,88,45,53,61,88,36,35,34,33,32,88,29,21,13,5,99}, //37 303 {39,88,46,54,62,88,37,36,35,34,33,32,88,30,22,14,6,99}, //38 304 {47,55,63,88,38,37,36,35,34,33,32,88,31,23,15,7,99}, //39 305 {41,42,43,44,45,46,47,88,48,56,88,32,24,16,8,0,99}, //40 306 {42,43,44,45,46,47,88,49,57,88,40,88,33,25,17,9,1,99}, //41 307 {43,44,45,46,47,88,50,58,88,41,40,88,34,26,18,10,2,99}, //42 308 {44,45,46,47,88,51,59,88,42,41,40,88,35,27,19,11,3,99}, //43 309 {45,46,47,88,52,60,88,43,42,41,40,88,36,28,20,12,4,99}, //44 310 {46,47,88,53,61,88,44,43,42,41,40,88,37,29,21,13,5,99}, //45 311 {47,88,54,62,88,45,44,43,42,41,40,88,38,30,22,14,6,99}, //46 312 {55,63,88,46,45,44,43,42,41,40,88,39,31,23,15,7,99}, //47 313 {49,50,51,52,53,54,55,88,56,88,40,32,24,16,8,0,99}, //48 314 {50,51,52,53,54,55,88,57,88,48,88,41,33,25,17,9,1,99}, //49 315 {51,52,53,54,55,88,58,88,49,48,88,42,34,26,18,10,2,99}, //50 316 {52,53,54,55,88,59,88,50,49,48,88,43,35,27,19,11,3,99}, //51 317 {53,54,55,88,60,88,51,50,49,48,88,44,36,28,20,12,4,99}, //52 318 {54,55,88,61,88,52,51,50,49,48,88,45,37,29,21,13,5,99}, //53 319 {55,88,62,88,53,52,51,50,49,48,88,46,38,30,22,14,6,99}, //54 320 {63,88,54,53,52,51,50,49,48,88,47,39,31,23,15,7,99}, //55 321 {57,58,59,60,61,62,63,88,48,40,32,24,16,8,0,99}, //56 322 {58,59,60,61,62,63,88,56,88,49,41,33,25,17,9,1,99}, //57 323 {59,60,61,62,63,88,57,56,88,50,42,34,26,18,10,2,99}, //58 324 {60,61,62,63,88,58,57,56,88,51,43,35,27,19,11,3,99}, //59 325 {61,62,63,88,59,58,57,56,88,52,44,36,28,20,12,4,99}, //60 326 {62,63,88,60,59,58,57,56,88,53,45,37,29,21,13,5,99}, //61 327 {63,88,61,60,59,58,57,56,88,54,46,38,30,22,14,6,99}, //62 328 {62,61,60,59,58,57,56,88,55,47,39,31,23,15,7,99} //63 329}; 330 331const byte knight_step[64][9] PROGMEM={ 332 {10,17,99}, //0 333 {11,18,16,99}, //1 334 {12,19,17,8,99}, //2 335 {13,20,18,9,99}, //3 336 {14,21,19,10,99}, //4 337 {15,22,20,11,99}, //5 338 {23,21,12,99}, //6 339 {22,13,99}, //7 340 {2,18,25,99}, //8 341 {3,19,26,24,99}, //9 342 {4,20,27,25,16,0,99}, //10 343 {5,21,28,26,17,1,99}, //11 344 {6,22,29,27,18,2,99}, //12 345 {7,23,30,28,19,3,99}, //13 346 {31,29,20,4,99}, //14 347 {30,21,5,99}, //15 348 {1,10,26,33,99}, //16 349 {2,11,27,34,32,0,99}, //17 350 {3,12,28,35,33,24,8,1,99}, //18 351 {4,13,29,36,34,25,9,2,99}, //19 352 {5,14,30,37,35,26,10,3,99}, //20 353 {6,15,31,38,36,27,11,4,99}, //21 354 {7,39,37,28,12,5,99}, //22 355 {38,29,13,6,99}, //23 356 {9,18,34,41,99}, //24 357 {10,19,35,42,40,8,99}, //25 358 {11,20,36,43,41,32,16,9,99}, //26 359 {12,21,37,44,42,33,17,10,99}, //27 360 {13,22,38,45,43,34,18,11,99}, //28 361 {14,23,39,46,44,35,19,12,99}, //29 362 {15,47,45,36,20,13,99}, //30 363 {46,37,21,14,99}, //31 364 {17,26,42,49,99}, //32 365 {18,27,43,50,48,16,99}, //33 366 {19,28,44,51,49,40,24,17,99}, //34 367 {20,29,45,52,50,41,25,18,99}, //35 368 {21,30,46,53,51,42,26,19,99}, //36 369 {22,31,47,54,52,43,27,20,99}, //37 370 {23,55,53,44,28,21,99}, //38 371 {54,45,29,22,99}, //39 372 {25,34,50,57,99}, //40 373 {26,35,51,58,56,24,99}, //41 374 {27,36,52,59,57,48,32,25,99}, //42 375 {28,37,53,60,58,49,33,26,99}, //43 376 {29,38,54,61,59,50,34,27,99}, //44 377 {30,39,55,62,60,51,35,28,99}, //45 378 {31,63,61,52,36,29,99}, //46 379 {62,53,37,30,99}, //47 380 {33,42,58,99}, //48 381 {34,43,59,32,99}, //49 382 {35,44,60,56,40,33,99}, //50 383 {36,45,61,57,41,34,99}, //51 384 {37,46,62,58,42,35,99}, //52 385 {38,47,63,59,43,36,99}, //53 386 {39,60,44,37,99}, //54 387 {61,45,38,99}, //55 388 {41,50,99}, //56 389 {40,42,51,99}, //57 390 {43,52,48,41,99}, //58 391 {44,53,49,42,99}, //59 392 {45,54,50,43,99}, //60 393 {46,55,51,44,99}, //61 394 {47,52,45,99}, //62 395 {53,46,99} //63 +++++ 396}; 397 398const byte king_step[64][9] PROGMEM={ 399 {1,9,8,99}, //0 400 {2,10,9,8,0,99}, //1 401 {3,11,10,9,1,99}, //2 402 {4,12,11,10,2,99}, //3 403 {5,13,12,11,3,99}, //4 404 {6,14,13,12,4,99}, //5 405 {7,15,14,13,5,99}, //6 406 {15,14,6,99}, //7 407 {1,9,17,16,0,99}, //8 408 {2,10,18,17,16,8,0,1,99}, //9 409 {3,11,19,18,17,9,1,2,99}, //10 410 {4,12,20,19,18,10,2,3,99}, //11 411 {5,13,21,20,19,11,3,4,99}, //12 412 {6,14,22,21,20,12,4,5,99}, //13 413 {7,15,23,22,21,13,5,6,99}, //14 414 {23,22,14,6,7,99}, //15 415 {9,17,25,24,8,99}, //16 416 {10,18,26,25,24,16,8,9,99}, //17 417 {11,19,27,26,25,17,9,10,99}, //18 418 {12,20,28,27,26,18,10,11,99}, //19 419 {13,21,29,28,27,19,11,12,99}, //20 420 {14,22,30,29,28,20,12,13,99}, //21 421 {15,23,31,30,29,21,13,14,99}, //22 422 {31,30,22,14,15,99}, //23 423 {17,25,33,32,16,99 }, //24 424 {18,26,34,33,32,24,16,17,99}, //25 425 {19,27,35,34,33,25,17,18,99}, //26 426 {20,28,36,35,34,26,18,19,99}, //27 427 {21,29,37,36,35,27,19,20,99}, //28 428 {22,30,38,37,36,28,20,21,99}, //29 429 {23,31,39,38,37,29,21,22,99}, //30 430 {39,38,30,22,23,99}, //31 431 {25,33,41,40,24,99}, //32 432 {26,34,42,41,40,32,24,25,99}, //33 433 {27,35,43,42,41,33,25,26,99}, //34 434 {28,36,44,43,42,34,26,27,99}, //35 435 {29,37,45,44,43,35,27,28,99}, //36 436 {30,38,46,45,44,36,28,29,99}, //37 437 {31,39,47,46,45,37,29,30,99}, //38 438 {47,46,38,30,31,99}, //39 439 {33,41,49,48,32,99}, //40 440 {34,42,50,49,48,40,32,33,99}, //41 441 {35,43,51,50,49,41,33,34,99}, //42 442 {36,44,52,51,50,42,34,35,99}, //43 443 {37,45,53,52,51,43,35,36,99}, //44 444 {38,46,54,53,52,44,36,37,99}, //45 445 {39,47,55,54,53,45,37,38,99}, //46 446 {55,54,46,38,39,99}, //47 447 {41,49,57,56,40,99}, //48 448 {42,50,58,57,56,48,40,41,99}, //49 449 {43,51,59,58,57,49,41,42,99}, //50 450 {44,52,60,59,58,50,42,43,99}, //51 451 {45,53,61,60,59,51,43,44,99}, //52 452 {46,54,62,61,60,52,44,45,99}, //53 453 {47,55,63,62,61,53,45,46,99}, //54 454 {63,62,54,46,47,99}, //55 455 {49,57,48,99}, //56 456 {50,58,56,48,49,99}, //57 457 {51,59,57,49,50,99}, //58 458 {52,60,58,50,51,99}, //59 459 {53,61,59,51,52,99}, //60 460 {54,62,60,52,53,99}, //61 461 {55,63,61,53,54,99}, //62 462 {62,54,55,99} //63 +++++ 463}; 464
ArduinoMegaChess2.ino
arduino
1//ArduinoMega Chess 2.0 2//Sergey Urusov, ususovsv@gmail.com 3#include 4 "wac.h" 5#include "logic.h" 6#include <stdint.h> 7#include <avr/pgmspace.h> 8#include 9 <EEPROM.h> 10 11#define MAXSTEPS 600 //600*7=4200 bytes, 700 - works too 12#define 13 MAXDEPTH 20 //28*20=560 bytes 14 15typedef struct { 16 signed char f1,f2; //figure 17 moved and taken 18 signed char c1,c2; //from and to coordinates 19 signed char 20 typecheck; //check after move &B1000, move type &B111 1-En Passant,2-king castle,3-quween 21 castle,4-5-6-7-promotion to khight,bishop,rook,queen 22 short weight; //position 23 weight 24} step_t; 25 26step_t steps[MAXSTEPS]; //moves massive include solving 27 tree 28short ply; //number of halfstep in match, started with 0 29 30struct position_t 31 { 32 byte w; //white to move 1, black - 0 33 byte wrk, wrq, brk, brq; //castle 34 ability 35 byte pp; //number of field 1..63 of last two squares pawn move 36 37 short b_step; //number of levels first move 38 short l_step; //quantity of moves 39 on level 40 short cur_step; //current move on level 41 short best_step; //best 42 move on level 43 step_t cut; //move for sorting (cut alpha-beta) 44 byte check_on_table; 45 //moving side under check 46 short weight_w; //weight of white figures 47 48 short weight_b; //weight of black figures 49 short weight_s; //statistic estimation 50 of position, in favor of whites + 51} pos[MAXDEPTH]; 52 53 54struct startpos_t 55 { 56 byte w; 57 byte wrk, wrq, brk, brq; 58 byte pp; 59 char pole[64]; 60 61 int ply; 62} startpos; 63 64byte poswk=0; //white king field 65byte 66 posbk=0; //black king field 67 68int level; //number of current level of solving 69 tree 70unsigned long timelimith=5000; //limith of thinking time in ms 71const 72 int limits[10]={5,10,30,60,120,180,300,600,1800,3600}; 73const char* limitstrings[10]={"5 74 sec","10 sec","30 sec","1 min","2 min","3 min","5 min","10 min","30 75 min","1 hr"}; 76byte limit=0; 77unsigned long starttime; 78boolean endspiel=0; 79boolean 80 halt=0; 81unsigned long count=0; 82int depth; 83boolean TRACE=0; 84int maxstep; 85boolean 86 solving=0; 87boolean gameover=0; 88boolean autow=0; 89boolean autob=1; 90boolean 91 debute; 92 93String str_step(step_t); 94#include "gui.h" 95 96//**************************** 97void 98 new_game(String fen="") { 99 if (fen=="") fen=F("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR 100 w KQkq -"); // 101 fenload(fen); 102 for (int i=0;i<64;i++) startpos.pole[i]=pole[i]; 103 104 startpos.w=pos[0].w; 105 startpos.wrk=pos[0].wrk; 106 107 startpos.wrq=pos[0].wrq; 108 109 startpos.brk=pos[0].brk; 110 startpos.brq=pos[0].brq; 111 112 startpos.w=pos[0].w; 113 startpos.pp=pos[0].pp; 114 115 startpos.ply=ply; 116 kingpositions(); 117} 118//**************************** 119void 120 setup() { 121 Serial.begin(115200); 122 while (!Serial) ; 123 Serial.println(F("Start")); 124 125 new_game(); 126 cleardisplayboard(); 127 if (!rotate) { autow=0; autob=1; 128 } else { autow=1; autob=0; } 129 guistart(); 130 clearstatus(); 131 132 //wactest(); 133 Serial.println(F("Command:")); 134} 135//**************************** 136void 137 start_game() { 138 for (int i=0;i<64;i++) pole[i]=startpos.pole[i]; 139 pos[0].w=startpos.w; 140 141 pos[0].wrk=startpos.wrk; 142 143 pos[0].wrq=startpos.wrq; 144 pos[0].brk=startpos.brk; 145 146 pos[0].brq=startpos.brq; 147 148 pos[0].w=startpos.w; 149 pos[0].pp=startpos.pp; 150 ply=startpos.ply; 151 152 kingpositions(); 153} 154//********************************** 155boolean 156 fenload(String ss) { 157 char s='x',i=0,j=0; boolean load=false; 158 for (int 159 i=0;i<64;i++) pole[i]=0; 160 pos[0].w=1; 161 pos[0].wrk=0; 162 pos[0].wrq=0; pos[0].brk=0; pos[0].brq=0; 163 pos[0].pp=0; 164 pos[0].cur_step=0; 165 pos[0].b_step=MAXDEPTH; pos[0].l_step=0; 166 int spaces=0; 167 for (int 168 c=0; c<ss.length(); c++) { 169 s=ss[c]; 170 if (i>7) { i=0; j++; } 171 172 if (spaces==3&&int(s)>='a'&&int(s)<='h') { 173 c++; 174 175 char s1=ss[c]; 176 if (int(s1)>='1'&&int(s1)<='8') { 177 pos[0].pp=8*(7-(int(s1)-int('1')))+int(s)-int('a'); 178 179 } 180 } else { 181 int l=j*8+i; 182 switch (s) { 183 184 case '/': i=0; break; 185 case 'p': pole[l]=-fp; i++; break; 186 case 187 'P': pole[l]=fp; i++; break; 188 case 'n': pole[l]=-fn; i++; break; 189 case 190 'N': pole[l]=fn; i++; break; 191 case 'b': if (spaces==0) { pole[l]=-fb; i++; 192 } else 193 if (spaces==1) { pos[0].w=0; load=true; } 194 195 break; 196 case 'B': pole[l]=fb; i++; break; 197 case 'r': 198 pole[l]=-fr; i++; break; 199 case 'R': pole[l]=fr; i++; break; 200 case 'q': 201 if (spaces==0) { pole[l]=-fq; i++; } else pos[0].brq=1; 202 break; 203 204 case 'Q': if (spaces==0) { pole[l]=fq; i++; } else pos[0].wrq=1; 205 break; 206 207 case 'k': if (spaces==0) { pole[l]=-fk; i++; } else pos[0].brk=1; 208 break; 209 210 case 'K': if (spaces==0) { pole[l]=fk; i++; } else pos[0].wrk=1; 211 break; 212 213 case '1': i++; break; 214 case '2': i+=2; break; 215 case '3': i+=3; break; 216 217 case '4': i+=4; break; 218 case '5': i+=5; break; 219 case '6': i+=6; 220 break; 221 case '7': i+=7; break; 222 case '8': i=0; j++; break; 223 case 224 ' ': spaces++; break; 225 case 'w': if (spaces==1) { pos[0].w=1; load=true; 226 } break; 227 } 228 } 229 if (spaces==4) break; 230 231 } 232 if (!load) Serial.println(F("Error")); 233 if (pos[0].w) ply=0; else 234 ply=1; 235 steps[0].f1=0; steps[1].f1=0; 236 return load; 237} 238//**************************** 239void 240 show_position() { 241 for (int i=0;i<8;i++) { 242 Serial.println(F("-----------------------------------------")); 243 244 Serial.print("|"); 245 for (int j=0;j<8;j++) { 246 247 signed char f=pole[i*8+j]; 248 if (f>=0) { Serial.print(" 249 "); Serial.print(fig_symb1[f]); Serial.print(" |"); } 250 251 else { Serial.print(" -"); Serial.print(fig_symb1[-f]); Serial.print(" 252 |"); } 253 } 254 Serial.print(" "); 255 256 Serial.println(8-i); 257 } 258 Serial.println(F("-----------------------------------------")); 259 260 Serial.print(F(" a b c d e f g h ")); 261 262 if (pos[0].w==0) Serial.print(F("Black")); else Serial.print(F("White")); 263 264 Serial.println(); 265} 266//**************************** 267String 268 str_pole(int i) { 269 return String(char('a'+i%8)+String(8-i/8)); 270} 271//**************************** 272String 273 str_step(step_t st) { 274 String s=""; 275 if (st.f1==0) return s; 276 if 277 ((st.typecheck&B111)==2) s="0-0"; 278 else if ((st.typecheck&B111)==3) s="0-0-0"; 279 280 else { 281 if (abs(st.f1)>1) s=s+fig_symb[abs(st.f1)]; 282 s=s+str_pole(st.c1); 283 284 if (st.f2==0) s=s+"-"; 285 if (st.f2!=0) s=s+"x"; 286 287 s=s+str_pole(st.c2); 288 } 289 if ((st.typecheck&B111)>3) s=s+"="+fig_symb[(st.typecheck&B111)-2]; 290 291 if (st.typecheck&B1000) s=s+"+"; 292 return s; 293} 294//**************************** 295void 296 show_steps(int l) { 297 Serial.print(F("Steps=")); Serial.println(String(pos[l].l_step-pos[l].b_step)); 298 299 for (int i=pos[l].b_step;i<pos[l].l_step;i++) { 300 Serial.print(str_step(steps[i])); 301 Serial.print(" "); Serial.print(steps[i].weight); Serial.print(F(" ")); 302 303 if ((i+1)%3==0) Serial.println(); 304 } 305 Serial.println(); 306} 307//**************************** 308 309//**************************** 310//**************************** 311//**************************** 312 313//**************************** 314//**************************** 315//**************************** 316 317void movestep(int l, step_t &s) { 318 pole[s.c1]=0; 319 pole[s.c2]=s.f1; 320 321 if (pos[l].w) { //white to move 322 if (s.f1==fk) poswk=s.c2; 323 324 switch (s.typecheck&B111) { 325 case 0: 326 return; 327 case 328 1: //En Passant 329 pole[s.c2+8]=0; 330 break; 331 case 2: //short castle 332 333 pole[60]=0; 334 pole[61]=fr; 335 pole[62]=fk; 336 pole[63]=0; 337 338 poswk=62; 339 break; 340 case 3: //long castle 341 pole[60]=0; 342 343 pole[59]=fr; 344 pole[58]=fk; 345 pole[57]=0; 346 pole[56]=0; 347 348 poswk=58; 349 break; 350 default: 351 pole[s.c2]=(s.typecheck&B111)-2; 352 353 } 354 } else { //black to move 355 if (s.f1==-fk) posbk=s.c2; 356 357 switch ((s.typecheck&B111)) { 358 case 0: 359 return; 360 case 361 1: //En Passant 362 pole[s.c2-8]=0; 363 break; 364 case 2: //short castle 365 366 pole[4]=0; 367 pole[5]=-fr; 368 pole[6]=-fk; 369 pole[7]=0; 370 posbk=6; 371 372 break; 373 case 3: //long castle 374 pole[4]=0; 375 pole[3]=-fr; 376 377 pole[2]=-fk; 378 pole[1]=0; 379 pole[0]=0; 380 posbk=2; 381 382 break; 383 default: 384 pole[s.c2]=2-(s.typecheck&B111); 385 } 386 } 387 388} 389//**************************** 390void backstep(int l, step_t &s) 391 { 392 pole[s.c1]=s.f1; 393 pole[s.c2]=s.f2; 394 if (pos[l].w) { //white 395 to move 396 if (s.f1==fk) poswk=s.c1; 397 switch (s.typecheck&B111) { 398 case 399 0: return; 400 case 1: //En Passant 401 pole[s.c2]=0; 402 pole[s.c2+8]=-fp; 403 404 break; 405 case 2: //short castle 406 pole[60]=fk; 407 pole[61]=0; 408 409 pole[62]=0; 410 pole[63]=fr; 411 poswk=60; 412 break; 413 case 414 3: //long castle 415 pole[60]=fk; 416 pole[59]=0; 417 pole[58]=0; 418 pole[57]=0; 419 420 pole[56]=fr; 421 poswk=60; 422 break; 423 } 424 } else { //black 425 to move 426 if (s.f1==-fk) posbk=s.c1; 427 switch (s.typecheck&B111) { 428 case 429 0: return; 430 case 1: //En Passant 431 pole[s.c2]=0; 432 pole[s.c2-8]=fp; 433 434 break; 435 case 2: //short castle 436 pole[4]=-fk; 437 pole[5]=0; 438 439 pole[6]=0; 440 pole[7]=-fr; 441 posbk=4; 442 break; 443 case 444 3: //long castle 445 pole[4]=-fk; 446 pole[3]=0; 447 pole[2]=0; 448 pole[1]=0; 449 450 pole[0]=-fr; 451 posbk=4; 452 break; 453 } 454 } 455} 456//**************************** 457 458void movepos(int l, step_t &s) { 459 pos[l+1].wrk=pos[l].wrk; pos[l+1].wrq=pos[l].wrq; 460 461 pos[l+1].brk=pos[l].brk; pos[l+1].brq=pos[l].brq; 462 pos[l+1].pp=0; 463 464 if (pos[l].w) { // 465 if (pos[l].wrk||pos[l].wrq) { 466 if (s.c1==60) { 467 468 pos[l+1].wrk=0; pos[l+1].wrq=0; 469 } else if (s.c1==63) pos[l+1].wrk=0; 470 471 else if (s.c1==56) pos[l+1].wrq=0; 472 } 473 if ((s.typecheck&B111)==0&&s.f1==fp&&s.c2==s.c1-16) 474 475 if (column[s.c2]>1&&pole[s.c2-1]==-fp||column[s.c2]<8&&pole[s.c2+1]==-fp) 476 pos[l+1].pp=s.c1-8; 477 pos[l+1].weight_w=pos[l].weight_w; pos[l+1].weight_b=pos[l].weight_b; 478 479 if (s.f2!=0) pos[l+1].weight_b-=fig_weight[-s.f2]; 480 if ((s.typecheck&B111)>3) 481 pos[l+1].weight_w+=fig_weight[(s.typecheck&B111)-2]-100; 482 if (s.f1==fk&&endspiel) 483 484 pos[l+1].weight_s=pos[l].weight_s+(int)pgm_read_word(&stat_weightw[6][s.c2])-(int)pgm_read_word(&stat_weightw[6][s.c1]); 485 486 else 487 pos[l+1].weight_s=pos[l].weight_s+(int)pgm_read_word(&stat_weightw[s.f1-1][s.c2])-(int)pgm_read_word(&stat_weightw[s.f1-1][s.c1]); 488 489 if (s.f2!=0) pos[l+1].weight_s+=(int)pgm_read_word(&stat_weightb[-s.f2-1][s.c2]); 490 491 } else { // 492 if (pos[l].brk||pos[l].brq) { 493 if (s.c1==4) { 494 495 pos[l+1].brk=0; pos[l+1].brq=0; 496 } else if (s.c1==7) pos[l+1].brk=0; 497 498 else if (s.c1==0) pos[l+1].brq=0; 499 } 500 if ((s.typecheck&B111)==0&&s.f1==-fp&&s.c2==s.c1+16) 501 502 if (column[s.c2]>1&&pole[s.c2-1]==fp||column[s.c2]<8&&pole[s.c2+1]==fp) 503 pos[l+1].pp=s.c1+8; 504 pos[l+1].weight_w=pos[l].weight_w; pos[l+1].weight_b=pos[l].weight_b; 505 506 if (s.f2!=0) pos[l+1].weight_w-=fig_weight[s.f2]; 507 if ((s.typecheck&&B111)>3) 508 pos[l+1].weight_b+=fig_weight[(s.typecheck&B111)-2]-100; 509 if (s.f1==-fk&&endspiel) 510 511 pos[l+1].weight_s=pos[l].weight_s-(int)pgm_read_word(&stat_weightb[6][s.c2])+(int)pgm_read_word(&stat_weightb[6][s.c1]); 512 513 else 514 pos[l+1].weight_s=pos[l].weight_s-(int)pgm_read_word(&stat_weightb[-s.f1-1][s.c2])+(int)pgm_read_word(&stat_weightb[-s.f1-1][s.c1]); 515 516 if (s.f2!=0) pos[l+1].weight_s-=(int)pgm_read_word(&stat_weightw[s.f2-1][s.c2]); 517 518 } 519 count++; //estimated positions count 520} 521//**************************** 522 523boolean check_w() { 524 signed char f2=0; 525 int j=0; 526 if (pole[poswk]!=fk) 527 { 528 for (int i=0;i<64;i++) if (pole[i]==fk) { poswk=i; break; } 529 530 } 531 while (pgm_read_byte(&diag_step[poswk][j])!=99) { 532 533 if (pgm_read_byte(&diag_step[poswk][j])==88) f2=0; 534 else if (f2==0) { 535 536 f2=pole[pgm_read_byte(&diag_step[poswk][j])]; 537 if (f2==-fb||f2==-fq) 538 return(true); 539 } 540 j++; 541 } 542 f2=0; j=0; 543 while (pgm_read_byte(&stra_step[poswk][j])!=99) 544 { 545 if (pgm_read_byte(&stra_step[poswk][j])==88) f2=0; 546 547 else if (f2==0) { 548 f2=pole[pgm_read_byte(&stra_step[poswk][j])]; 549 550 if (f2==-fr||f2==-fq) return(true); 551 if (j==0||pgm_read_byte(&stra_step[poswk][j])==88) 552 553 if (f2==-fk) return(true); 554 } 555 j++; 556 } 557 j=0; 558 while 559 (pgm_read_byte(&knight_step[poswk][j])!=99) { 560 if (pole[pgm_read_byte(&knight_step[poswk][j])]==-fn) 561 return(true); 562 j++; 563 } 564 if (row[poswk]<7) { 565 if 566 (column[poswk]>1&&pole[poswk-9]==-fp) return(true); 567 if (column[poswk]<8&&pole[poswk-7]==-fp) 568 return(true); 569 } 570 j=0; 571 while (pgm_read_byte(&king_step[poswk][j])!=99) 572 { 573 if (pole[pgm_read_byte(&king_step[poswk][j])]==-fk) return(true); 574 575 j++; 576 } 577 return(false); 578} 579//**************************** 580boolean 581 check_b() { 582 signed char f2=0; 583 int j=0; 584 if (pole[posbk]!=-fk) { 585 586 for (int i=0;i<64;i++) if (pole[i]==-fk) { posbk=i; break; } 587 588 } 589 while (pgm_read_byte(&diag_step[posbk][j])!=99) { 590 591 if (pgm_read_byte(&diag_step[posbk][j])==88) f2=0; 592 else if (f2==0) { 593 594 f2=pole[pgm_read_byte(&diag_step[posbk][j])]; 595 if (f2==fb||f2==fq) 596 return(true); 597 } 598 j++; 599 } 600 f2=0; j=0; 601 while (pgm_read_byte(&stra_step[posbk][j])!=99) 602 { 603 if (pgm_read_byte(&stra_step[posbk][j])==88) f2=0; 604 605 else if (f2==0) { 606 f2=pole[pgm_read_byte(&stra_step[posbk][j])]; 607 608 if (f2==fr||f2==fq) return(true); 609 if (j==0||pgm_read_byte(&stra_step[posbk][j])==88) 610 611 if (f2==fk) return(true); 612 } 613 j++; 614 } 615 j=0; 616 while 617 (pgm_read_byte(&knight_step[posbk][j])!=99) { 618 if (pole[pgm_read_byte(&knight_step[posbk][j])]==fn) 619 return(true); 620 j++; 621 } 622 if (row[posbk]>2) { 623 624 if (column[posbk]>1&&pole[posbk+7]==fp) return(true); 625 if (column[posbk]<8&&pole[posbk+9]==fp) 626 return(true); 627 } 628 j=0; 629 while (pgm_read_byte(&king_step[posbk][j])!=99) 630 { 631 if (pole[pgm_read_byte(&king_step[posbk][j])]==fk) return(true); 632 633 j++; 634 } 635 return(false); 636} 637//**************************** 638 639//**************************** 640void 641 add_king(int l, int i) { 642 signed char f1=pole[i]; 643 signed char f2; 644 int 645 j=0; 646 while (pgm_read_byte(&king_step[i][j])!=99) { 647 f2=pole[pgm_read_byte(&king_step[i][j])]; 648 649 if (f2==0||f2<0&&f1>0||f2>0&&f1<0) { 650 steps[pos[l].l_step].typecheck=0; 651 652 steps[pos[l].l_step].c1=i; 653 steps[pos[l].l_step].c2=pgm_read_byte(&king_step[i][j]); 654 655 steps[pos[l].l_step].f1=f1; 656 steps[pos[l].l_step].f2=f2; 657 658 pos[l].l_step++; 659 } 660 j++; 661 662 } 663} 664//**************************** 665void add_knight(int l, int i) 666 { 667 signed char f1=pole[i]; 668 signed char f2; 669 int j=0; 670 while (pgm_read_byte(&knight_step[i][j])!=99) 671 { 672 f2=pole[pgm_read_byte(&knight_step[i][j])]; 673 if 674 (f2==0||f2<0&&f1>0||f2>0&&f1<0) { 675 steps[pos[l].l_step].typecheck=0; 676 677 steps[pos[l].l_step].c1=i; 678 steps[pos[l].l_step].c2=pgm_read_byte(&knight_step[i][j]); 679 680 steps[pos[l].l_step].f1=f1; 681 steps[pos[l].l_step].f2=f2; 682 683 pos[l].l_step++; 684 } 685 j++; 686 687 } 688} 689//**************************** 690void add_stra(int l, int i) { 691 692 signed char f1=pole[i]; 693 signed char f2=0; 694 int j=0; 695 while (pgm_read_byte(&stra_step[i][j])!=99) 696 { 697 if (pgm_read_byte(&stra_step[i][j])==88) f2=0; 698 else 699 if (f2==0) { 700 f2=pole[pgm_read_byte(&stra_step[i][j])]; 701 if 702 (f2==0||f2<0&&f1>0||f2>0&&f1<0) { 703 steps[pos[l].l_step].typecheck=0; 704 705 steps[pos[l].l_step].c1=i; 706 steps[pos[l].l_step].c2=pgm_read_byte(&stra_step[i][j]); 707 708 steps[pos[l].l_step].f1=f1; 709 steps[pos[l].l_step].f2=f2; 710 711 712 pos[l].l_step++; 713 } 714 715 } 716 j++; 717 } 718} 719//**************************** 720void add_diag(int 721 l, int i) { 722 signed char f1=pole[i]; 723 signed char f2=0; 724 int j=0; 725 726 while (pgm_read_byte(&diag_step[i][j])!=99) { 727 if (pgm_read_byte(&diag_step[i][j])==88) 728 f2=0; 729 else if (f2==0) { 730 f2=pole[pgm_read_byte(&diag_step[i][j])]; 731 732 if (f2==0||f2<0&&f1>0||f2>0&&f1<0) { 733 steps[pos[l].l_step].typecheck=0; 734 735 steps[pos[l].l_step].c1=i; 736 steps[pos[l].l_step].c2=pgm_read_byte(&diag_step[i][j]); 737 738 steps[pos[l].l_step].f1=f1; 739 steps[pos[l].l_step].f2=f2; 740 741 pos[l].l_step++; 742 } 743 } 744 745 j++; 746 } 747} 748//**************************** 749void add_one(int l, 750 int c1, int c2) { 751 steps[pos[l].l_step].typecheck=0; 752 steps[pos[l].l_step].c1=c1; 753 754 steps[pos[l].l_step].c2=c2; 755 steps[pos[l].l_step].f1=pole[c1]; 756 757 steps[pos[l].l_step].f2=pole[c2]; 758 pos[l].l_step++; 759} 760//**************************** 761void 762 sort_steps(int l) { //moves massive sort by weight 763step_t buf; 764 for (int 765 i=pos[l].b_step;i<pos[l].l_step-1;i++) { 766 int maxweight=steps[i].weight; 767 768 int maxj=i; 769 for (int j=i+1;j<pos[l].l_step;j++) { 770 if (steps[j].weight>maxweight) 771 { 772 maxweight=steps[j].weight; maxj=j; 773 } 774 } 775 if 776 (maxweight==0&&l>0) return; 777 if (maxj==i) continue; 778 buf=steps[i]; 779 780 steps[i]=steps[maxj]; 781 steps[maxj]=buf; 782 } 783} 784//**************************** 785 786void generate_steps(int l) { 787 if (l>0) pos[l].b_step=pos[l-1].l_step; 788 else pos[l].b_step=ply+MAXDEPTH; 789 pos[l].cur_step=pos[l].b_step; pos[l].l_step=pos[l].b_step; 790 791 int check; 792 signed char f; 793 if (pole[poswk]!=fk) { 794 for 795 (int i=0;i<64;i++) if (pole[i]==fk) { poswk=i; break; } 796 } 797 if (pole[posbk]!=-fk) 798 { 799 for (int i=0;i<64;i++) if (pole[i]==-fk) { posbk=i; break; } 800 801 } 802 if (l>0) { 803 if ((steps[pos[l-1].cur_step].typecheck&B1000)==0) { 804 805 if (pos[l].w) pos[l].check_on_table=check_w(); else pos[l].check_on_table=check_b(); 806 807 if (pos[l].check_on_table) steps[pos[l-1].cur_step].typecheck=steps[pos[l-1].cur_step].typecheck|B1000; 808 809 } else pos[l].check_on_table=1; 810 } else if (pos[0].w) pos[0].check_on_table=check_w(); 811 else pos[0].check_on_table=check_b(); 812 for (int ii=0;ii<64;ii++) { 813 814 int i; 815 if (pos[l].w) i=ii; else i=63-ii; 816 f=pole[i]; 817 if (f==0||f<0&&pos[l].w||f>0&&!pos[l].w) 818 continue; 819 if (pos[l].l_step>MAXSTEPS-30) break; 820 switch (abs(f)) { 821 822 case fn: add_knight(l,i);break; 823 case fb: add_diag(l,i); break; 824 case 825 fr: add_stra(l,i); break; 826 case fq: add_stra(l,i); add_diag(l,i); break; 827 828 } 829 } 830 for (int ii=0;ii<64;ii++) { 831 int i; 832 if (pos[l].w) 833 i=ii; else i=63-ii; 834 f=pole[i]; 835 if (f==0||f<0&&pos[l].w||f>0&&!pos[l].w) 836 continue; 837 if (pos[l].l_step>MAXSTEPS-30) break; 838 switch (abs(f)) { 839 840 case fk: add_king(l,i); break; 841 case fp: 842 if (f==fp) 843 { 844 if (row[i]<7&&pole[i-8]==0) add_one(l,i,i-8); 845 if (row[i]==2&&pole[i-8]==0&&pole[i-16]==0) 846 add_one(l,i,i-16); 847 if (row[i]==7) { 848 if (pole[i-8]==0) 849 { 850 add_one(l,i,i-8); steps[pos[l].l_step-1].typecheck=4; 851 add_one(l,i,i-8); 852 steps[pos[l].l_step-1].typecheck=5; 853 add_one(l,i,i-8); steps[pos[l].l_step-1].typecheck=6; 854 855 add_one(l,i,i-8); steps[pos[l].l_step-1].typecheck=7; 856 857 } 858 if (column[i]>1&&pole[i-9]<0) { 859 add_one(l,i,i-9); 860 steps[pos[l].l_step-1].typecheck=4; 861 add_one(l,i,i-9); steps[pos[l].l_step-1].typecheck=5; 862 863 add_one(l,i,i-9); steps[pos[l].l_step-1].typecheck=6; 864 865 add_one(l,i,i-9); steps[pos[l].l_step-1].typecheck=7; 866 867 } 868 if (column[i]<8&&pole[i-7]<0) { 869 add_one(l,i,i-7); 870 steps[pos[l].l_step-1].typecheck=4; 871 add_one(l,i,i-7); steps[pos[l].l_step-1].typecheck=5; 872 873 add_one(l,i,i-7); steps[pos[l].l_step-1].typecheck=6; 874 875 add_one(l,i,i-7); steps[pos[l].l_step-1].typecheck=7; 876 } 877 878 } else { 879 if (column[i]>1&&pole[i-9]<0) add_one(l,i,i-9); 880 881 if (column[i]<8&&pole[i-7]<0) add_one(l,i,i-7); 882 } 883 884 } else if (f==-fp) { 885 if (row[i]>2&&pole[i+8]==0) add_one(l,i,i+8); 886 887 if (row[i]==7&&pole[i+8]==0&&pole[i+16]==0) add_one(l,i,i+16); 888 if 889 (row[i]==2) { 890 if (pole[i+8]==0) { 891 add_one(l,i,i+8); steps[pos[l].l_step-1].typecheck=4; 892 893 add_one(l,i,i+8); steps[pos[l].l_step-1].typecheck=5; 894 895 add_one(l,i,i+8); steps[pos[l].l_step-1].typecheck=6; 896 add_one(l,i,i+8); 897 steps[pos[l].l_step-1].typecheck=7; 898 } 899 if (column[i]>1&&pole[i+7]>0) 900 { 901 add_one(l,i,i+7); steps[pos[l].l_step-1].typecheck=4; 902 add_one(l,i,i+7); 903 steps[pos[l].l_step-1].typecheck=5; 904 add_one(l,i,i+7); steps[pos[l].l_step-1].typecheck=6; 905 906 add_one(l,i,i+7); steps[pos[l].l_step-1].typecheck=7; 907 908 } 909 if (column[i]<8&&pole[i+9]>0) { 910 add_one(l,i,i+9); 911 steps[pos[l].l_step-1].typecheck=4; 912 add_one(l,i,i+9); steps[pos[l].l_step-1].typecheck=5; 913 914 add_one(l,i,i+9); steps[pos[l].l_step-1].typecheck=6; 915 916 add_one(l,i,i+9); steps[pos[l].l_step-1].typecheck=7; 917 918 } 919 } else { 920 if (column[i]>1&&pole[i+7]>0) add_one(l,i,i+7); 921 922 if (column[i]<8&&pole[i+9]>0) add_one(l,i,i+9); 923 } 924 925 } 926 } //switch 927 } // 928 929 if (pos[l].pp!=0&&pole[pos[l].pp]==0) 930 { //en passant !!! 931 if (pos[l].w==1) { 932 if (column[pos[l].pp]>1&&pole[pos[l].pp+7]==fp) 933 { add_one(l,pos[l].pp+7,pos[l].pp); steps[pos[l].l_step-1].typecheck=1; steps[pos[l].l_step-1].f2=-fp;} 934 935 if (column[pos[l].pp]<8&&pole[pos[l].pp+9]==fp) { add_one(l,pos[l].pp+9,pos[l].pp); 936 steps[pos[l].l_step-1].typecheck=1; steps[pos[l].l_step-1].f2=-fp;} 937 } else 938 { 939 if (column[pos[l].pp]>1&&pole[pos[l].pp-9]==-fp) { add_one(l,pos[l].pp-9,pos[l].pp); 940 steps[pos[l].l_step-1].typecheck=1; steps[pos[l].l_step-1].f2=fp;} 941 if (column[pos[l].pp]<8&&pole[pos[l].pp-7]==-fp) 942 { add_one(l,pos[l].pp-7,pos[l].pp); steps[pos[l].l_step-1].typecheck=1; steps[pos[l].l_step-1].f2=fp;} 943 944 } 945 } 946 947 if (pos[l].w==1&&!pos[l].check_on_table) { //white catle 948 949 if (pos[l].wrk) { //short 950 if (pole[60]==fk&&pole[61]==0&&pole[62]==0&&pole[63]==fr) 951 { 952 pole[60]=0; pole[61]=fk; poswk=61; check=check_w(); pole[60]=fk; poswk=60; 953 pole[61]=0; 954 if (!check) { 955 steps[pos[l].l_step].typecheck=2; 956 957 steps[pos[l].l_step].c1=60; 958 steps[pos[l].l_step].c2=62; 959 960 steps[pos[l].l_step].f1=fk; 961 steps[pos[l].l_step].f2=0; 962 963 pos[l].l_step++; 964 } 965 } 966 967 } 968 if (pos[l].wrq) { //long 969 if (pole[60]==fk&&pole[59]==0&&pole[58]==0&&pole[57]==0&&pole[56]==fr) 970 { 971 pole[60]=0; pole[59]=fk; poswk=59; check=check_w(); pole[60]=fk; poswk=60; 972 pole[59]=0; 973 if (!check) { 974 steps[pos[l].l_step].typecheck=3; 975 976 steps[pos[l].l_step].c1=60; 977 steps[pos[l].l_step].c2=58; 978 979 steps[pos[l].l_step].f1=fk; 980 steps[pos[l].l_step].f2=0; 981 982 pos[l].l_step++; 983 } 984 } 985 986 } 987 } else if (pos[l].w==0&&!pos[l].check_on_table) { //black castle 988 if 989 (pos[l].brk) { //short 990 if (pole[4]==-fk&&pole[5]==0&&pole[6]==0&&pole[7]==-fr) 991 { 992 pole[4]=0; pole[5]=-fk; posbk=5; check=check_b(); pole[4]=-fk; posbk=4; 993 pole[5]=0; 994 if (!check) { 995 steps[pos[l].l_step].typecheck=2; 996 997 steps[pos[l].l_step].c1=4; 998 steps[pos[l].l_step].c2=6; 999 1000 steps[pos[l].l_step].f1=-fk; 1001 steps[pos[l].l_step].f2=0; 1002 1003 pos[l].l_step++; 1004 } 1005 } 1006 1007 } 1008 if (pos[l].brq) { //long 1009 if (pole[4]==-fk&&pole[3]==0&&pole[2]==0&&pole[1]==0&&pole[0]==-fr) 1010 { 1011 pole[4]=0; pole[3]=-fk; posbk=3; check=check_b(); pole[4]=-fk; posbk=4; 1012 pole[3]=0; 1013 if (!check) { 1014 steps[pos[l].l_step].typecheck=3; 1015 1016 steps[pos[l].l_step].c1=4; 1017 steps[pos[l].l_step].c2=2; 1018 1019 steps[pos[l].l_step].f1=-fk; 1020 steps[pos[l].l_step].f2=0; 1021 1022 pos[l].l_step++; 1023 } 1024 } 1025 1026 } 1027 } 1028 for (int i=pos[l].b_step;i<pos[l].l_step;i++) { 1029 steps[i].typecheck=steps[i].typecheck&B111; 1030 1031 steps[i].weight=abs(steps[i].f2); 1032 if (abs(steps[i].typecheck&&B111)>3) 1033 steps[i].weight+=fig_weight[abs(steps[i].typecheck&&B111)-2]; 1034 steps[i].weight<<=2; 1035 1036 if (l>0) { //add to weight of best level move 1037 if (pos[l].cut.c2==steps[i].c2&&pos[l].cut.c1==steps[i].c1) 1038 steps[i].weight+=5; //best move 1039 if (steps[i].c2==steps[pos[l-1].cur_step].c2) 1040 steps[i].weight+=8; //taking last moves figure 1041 } 1042 } 1043 //i 1044 sort_steps(l); 1045 1046} 1047//**************************** 1048int 1049 evaluate(int l) { //calculating position weight proportional 1050int res; 1051 if 1052 (pos[l].w) res=5000L*(pos[l].weight_w-pos[l].weight_b+pos[l].weight_s)/(pos[l].weight_w+pos[l].weight_b+2000); 1053 1054 else res=5000L*(pos[l].weight_b-pos[l].weight_w-pos[l].weight_s)/(pos[l].weight_w+pos[l].weight_b+2000); 1055 1056 if (debute) res+=random(30); 1057 return res; 1058} 1059//**************************** 1060 1061boolean checkd_w() { 1062 signed char f2=0; 1063 int j=0; 1064 while (pgm_read_byte(&diag_step[poswk][j])!=99) 1065 { 1066 if (pgm_read_byte(&diag_step[poswk][j])==88) f2=0; 1067 1068 else if (f2==0) { 1069 f2=pole[pgm_read_byte(&diag_step[poswk][j])]; 1070 1071 if (f2==-fb||f2==-fq) return(true); 1072 } 1073 j++; 1074 } 1075 f2=0; 1076 j=0; 1077 while (pgm_read_byte(&stra_step[poswk][j])!=99) { 1078 1079 if (pgm_read_byte(&stra_step[poswk][j])==88) f2=0; 1080 else if (f2==0) { 1081 1082 f2=pole[pgm_read_byte(&stra_step[poswk][j])]; 1083 if (f2==-fr||f2==-fq) 1084 return(true); 1085 if (j==0||pgm_read_byte(&stra_step[poswk][j])==88) 1086 1087 if (f2==-fk) return(true); 1088 } 1089 j++; 1090 } 1091 return(false); 1092 1093} 1094//**************************** 1095boolean checkd_b() { 1096 signed 1097 char f2=0; 1098 int j=0; 1099 while (pgm_read_byte(&diag_step[posbk][j])!=99) { 1100 1101 if (pgm_read_byte(&diag_step[posbk][j])==88) f2=0; 1102 1103 else if (f2==0) { 1104 f2=pole[pgm_read_byte(&diag_step[posbk][j])]; 1105 1106 if (f2==fb||f2==fq) return(true); 1107 } 1108 j++; 1109 } 1110 f2=0; 1111 j=0; 1112 while (pgm_read_byte(&stra_step[posbk][j])!=99) { 1113 1114 if (pgm_read_byte(&stra_step[posbk][j])==88) f2=0; 1115 else if (f2==0) { 1116 1117 f2=pole[pgm_read_byte(&stra_step[posbk][j])]; 1118 if (f2==fr||f2==fq) 1119 return(true); 1120 if (j==0||pgm_read_byte(&stra_step[posbk][j])==88) 1121 1122 if (f2==fk) return(true); 1123 } 1124 j++; 1125 } 1126 return(false); 1127 1128} 1129//**************************** 1130int active(step_t& s) { //determines 1131 if move active before move 1132int j; 1133 if (s.f2!=0||(s.typecheck&B111)>3) 1134 return 1; //taking or promotion 1135 if (abs(s.f2)==fk) return -1; //king moves 1136 not active, castling too 1137 switch (s.f1) { 1138 case fp: 1139 if (row[s.c2]>5) 1140 return 1; //en passant 1141 if (column[s.c2]>1&&posbk==s.c2-9||column[s.c2]<8&&posbk==s.c2-7) 1142 return 1; //check by pawn 1143 return -1; 1144 case -fp: 1145 if (row[s.c2]<4) 1146 return 1; //en passant 1147 if (column[s.c2]>1&&poswk==s.c2+7||column[s.c2]<8&&posbk==s.c2+9) 1148 return 1; //check by pawn 1149 return -1; 1150 case fn: 1151 j=0; 1152 1153 while (pgm_read_byte(&knight_step[s.c2][j])!=99) { 1154 if 1155 (pole[pgm_read_byte(&knight_step[s.c2][j])]==-fk) return 1; //check by knight 1156 1157 j++; 1158 } 1159 return 0; 1160 case -fn: 1161 j=0; 1162 1163 while (pgm_read_byte(&knight_step[s.c2][j])!=99) { 1164 if 1165 (pole[pgm_read_byte(&knight_step[s.c2][j])]==fk) return 1; //check by knight 1166 1167 j++; 1168 } 1169 return 0; 1170 case fb: 1171 if (diag1[s.c2]!=diag1[posbk]&&diag2[s.c2]!=diag2[posbk]) 1172 return -1; //not king diagonal 1173 return 0; 1174 case -fb: 1175 if (diag1[s.c2]!=diag1[poswk]&&diag2[s.c2]!=diag2[poswk]) 1176 return -1; //not king diagonal 1177 return 0; 1178 case fr: 1179 if (row[s.c2]!=row[posbk]&&column[s.c2]!=column[posbk]) 1180 return -1; //not horiz-vert of king 1181 return 0; 1182 case -fr: 1183 if (row[s.c2]!=row[poswk]&&column[s.c2]!=column[poswk]) 1184 return -1; //not horiz-vert of king 1185 return 0; 1186 case fq: 1187 if (diag1[s.c2]!=diag1[posbk]&&diag2[s.c2]!=diag2[posbk]&& 1188 //not king diagonal 1189 row[s.c2]!=row[posbk]&&column[s.c2]!=column[posbk]) 1190 return -1; //not horiz-vert of king 1191 return 0; 1192 case -fq: 1193 if (diag1[s.c2]!=diag1[poswk]&&diag2[s.c2]!=diag2[poswk]&& 1194 //not king diagonal 1195 row[s.c2]!=row[poswk]&&column[s.c2]!=column[poswk]) 1196 return -1; //not horiz-vert of king 1197 return 0; 1198 } //switch 1199 return 1200 0; 1201} 1202//**************************** 1203int quiescence(int l, int alpha, 1204 int beta, int depthleft) { 1205 if (depthleft<=0||l>MAXDEPTH-1) { 1206 if 1207 (l>depth) depth=l; 1208 return evaluate(l); 1209 } 1210 // Serial.println(l); 1211 1212 int score=-20000; 1213 generate_steps(l); 1214 if (pos[l].l_step>MAXSTEPS-30) 1215 return(evaluate(l)); 1216 //if (pos[l].l_step>maxstep) maxstep=pos[l].l_step; 1217 1218 1219 if (!pos[l].check_on_table) { 1220 int weight=evaluate(l); 1221 if 1222 (weight >= score) score=weight; 1223 if (score>alpha) alpha=score; 1224 if 1225 (alpha>=beta) return alpha; 1226 } 1227 int 1228 check,checked,act; 1229 for (int i=pos[l].b_step;i<pos[l].l_step;i++) { 1230 1231 act=1; 1232 if (!pos[l].check_on_table) { 1233 act=active(steps[i]); 1234 1235 if (act==-1) continue; 1236 } 1237 movestep(l,steps[i]); 1238 1239 check=0; 1240 if (act==0) { 1241 if (pos[l].w) check=checkd_b(); else check=checkd_w(); 1242 1243 if (check) steps[i].typecheck=steps[i].typecheck|B1000; 1244 if 1245 (!check) { backstep(l,steps[i]); continue; } 1246 } 1247 if (pos[l].w) 1248 checked=check_w(); else checked=check_b(); 1249 if (checked) { backstep(l,steps[i]); 1250 continue; } //if check opens - move restricted 1251 1252 if (check&&depthleft==1&&l<MAXDEPTH-1) 1253 depthleft++; 1254 1255 pos[l].cur_step=i; 1256 1257 1258 movepos(l,steps[i]); 1259 steps[ply+l]=steps[i]; 1260 int tmp=-quiescence(l+1,-beta,-alpha,depthleft-1); 1261 1262 backstep(l,steps[i]); 1263 if (tmp>score) score=tmp; 1264 if (score>alpha) 1265 { 1266 alpha=score; 1267 pos[l].best_step=i; 1268 1269 pos[l].cut=steps[i]; 1270 } 1271 if (alpha>=beta 1272 ) return alpha; 1273 } 1274 if (score==-20000) { 1275 if (pos[l].check_on_table) 1276 { 1277 score=-10000+l; 1278 } 1279 } 1280 return score; 1281} 1282//**************************** 1283 1284void print_best(step_t& s) { 1285 String wei=String(getcoeff()*s.weight/100.,2); 1286 1287 if (s.weight>9000) wei="+M"+String((10001-s.weight)/2); 1288 int tim=(millis()-starttime)/1000; 1289 1290 Serial.print(str_step(pos[0].cut)+" ("+wei+") "+get_time(tim)+" "); 1291 1292} 1293//**************************** 1294int draw_repeat(int l) { 1295 if 1296 (l+ply<=12) return 0; 1297 for (int i=0;i<4;i++) { 1298 int li=ply+l-i; 1299 if 1300 (steps[li].c1!=steps[li-4].c1||steps[li].c2!=steps[li-4].c2|| 1301 steps[li].c1!=steps[li-8].c1||steps[li].c2!=steps[li-8].c2) 1302 return 0; 1303 } 1304 if (TRACE>0) Serial.println("repeat!"); 1305 return 1; 1306} 1307//**************************** 1308 1309int alphaBeta(int l, int alpha, int beta, int depthleft) { 1310 int score=-20000, 1311 check, tmp; 1312 if (depthleft<=0||l>=MAXDEPTH) { 1313 int fd=4; //4 1314 1315 if (l<5&&steps[pos[0].cur_step].typecheck&B1000) fd+=2; // 1316 1317 if (steps[pos[l-1].cur_step].f2!=0) fd+=2; // 1318 return quiescence(l,alpha,beta,fd); 1319 1320 } 1321 if (l>0) generate_steps(l); 1322 if 1323 (pos[l].l_step>MAXSTEPS-30) return(evaluate(l)); 1324 //if (pos[l].l_step>maxstep) 1325 maxstep=pos[l].l_step; 1326 for (int i=pos[l].b_step;i<pos[l].l_step;i++) { 1327 1328 if (l==0) depth=depthleft; 1329 movestep(l,steps[i]); 1330 1331 if (pos[l].w) check=check_w(); else check=check_b(); 1332 1333 if (check) { backstep(l,steps[i]); continue; } //if check opens - move restricted 1334 1335 pos[l].cur_step=i; 1336 movepos(l,steps[i]); 1337 steps[ply+l]=steps[i]; 1338 1339 if (TRACE>l) { 1340 if (l==0) { 1341 Serial.print(str_step(steps[i])); 1342 Serial.print(" "); 1343 } else { 1344 Serial.println(); 1345 1346 for (int ll=0;ll<l;ll++) Serial.print(" "); 1347 1348 Serial.print(String(l+1)+"- "+str_step(steps[i])); 1349 } 1350 1351 } //TRACE 1352 tmp=-alphaBeta(l+1,-beta,-alpha,depthleft-1); 1353 1354 backstep(l,steps[i]); 1355 if (draw_repeat(l)) tmp=0; 1356 if 1357 (tmp>score) score=tmp; 1358 steps[i].weight=tmp; 1359 if (score>alpha&&!halt) 1360 { 1361 alpha=score; 1362 pos[l].best_step=i; 1363 1364 pos[l].cut=steps[i]; 1365 if (l==0) { 1366 1367 if (depthleft<10) Serial.print(" "); 1368 if (depth<10) Serial.print(" 1369 "); 1370 Serial.print(String(depthleft)+"/"+String(depth)+" "); 1371 1372 print_best(steps[i]); 1373 Serial.println(); 1374 } 1375 1376 } 1377 if (TRACE>l) { 1378 if (l==0) { 1379 Serial.println(" 1380 "+String(tmp)+" "+String(depth)); 1381 } else 1382 { 1383 Serial.print(" = "+String(tmp)); 1384 } 1385 1386 } 1387 if (alpha>=beta) return alpha; 1388 1389 if (halt||(l<3&&millis()-starttime>timelimith)) { //time out or stop 1390 halt=1; 1391 1392 return score; 1393 } 1394 if (millis()-guitime>100) 1395 gui(); 1396 } //all moves 1397 if (score==-20000) { 1398 if (pos[l].check_on_table) 1399 { 1400 score=-10000+l; steps[pos[l-1].cur_step].typecheck=steps[pos[l-1].cur_step].typecheck|B1000; 1401 1402 } else score=0; 1403 } 1404 return score; 1405} 1406//**************************** 1407 1408//**************************** 1409boolean is_draw() { //determines if draw 1410 on desk 1411 boolean draw=false; 1412 int cn=0,cbw=0,cbb=0,co=0,cb=0,cw=0; 1413 for 1414 (int i=0;i<64;i++) { 1415 if (abs(pole[i])==1) co++; 1416 if (abs(pole[i])>3&&abs(pole[i])<6) 1417 co++; //calculationg pawns, rooks, queens 1418 if (abs(pole[i])==6) continue; 1419 //without kings 1420 if (abs(pole[i])==2) cn++; //number of knights 1421 if 1422 (abs(pole[i])==3&&(column[i]+row[i])%2==0) cbb++; //number of whitefields bishops 1423 1424 if (abs(pole[i])==3&&(column[i]+row[i])%2==1) cbw++; //number of blackfields 1425 bishops 1426 if (pole[i]==3) cw++; //number of white bishops 1427 if (pole[i]==-3) 1428 cb++; /number of black bishops 1429 } 1430 if (cn==1&&co+cbb+cbw==0) draw=true; 1431 //one knight only 1432 if (cbb+cbw==1&&co+cn==0) draw=true; //one bishop only 1433 1434 if (co+cn+cbb==0||co+cn+cbw==0) draw=true; // 1435 if (co+cn==0&&cb==1&&cw==1) 1436 draw=true; //two bihops diffrent color 1437 if (draw) return draw; 1438 int lastmove=0; 1439 1440 for (int i=0;i<ply;i++) // 1441 if (abs(steps[i].c1)==fp||steps[i].f2!=0||(steps[i].typecheck&B111)!=0) 1442 lastmove=i; 1443 if (lastmove<ply-100) return 1; //50 moves rule draw 1444 if 1445 (lastmove>ply-11) return 0; // 1446 return 0; //!!!!!!!!!!!!!!!!!!!! 1447 1448 int ply0=ply; 1449 char poleb[64]; // 1450 while (lastmove<ply0-11) { 1451 start_game(); 1452 1453 for (int i=0;i<=lastmove;i++) { // 1454 pos[0].cur_step=i; 1455 1456 movestep(0,steps[i]); 1457 movepos(0,steps[i]); 1458 pos[1].w=!pos[0].w; 1459 1460 pos[0]=pos[1]; 1461 } 1462 for (int i=0;i<64;i++) poleb[i]=pole[i]; 1463 // 1464 int repeats=0; 1465 1466 lastmove++; 1467 } 1468 start_game(); 1469 1470 for (int i=0;i<ply0;i++) { // 1471 pos[0].cur_step=i; 1472 movestep(0,steps[i]); 1473 1474 movepos(0,steps[i]); 1475 pos[1].w=!pos[0].w; 1476 pos[0]=pos[1]; 1477 1478 } 1479 ply=ply0; 1480 1481 return draw; 1482} 1483//**************************** 1484boolean 1485 is_debute() { 1486 int diff=0; 1487 for (int i=0;i<64;i++) if (pole[i]!=(char) pgm_read_byte(&polestart[i])) 1488 diff++; 1489 debute=0; 1490 if (diff<13) debute=1; 1491 return debute; 1492} 1493//**************************** 1494 1495int generate_legal() { 1496 kingpositions(); 1497 generate_steps(0); 1498 int 1499 legal=0; 1500 int check; 1501 for (int i=pos[0].b_step;i<pos[0].l_step;i++) { 1502 1503 pos[0].cur_step=i; 1504 movestep(0,steps[i]); 1505 if (pos[0].w) check=check_w(); 1506 else check=check_b(); 1507 //pos[0].check_on_table=check; 1508 1509 if (!check) legal++; 1510 if (!check) steps[i].weight=0; else steps[i].weight=-30000; 1511 1512 backstep(0,steps[i]); 1513 } 1514 sort_steps(0); 1515 pos[0].l_step=pos[0].b_step+legal; 1516 //illegal moves delete 1517 return(legal); 1518} 1519//**************************** 1520 1521void kingpositions() { 1522 for (int i=0;i<64;i++) { //kings positions definition 1523 1524 if (pole[i]==fk) poswk=i; 1525 if (pole[i]==-fk) posbk=i; 1526 } 1527} 1528 1529//**************************** 1530int solve() { 1531step_t best; 1532 1533 starttime=millis(); 1534 if (is_draw()) { Serial.println(" DRAW!"); return 1535 0; } //draw 1536 kingpositions(); 1537 pos[0].weight_w=0;pos[0].weight_b=0; 1538 1539 for (int i=0;i<64;i++) { //enspile and figures weights definition 1540 if (pole[i]<0) 1541 { 1542 pos[0].weight_b+=fig_weight[-pole[i]]; 1543 } else if (pole[i]>0) 1544 { 1545 pos[0].weight_w+=fig_weight[pole[i]]; //full start weight 8000 1546 1547 } 1548 } 1549 if (pos[0].weight_w+pos[0].weight_b<3500) endspiel=true; 1550 else endspiel=false; //3500? 1551 is_debute(); 1552 //Serial.println(pos[0].weight_w); 1553 1554 //Serial.println(pos[0].weight_b); 1555 pos[0].weight_s=0; 1556 pos[0].cut.f1=0; 1557 pos[0].cut.weight=0; 1558 for (int i=0;i<64;i++) { //get statistic estimation 1559 1560 int f=pole[i]; 1561 if (!f) continue; 1562 if (abs(f)==fk&&endspiel) { 1563 1564 if (f<0) 1565 pos[0].weight_s-=(int)pgm_read_word(&stat_weightb[6][i]); 1566 1567 else 1568 pos[0].weight_s+=(int)pgm_read_word(&stat_weightw[6][i]); 1569 1570 } else { 1571 if (f<0) 1572 1573 pos[0].weight_s-=(int)pgm_read_word(&stat_weightb[-f-1][i]); 1574 1575 else 1576 pos[0].weight_s+=(int)pgm_read_word(&stat_weightw[f-1][i]); 1577 1578 } 1579 } 1580 int startscore=evaluate(0); 1581 1582 count=0; //maxstep=0; 1583 for (int i=1;i<MAXDEPTH;i++) { 1584 if (i%2) pos[i].w=!pos[0].w; 1585 else pos[i].w=pos[0].w; 1586 pos[i].pp=0; 1587 } 1588 best.f1=0; 1589 int 1590 samebest=0; 1591 int legal=generate_legal(); 1592 if (legal==0) 1593 if (pos[0].check_on_table) 1594 { Serial.println(" CHECKMATE!"); return -2; } // 1595 else { Serial.println(" 1596 PAT!"); return 0; } // 1597 1598 if (legal==1) { //ove answere 1599 pos[0].cut=steps[pos[0].b_step]; 1600 1601 movestep(0,pos[0].cut); 1602 int v=evaluate(0); 1603 backstep(0,pos[0].cut); 1604 1605 pos[0].cut.weight=v; 1606 return 1; 1607 } 1608 1609 halt=0; 1610 BAction.Show("STOP"); 1611 1612 BMenu.Hide(); 1613 randomSeed(millis()); 1614 erasestatus(); 1615 1616 //status_c1=-1; status_c2=-1; 1617 solving=1; 1618 int ALPHA=-20000; 1619 int 1620 BETA=20000; 1621 level=2; //2 1622 for (int x=0;x<MAXDEPTH;x++) { 1623 pos[x].cut.f1=0; 1624 pos[x].cut.c2=-1; 1625 } // 1626 int score; 1627 while (level<=10) 1628 { 1629 if (TRACE>0) { 1630 Serial.print(F("******* LEVEL=")); Serial.print(level); 1631 1632 Serial.println(); 1633 } 1634 for (int x=1;x<MAXDEPTH;x++) { 1635 1636 pos[x].cut.f1=0; pos[x].cut.c2=-1; 1637 } // 0 1638 for (int 1639 i=pos[0].b_step;i<pos[0].l_step;i++) { // 1640 pos[0].cur_step=i; 1641 1642 movestep(0,steps[i]); 1643 int check=0; 1644 if (pos[0].w) check=check_b(); 1645 else check=check_w(); 1646 if (check) steps[i].typecheck=steps[i].typecheck|B1000; 1647 1648 steps[i].weight+=evaluate(0)+(steps[i].typecheck&B1000)*30; 1649 if 1650 (steps[i].f2!=0) steps[i].weight-=steps[i].f1; 1651 backstep(0,steps[i]); 1652 1653 } 1654 steps[pos[0].b_step].weight+=10000; //first - always first 1655 sort_steps(0); 1656 1657 for (int i=pos[0].b_step;i<pos[0].l_step;i++) steps[i].weight=-8000; 1658 //weights down 1659 1660// show_steps(0); 1661// delay(100000000000000000000); 1662 1663 1664 score=alphaBeta(0,ALPHA,BETA,level); 1665 unsigned long tim=millis()-starttime; 1666 1667 boolean out=0; 1668 ALPHA=score-100; 1669 BETA=score+100; 1670 1671 if (score>=BETA) { out++; BETA=20000; } 1672 if (score<=ALPHA) { out++; 1673 ALPHA=-20000; } 1674 sort_steps(0); // 1675 if (best.f1==steps[pos[0].b_step].f1&&best.c1==steps[pos[0].b_step].c1 1676 1677 &&best.c2==steps[pos[0].b_step].c2&&best.typecheck==steps[pos[0].b_step].typecheck) 1678 { 1679 samebest++; 1680 if (samebest>=2&&score>=startscore+200&&tim>timelimith/4) 1681 break; 1682 } else { best=steps[pos[0].b_step]; samebest=0; } 1683 if (score>9900||pos[0].cut.weight<-9900||tim>timelimith||halt) 1684 break; 1685 1686 if (!out) level++; 1687 } 1688 Serial.print("Move="); 1689 1690 print_best(pos[0].cut); 1691 Serial.println(" count="+String(count)+" nps="+String(1000*count/(millis()-starttime))); 1692 1693 //Serial.println(" maxstep="+String(maxstep)); 1694 halt=1; 1695 show_status(); 1696 1697 solving=0; 1698 if (pos[0].cut.weight<-9900) return -1; 1699 return 1700 1; 1701} 1702//**************************** 1703void wactest() { 1704char w[150]; 1705 String ss=""; 1706 timelimith=120000; 1707 TRACE=0; 1708 for (int i=155;i<=300;i++) 1709 { 1710 strcpy_P(w, (char*)pgm_read_word(&wacs[i-1])); 1711 ss=w; 1712 new_game(ss); 1713 1714 show_position(); 1715 clearstatus(); 1716 show_board(); 1717 1718 Serial.println(ss); 1719 Serial.println(); 1720 } 1721} 1722//********************************** 1723float 1724 getcoeff() { 1725 float coeff=(pos[0].weight_b+pos[0].weight_w+2000)/5000.0; 1726 1727 //Serial.println(coeff,2); 1728 return coeff; 1729} 1730//********************************** 1731void 1732 show_status() { 1733 String wei; 1734 1735 if (pos[0].cut.weight>9000) wei="M"+String((10001-pos[0].cut.weight)/2); 1736 1737 else if (pos[0].cut.weight<-9000) wei="-M"+String((10001+pos[0].cut.weight)/2); 1738 1739 else wei=String(getcoeff()*pos[0].cut.weight/100.0,2); 1740 if (pos[0].cut.weight>0) 1741 wei="+"+wei; 1742 uint16_t c=GRAY; 1743 if (halt) { 1744 wei=wei+" "+String(1000*count/(millis()-starttime)); 1745 1746 showstatus(get_time((millis()-starttime)/1000)+" "+String(level)+"/"+String(depth),str_step(pos[0].cut),wei,GRAY,WHITE); 1747 1748 } else { 1749 showstatus(get_time((millis()-starttime)/1000)+" "+String(level),str_step(pos[0].cut),wei); 1750 1751 } 1752} 1753//********************************** 1754void closemenu() { 1755 1756 menu=0; 1757 BMenu.Show("MENU"); 1758 BBack.Hide(); 1759 1760 BTime.Hide(); 1761 BNew.Hide(); 1762 1763 BAuto.Hide(); 1764 BRotate.Hide(); 1765 1766 BLoad.Hide(); 1767 BSave.Hide(); 1768 clearmenu(); 1769 1770 show_steps(); 1771 clearstatus(); 1772 BAction.Show("START"); 1773} 1774//********************************** 1775 1776void check_gameend() { 1777 kingpositions(); 1778 String st; 1779 1780 if (is_draw()) { gameover=1; st=F("draw!"); } 1781 else if (generate_legal()==0) 1782 1783 if (pos[0].check_on_table) { gameover=1; st=F("checkmate!"); } // 1784 1785 else { gameover=1; st=F("pat!"); } // 1786 if (gameover) showstatus(statusbuf1,st,statusbuf3,GRAY,RED); 1787 1788} 1789//********************************** 1790void eepromsave() { 1791 EEPROM.put(0,limit); 1792 1793 EEPROM.put(1,autow); 1794 EEPROM.put(2,autob); 1795 EEPROM.put(3,rotate); 1796 EEPROM.put(4,sound); 1797 1798 EEPROM.put(5,ply); 1799 EEPROM.put(10,startpos); 1800 for (int i=0;i<ply;i++) 1801 1802 EEPROM.put(100+i*sizeof(step_t),steps[i]); 1803} 1804//********************************** 1805 1806void eepromload() { 1807 EEPROM.get(0,limit); 1808 EEPROM.get(1,autow); 1809 EEPROM.get(2,autob); 1810 1811 EEPROM.get(3,rotate); 1812 EEPROM.get(4,sound); 1813 EEPROM.get(10,startpos); 1814 1815 start_game(); 1816 EEPROM.get(5,ply); 1817 for (int i=0;i<ply;i++) 1818 EEPROM.get(100+i*sizeof(step_t),steps[i]); 1819 1820 int pl=ply; 1821 for (int i=0;i<pl;i++) { 1822 pos[0].cur_step=i; 1823 if (pos[0].w==1) 1824 pos[1].w=1; else pos[1].w=0; 1825 if (steps[i].f1!=0) { 1826 movestep(0,steps[i]); 1827 1828 movepos(0,steps[i]); 1829 } 1830 pos[0]=pos[1]; 1831 1832 } 1833 ply=pl; 1834 if (ply%2==0) pos[0].w=1; else pos[0].w=0; 1835} 1836//********************************** 1837 1838void gui() { 1839char w[150]; 1840 if (Serial.available()) { 1841 String 1842 s=""; 1843 while (Serial.available()) s=s+char(Serial.read()); 1844 s.trim(); 1845 1846 if (solving) { 1847 if (!halt) { 1848 s.toUpperCase(); 1849 1850 if (s=="STOP") { halt=1; Serial.println("STOPPED"); } 1851 1852 } 1853 } else { //!solving 1854 if (s.indexOf("TIME")==0||s.indexOf("time")==0) 1855 { 1856 long tim=s.substring(4).toInt(); 1857 if (tim!=0) timelimith=tim*1000; 1858 1859 if (timelimith/60000>0) { 1860 Serial.print("timelimith = "+String(timelimith/60000)+" 1861 min "); 1862 int sec=(timelimith%60000)/1000; 1863 if (sec>0) Serial.println(String(sec)+" 1864 sec"); else Serial.println(); 1865 } else Serial.println("timelimith 1866 = "+String(timelimith/1000)+" sec"); 1867 } else { 1868 if (s.indexOf("/")==-1) 1869 { 1870 int n=s.toInt(); 1871 if (n>0&&n<=300) { 1872 strcpy_P(w, 1873 (char*)pgm_read_word(&wacs[n-1])); 1874 s=w; 1875 } else if (s=="0") 1876 s=F("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -"); 1877 else 1878 return; 1879 } 1880 new_game(s); 1881 gameover=0; 1882 if 1883 (pos[0].w) { autow=1; autob=0; } else { autob=1; autow=0; } 1884 initboard(); 1885 1886 show_position(); 1887 clearstatus(); 1888 show_board(); 1889 1890 Serial.println(s); 1891 } 1892 } 1893 Serial.println(F("Command:")); 1894 1895 } //serial 1896 if (gettouch()) { 1897 if (solving) { 1898 if (BAction.IsPressed()) 1899 { //calculation stop 1900 beep(100); 1901 if (!halt) { 1902 halt=1; 1903 1904 pause=1; 1905 BAction.Hide(); 1906 } 1907 } 1908 } else 1909 { //solving 1910 if (BAction.IsPressed()) { 1911 beep(100); 1912 if 1913 (status_c1!=-1&&status_c2!=-1) { //player move try 1914 generate_legal(); 1915 1916 int g=0, gn=-1; 1917 for (int i=pos[0].b_step;i<pos[0].l_step;i++) 1918 { 1919 if (steps[i].c1==status_c1&&steps[i].c2==status_c2) { g++; gn=i; } 1920 1921 } 1922 if (!g) { 1923 beep(300); 1924 erasestatus(); 1925 1926 } else { 1927 pos[0].cur_step=gn; 1928 movestep(0,steps[gn]); 1929 1930 movepos(0,steps[gn]); 1931 steps[ply]=steps[gn]; 1932 1933 pos[1].w=!pos[0].w; 1934 pos[0]=pos[1]; 1935 ply++; 1936 1937 //show_position(); 1938 show_board(); 1939 show_steps(); 1940 1941 erasestatus(); 1942 check_gameend(); 1943 BAction.Show("START"); 1944 1945 BMenu.Show("MENU"); 1946 pause=0; 1947 } 1948 1949 } else { 1950 pause=0; 1951 BAction.Show("START"); 1952 } 1953 1954 } else if (BMenu.IsPressed()) { 1955 beep(100); 1956 if (!menu) 1957 { 1958 menu=1; 1959 BAction.Hide(); 1960 erasestatus(); 1961 clearmenu(); 1962 1963 BMenu.Show("EXIT"); 1964 if (ply>1) BBack.Show("BACK"); else 1965 BBack.Hide(); 1966 BTime.Show(limitstrings[limit]); 1967 1968 BNew.Show("NEW"); 1969 String sa=""; 1970 if 1971 (autow) sa="W"; 1972 if (autob) sa=sa+"B"; 1973 if (sa=="") sa="-"; 1974 1975 sa="AUTO:"+sa; 1976 BAuto.Show(sa); 1977 BRotate.Show("ROTATE"); 1978 1979 BLoad.Show(); 1980 BSave.Show(); 1981 1982 } else { //menu 1983 closemenu(); 1984 1985 } 1986 } else if (BTime.IsPressed()) { 1987 beep(100); 1988 limit+=1; 1989 if (limit>9) limit=0; 1990 timelimith=limits[limit]*1000; 1991 //Serial.println(timelimith); 1992 1993 BTime.Show(limitstrings[limit]); 1994 } else if (BBack.IsPressed()) { 1995 1996 beep(100); 1997 int pl=ply-2; 1998 if (pl<0) pl=0; 1999 2000 start_game(); 2001 for (int i=0;i<pl;i++) { 2002 pos[0].cur_step=i; 2003 2004 if (pos[0].w==1) pos[1].w=1; else pos[1].w=0; 2005 if (steps[i].f1!=0) 2006 { 2007 movestep(0,steps[i]); 2008 movepos(0,steps[i]); 2009 2010 } 2011 pos[0]=pos[1]; 2012 } 2013 ply=pl; 2014 if 2015 (ply%2==0) pos[0].w=1; else pos[0].w=0; 2016 closemenu(); 2017 erasestatus(); 2018 2019 show_board(); 2020 show_color(); 2021 show_steps(); 2022 } 2023 else if (BNew.IsPressed()) { 2024 beep(100); 2025 new_game(); 2026 2027 cleardisplayboard(); 2028 show_board(); 2029 border(); 2030 closemenu(); 2031 2032 erasestatus(); 2033 gameover=0; 2034 } else if 2035 (BAuto.IsPressed()) { 2036 beep(100); 2037 if (!autow&&!autob) 2038 autob=1; 2039 else if (!autow&&autob) { autow=1; autob=0; } 2040 else 2041 if (autow&&!autob) { autow=1; autob=1; } 2042 else { autow=0; autob=0; } 2043 2044 String sa=""; 2045 if (autow) sa="W"; 2046 if (autob) sa=sa+"B"; 2047 2048 if (sa=="") sa="-"; 2049 sa="AUTO:"+sa; 2050 BAuto.Show(sa); 2051 2052 show_color(); 2053 } else if (BRotate.IsPressed()) { 2054 beep(100); 2055 2056 BRotate.Show(); 2057 if (rotate) rotate=0; 2058 else rotate=1; 2059 erasestatus(); 2060 border(); 2061 cleardisplayboard(); 2062 2063 show_board(); 2064 show_color(); 2065 } else if (BSave.IsPressed()) 2066 { 2067 beep(100); 2068 eepromsave(); 2069 BSave.Show(); 2070 2071 closemenu(); 2072 erasestatus(); 2073 } else if (BLoad.IsPressed()) 2074 { 2075 beep(100); 2076 eepromload(); 2077 BLoad.Show(); 2078 2079 closemenu(); 2080 erasestatus(); 2081 cleardisplayboard(); 2082 show_board(); 2083 2084 show_color(); 2085 show_steps(); 2086 gameover=0; 2087 } 2088 else { 2089 signed char c=field_pressed(); 2090 if (!menu&&c!=-1) { 2091 2092 if (status_c1==-1) { 2093 status_c1=c; status_step(status_c1,1,getColor(220,0,0)); 2094 2095 } else if (status_c2==-1) { 2096 status_c2=c; status_step(status_c2,1,getColor(0,180,0)); 2097 2098 } 2099 if (status_c1!=-1&&status_c2!=-1&&c!=status_c2) erasestatus(); 2100 2101 } 2102 } 2103 2104 } //solving 2105 } //gettouch 2106 if 2107 (solving&&millis()-statustime>999) { show_status(); statustime=millis(); } 2108 if 2109 (!pause&&!menu&&!solving&&!gameover) { 2110 if (pos[0].w&&autow||!pos[0].w&&autob) 2111 { 2112 halt=0; 2113 TRACE=0; 2114 gameover=0; 2115 int res=solve(); 2116 2117 //Serial.println(res); 2118 if (res==1) { 2119 movestep(0,pos[0].cut); 2120 2121 movepos(0,pos[0].cut); 2122 steps[ply]=pos[0].cut; 2123 pos[0]=pos[1]; 2124 2125 ply++; 2126 //show_position(); 2127 show_board(); 2128 show_steps(); 2129 2130 erasestatus(); 2131 check_gameend(); 2132 } else { 2133 String 2134 st=F("draw!"); 2135 if (res==-1) st=F("give up!"); 2136 else if (res==-2) 2137 st=F("checkmate!"); 2138 for (int k=0;k<11;k++) statusbuf2[k]='-'; 2139 showstatus(statusbuf1,st,statusbuf3,GRAY,RED); 2140 2141 gameover=1; 2142 } 2143 BAction.Show("START"); 2144 BMenu.Show("MENU"); 2145 2146 } else { // 2147 } 2148 } 2149 guitime=millis(); 2150} 2151//**************************** 2152void 2153 loop() { 2154 gui(); 2155 delay(100); 2156} 2157//**************************** 2158
Downloadable files
schematic_n3mFTjgZxb.jpg
schematic_n3mFTjgZxb.jpg
Comments
Only logged in users can leave comments