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[<