Help moving someone else's code from MEGA2560 to Teensy 4.0

sremick

Member
Code is located here: https://create.arduino.cc/projecthub/Sergey_Urusov/arduino-mega-chess-ii-b2e599

Display I'm using: https://www.ebay.com/itm/264583550286

MEGA2560 pin diagram: https://aws1.discourse-cdn.com/ardu.../368f6a73141b26b82227ae7794cc6920d402a618.png

So, I'm trying to migrate this code from the Mega to the Teensy. On the Mega it runs as-is with the display without any changes. just snap the display onto the Mega like it was designed, and everything just magically works "out of the box". Yay for that at least.

No so with the Teensy. The code compiles and uploads ok (There are "warnings" but no "errors" so I would hope it's ok?) I was able to map the pins 1-1:

LCD : MEGA : Teensy
--------------------------------
LCD_RD : A0 : 14
LCD_WR : A1 : 15
LCD_RS : A2 : 16
LCD_CS : A3 : 17
LCD_RST : A4 : 18
F_CS : A5 : 19
SD_SCK : 13 : 13
SD_D0 : 12 : 12
SD_DI : 11 : 11
SD_SS : 10 : 10
LCD_D1 : 9 : 9
LCD_D0 : 8 : 8
LCD_D7 : 7 : 7
LCD_D6 : 6 : 6
LCD_D5 : 5 : 5
LCD_D4 : 4 : 4
LCD_D3 : 3 : 3
LCD_D2 : 2 : 2

On the Teensy 4.0 pin diagram, pins 14-19 are also named A0-A5 so I was hoping it'd "just work".

I'm supplying the LCD's 3.3V from the Teensy's 3.3V out, and the LCD's 5V from the same source providing 5V to the Teensy VIN (it's actually like 4.77V).

Not sure what the problem is, but my first hunch is that even though the Teensy has the same pins, I might need to fiddle with pinmodes to get them to behave the way I want them too. Thing is, I'm not intimately familiar with the code or this display to even know which are input and which are output pins (it's a touchscreen, so some are output for that at least)

Second guess is a power issue...? Maybe 4.77V isn't close enough to 5V? Or maybe the Teensy's 250mA of 3.3V isn't enough? I would figure since the display has both 5V in and 3.3V in that the 5V is the primary power needing most the amps, and then the 3.3V is just as a digital reference...?

Too much of a newbie to know for sure, so I could use some guidance. Thanks!

Finally, the warnings I get when I compile for the Teensy (in case someone asks for it):

Code:
In file included from C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\gui.h:6:0,
                 from C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:68:
c:\Users\scott\OneDrive\Documents\Arduino\libraries\MCUFRIEND_kbv/UTFTGLUE.h:17:2: warning: #warning @@@@@@@@@@@@@@@@@@@@@@@@@ <UTFTGLUE.h> @@@@@@@@@@@@@@@@@@@@@@@@@@ [-Wcpp]
 #warning   @@@@@@@@@@@@@@@@@@@@@@@@@ <UTFTGLUE.h> @@@@@@@@@@@@@@@@@@@@@@@@@@
  ^
In file included from C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:4:0:
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\logic.h:63:1: warning: narrowing conversion of '-4' from 'int' to 'char' inside { } [-Wnarrowing]
 };  
 ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\logic.h:63:1: warning: narrowing conversion of '-2' from 'int' to 'char' inside { } [-Wnarrowing]
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\logic.h:63:1: warning: narrowing conversion of '-3' from 'int' to 'char' inside { } [-Wnarrowing]
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\logic.h:63:1: warning: narrowing conversion of '-5' from 'int' to 'char' inside { } [-Wnarrowing]
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\logic.h:63:1: warning: narrowing conversion of '-6' from 'int' to 'char' inside { } [-Wnarrowing]
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\logic.h:63:1: warning: narrowing conversion of '-3' from 'int' to 'char' inside { } [-Wnarrowing]
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\logic.h:63:1: warning: narrowing conversion of '-2' from 'int' to 'char' inside { } [-Wnarrowing]
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\logic.h:63:1: warning: narrowing conversion of '-4' from 'int' to 'char' inside { } [-Wnarrowing]
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\logic.h:63:1: warning: narrowing conversion of '-1' from 'int' to 'char' inside { } [-Wnarrowing]
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\logic.h:63:1: warning: narrowing conversion of '-1' from 'int' to 'char' inside { } [-Wnarrowing]
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\logic.h:63:1: warning: narrowing conversion of '-1' from 'int' to 'char' inside { } [-Wnarrowing]
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\logic.h:63:1: warning: narrowing conversion of '-1' from 'int' to 'char' inside { } [-Wnarrowing]
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\logic.h:63:1: warning: narrowing conversion of '-1' from 'int' to 'char' inside { } [-Wnarrowing]
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\logic.h:63:1: warning: narrowing conversion of '-1' from 'int' to 'char' inside { } [-Wnarrowing]
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\logic.h:63:1: warning: narrowing conversion of '-1' from 'int' to 'char' inside { } [-Wnarrowing]
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\logic.h:63:1: warning: narrowing conversion of '-1' from 'int' to 'char' inside { } [-Wnarrowing]
In file included from C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:68:0:
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\gui.h: In function 'void status_step(char, byte, uint16_t)':
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\gui.h:521:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   int i=column[c]-1; 
                 ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\gui.h:522:16: warning: array subscript has type 'char' [-Wchar-subscripts]
   int j=8-row[c];  
                ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino: In function 'boolean fenload(String)':
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:120:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int c=0; c<ss.length(); c++) {
                  ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino: In function 'void movepos(int, step_t&)':
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:349:42: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
     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;      
                                          ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:366:23: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
     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;    
                       ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:369:27: warning: comparison of constant '3' with boolean expression is always false [-Wbool-compare]
    if ((s.typecheck&&B111)>3) pos[l+1].weight_b+=fig_weight[(s.typecheck&B111)-2]-100;         
                           ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino: In function 'void add_king(int, int)':
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:471:20: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
     if (f2==0||f2<0&&f1>0||f2>0&&f1<0) {
                    ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:471:32: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
     if (f2==0||f2<0&&f1>0||f2>0&&f1<0) {
                                ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino: In function 'void add_knight(int, int)':
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:489:20: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
     if (f2==0||f2<0&&f1>0||f2>0&&f1<0) {
                    ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:489:32: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
     if (f2==0||f2<0&&f1>0||f2>0&&f1<0) {
                                ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino: In function 'void add_stra(int, int)':
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:509:21: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
      if (f2==0||f2<0&&f1>0||f2>0&&f1<0) {
                     ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:509:33: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
      if (f2==0||f2<0&&f1>0||f2>0&&f1<0) {
                                 ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino: In function 'void add_diag(int, int)':
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:531:21: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
      if (f2==0||f2<0&&f1>0||f2>0&&f1<0) {
                     ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:531:33: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
      if (f2==0||f2<0&&f1>0||f2>0&&f1<0) {
                                 ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino: In function 'void generate_steps(int)':
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:592:16: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   if (f==0||f<0&&pos[l].w||f>0&&!pos[l].w) continue;  
                ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:592:31: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   if (f==0||f<0&&pos[l].w||f>0&&!pos[l].w) continue;  
                               ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:605:17: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
    if (f==0||f<0&&pos[l].w||f>0&&!pos[l].w) continue;   
                 ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:605:32: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
    if (f==0||f<0&&pos[l].w||f>0&&!pos[l].w) continue;   
                                ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino: In function 'int active(step_t&)':
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:810:24: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
      if (column[s.c2]>1&&posbk==s.c2-9||column[s.c2]<8&&posbk==s.c2-7) return 1; //check by pawn
                        ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:814:24: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
      if (column[s.c2]>1&&poswk==s.c2+7||column[s.c2]<8&&posbk==s.c2+9) return 1; //check by pawn
                        ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino: In function 'boolean is_draw()':
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:1034:8: warning: unused variable 'repeats' [-Wunused-variable]
    int repeats=0;
        ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:1023:8: warning: variable 'poleb' set but not used [-Wunused-but-set-variable]
   char poleb[64]; //
        ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino: In function 'int solve()':
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:1095:42: warning: array subscript has type 'char' [-Wchar-subscripts]
       pos[0].weight_w+=fig_weight[pole[i]]; //full start weight 8000           
                                          ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:1128:6: warning: suggest explicit braces to avoid ambiguous 'else' [-Wparentheses]
   if (legal==0) 
      ^
In file included from C:\Users\scott\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.56.1\cores\teensy4/WProgram.h:41:0,
                 from C:\Users\scott\AppData\Local\Temp\arduino-sketch-6C9736ADEAE2791D10573918D9EEEF69\pch\Arduino.h:6:
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino: In function 'void wactest()':
C:\Users\scott\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.56.1\cores\teensy4/avr/pgmspace.h:109:2: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
 })
  ^
C:\Users\scott\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.56.1\cores\teensy4/avr/pgmspace.h:60:45: note: in definition of macro 'strcpy_P'
 #define strcpy_P(dest, src) strcpy((dest), (src))
                                             ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:1213:24: note: in expansion of macro 'pgm_read_word'
     strcpy_P(w, (char*)pgm_read_word(&wacs[i-1])); 
                        ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino: In function 'void show_status()':
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:1237:12: warning: unused variable 'c' [-Wunused-variable]
   uint16_t c=GRAY;
            ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino: In function 'void check_gameend()':
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:1266:14: warning: suggest explicit braces to avoid ambiguous 'else' [-Wparentheses]
      else if (generate_legal()==0) 
              ^
In file included from C:\Users\scott\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.56.1\cores\teensy4/WProgram.h:41:0,
                 from C:\Users\scott\AppData\Local\Temp\arduino-sketch-6C9736ADEAE2791D10573918D9EEEF69\pch\Arduino.h:6:
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino: In function 'void gui()':
C:\Users\scott\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.56.1\cores\teensy4/avr/pgmspace.h:109:2: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
 })
  ^
C:\Users\scott\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.56.1\cores\teensy4/avr/pgmspace.h:60:45: note: in definition of macro 'strcpy_P'
 #define strcpy_P(dest, src) strcpy((dest), (src))
                                             ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:1333:30: note: in expansion of macro 'pgm_read_word'
           strcpy_P(w, (char*)pgm_read_word(&wacs[n-1])); 
                              ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:1507:15: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   if (pos[0].w&&autow||!pos[0].w&&autob) {
               ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino: In function 'int solve()':
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:1185:4: warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false [-Wstrict-overflow]
    if (score>=BETA) { out++; BETA=20000; }         
    ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:1186:4: warning: assuming signed overflow does not occur when assuming that (X - c) > X is always false [-Wstrict-overflow]
    if (score<=ALPHA) { out++; ALPHA=-20000; }   
    ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:1189:42: warning: 'best.step_t::typecheck' may be used uninitialized in this function [-Wmaybe-uninitialized]
        &&best.c2==steps[pos[0].b_step].c2&&best.typecheck==steps[pos[0].b_step].typecheck) {
                                          ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:1189:8: warning: 'best.step_t::c2' may be used uninitialized in this function [-Wmaybe-uninitialized]
        &&best.c2==steps[pos[0].b_step].c2&&best.typecheck==steps[pos[0].b_step].typecheck) {
        ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:1188:40: warning: 'best.step_t::c1' may be used uninitialized in this function [-Wmaybe-uninitialized]
    if (best.f1==steps[pos[0].b_step].f1&&best.c1==steps[pos[0].b_step].c1
                                        ^
In file included from c:\Users\scott\OneDrive\Documents\Arduino\libraries\MCUFRIEND_kbv\MCUFRIEND_kbv.cpp:35:0:
c:\Users\scott\OneDrive\Documents\Arduino\libraries\MCUFRIEND_kbv\utility/mcufriend_shield.h:504:2: warning: #warning regular UNO shield on a Teensy 4.0 [-Wcpp]
 #warning regular UNO shield on a Teensy 4.0
  ^
c:\Users\scott\OneDrive\Documents\Arduino\libraries\MCUFRIEND_kbv\MCUFRIEND_kbv.cpp: In member function 'uint16_t MCUFRIEND_kbv::readReg(uint16_t, int8_t)':
c:\Users\scott\OneDrive\Documents\Arduino\libraries\MCUFRIEND_kbv\MCUFRIEND_kbv.cpp:162:13: warning: unused variable 'lo' [-Wunused-variable]
     uint8_t lo;
             ^
c:\Users\scott\OneDrive\Documents\Arduino\libraries\MCUFRIEND_kbv\MCUFRIEND_kbv.cpp: In member function 'uint16_t MCUFRIEND_kbv::readID()':
c:\Users\scott\OneDrive\Documents\Arduino\libraries\MCUFRIEND_kbv\MCUFRIEND_kbv.cpp:194:19: warning: unused variable 'ret2' [-Wunused-variable]
     uint16_t ret, ret2;
                   ^
c:\Users\scott\OneDrive\Documents\Arduino\libraries\MCUFRIEND_kbv\MCUFRIEND_kbv.cpp: In member function 'int16_t MCUFRIEND_kbv::readGRAM(int16_t, int16_t, uint16_t*, int16_t, int16_t)':
c:\Users\scott\OneDrive\Documents\Arduino\libraries\MCUFRIEND_kbv\MCUFRIEND_kbv.cpp:294:22: warning: unused variable 'tmp' [-Wunused-variable]
     uint8_t r, g, b, tmp;
                      ^
c:\Users\scott\OneDrive\Documents\Arduino\libraries\MCUFRIEND_kbv\MCUFRIEND_kbv.cpp: In member function 'virtual void MCUFRIEND_kbv::setRotation(uint8_t)':
c:\Users\scott\OneDrive\Documents\Arduino\libraries\MCUFRIEND_kbv\MCUFRIEND_kbv.cpp:355:29: warning: unused variable 'REV' [-Wunused-variable]
     uint16_t GS, SS_v, ORG, REV = _lcd_rev;
                             ^
c:\Users\scott\OneDrive\Documents\Arduino\libraries\MCUFRIEND_kbv\MCUFRIEND_kbv.cpp: In member function 'void MCUFRIEND_kbv::begin(uint16_t)':
c:\Users\scott\OneDrive\Documents\Arduino\libraries\MCUFRIEND_kbv\MCUFRIEND_kbv.cpp:1584:31: warning: unused variable 'ST7781_regValues' [-Wunused-variable]
         static const uint16_t ST7781_regValues[] PROGMEM = {
                               ^
c:\Users\scott\OneDrive\Documents\Arduino\libraries\MCUFRIEND_kbv\MCUFRIEND_kbv.cpp:1684:30: warning: unused variable 'ST7789_regValues_arcain6' [-Wunused-variable]
         static const uint8_t ST7789_regValues_arcain6[] PROGMEM = {
                              ^
c:\Users\scott\OneDrive\Documents\Arduino\libraries\MCUFRIEND_kbv\MCUFRIEND_kbv.cpp:2595:30: warning: unused variable 'ILI9341_regValues_ada' [-Wunused-variable]
         static const uint8_t ILI9341_regValues_ada[] PROGMEM = {        // Adafruit_TFTLCD only works with EXTC=0
                              ^
c:\Users\scott\OneDrive\Documents\Arduino\libraries\MCUFRIEND_kbv\MCUFRIEND_kbv.cpp:2675:30: warning: unused variable 'ILI9481_CPT29_regValues' [-Wunused-variable]
         static const uint8_t ILI9481_CPT29_regValues[] PROGMEM = {    // 320x430
                              ^
c:\Users\scott\OneDrive\Documents\Arduino\libraries\MCUFRIEND_kbv\MCUFRIEND_kbv.cpp:2687:30: warning: unused variable 'ILI9481_PVI35_regValues' [-Wunused-variable]
         static const uint8_t ILI9481_PVI35_regValues[] PROGMEM = {    // 320x480
                              ^
c:\Users\scott\OneDrive\Documents\Arduino\libraries\MCUFRIEND_kbv\MCUFRIEND_kbv.cpp:2699:30: warning: unused variable 'ILI9481_AUO317_regValues' [-Wunused-variable]
         static const uint8_t ILI9481_AUO317_regValues[] PROGMEM = {    // 320x480
                              ^
c:\Users\scott\OneDrive\Documents\Arduino\libraries\MCUFRIEND_kbv\MCUFRIEND_kbv.cpp:2710:30: warning: unused variable 'ILI9481_CMO35_regValues' [-Wunused-variable]
         static const uint8_t ILI9481_CMO35_regValues[] PROGMEM = {    // 320480
                              ^
c:\Users\scott\OneDrive\Documents\Arduino\libraries\MCUFRIEND_kbv\MCUFRIEND_kbv.cpp:2724:30: warning: unused variable 'ILI9481_RGB_regValues' [-Wunused-variable]
         static const uint8_t ILI9481_RGB_regValues[] PROGMEM = {    // 320x480
                              ^
c:\Users\scott\OneDrive\Documents\Arduino\libraries\MCUFRIEND_kbv\MCUFRIEND_kbv.cpp:2816:7: warning: label 'common_9488' defined but not used [-Wunused-label]
       common_9488:
       ^
Opening Teensy Loader...
teensy_size: Memory Usage on Teensy 4.0:
teensy_size:   FLASH: code:68692, data:43684, headers:8452   free for files:1910788
teensy_size:    RAM1: variables:15936, code:66984, padding:31320   free for local variables:410048
teensy_size:    RAM2: variables:12384  free for malloc/new:511904

--------------------------
Compilation complete.
Teensy did not respond to a USB-based request to enter program mode.
Please press the PROGRAM MODE BUTTON on your Teensy to upload your sketch.

--------------------------
upload complete.

Someone else mentioned concern about these warnings in particular:

Code:
    C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino: In function 'void wactest()':
C:\Users\scott\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.56.1\cores\teensy4/avr/pgmspace.h:109:2: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
 })
  ^
C:\Users\scott\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.56.1\cores\teensy4/avr/pgmspace.h:60:45: note: in definition of macro 'strcpy_P'
 #define strcpy_P(dest, src) strcpy((dest), (src))
                                             ^
C:\Users\scott\OneDrive\Documents\Arduino\arduinomegachess2\arduinomegachess2.ino:1213:24: note: in expansion of macro 'pgm_read_word'
     strcpy_P(w, (char*)pgm_read_word(&wacs[i-1])); 
                        ^
 
I was about to say post your code, but I see you have a pointer to it, but that is not the code that you are
trying to run because as you said you have modified it.
Please post the code you are trying to run.
 
Last edited:
I was about to say post your code, but I see you have a pointer to it, but that is not the code that you are
trying to run because as you said you have modified it.
Please post the code you are trying to run.

I actually didn't modify it. When I said I was able to map the pins 1-1 that's not in the code, that's in my wiring/selection of pins on the Teensy to pins on the display. I've checked and re-checked my wiring and it matches what I put in the first post (whether that is actually "correct" is part of what I'm trying to determine). I used jumper wires so I can make changes easily.
20220430_110458.jpg
 
Paste the code you are using.
If I had a problem I would not expect any helper to have to go to a third party site to see code.
 
Paste the code you are using.
If I had a problem I would not expect any helper to have to go to a third party site to see code.

It was due to the sheer length of the code, amongst several files. But here you go:

Code:
//ArduinoMega Chess 2.0
//Sergey Urusov, ususovsv@gmail.com
#include "wac.h"
#include "logic.h"
#include <stdint.h>
#include <avr/pgmspace.h>
#include <EEPROM.h> 

#define MAXSTEPS 600 //600*7=4200 bytes, 700 - works too
#define MAXDEPTH 20 //28*20=560 bytes

typedef struct {
  signed char f1,f2; //figure moved and taken
  signed char c1,c2; //from and to coordinates
  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
  short weight; //position weight
} step_t;

step_t steps[MAXSTEPS]; //moves massive include solving tree
short ply; //number of halfstep in match, started with 0

struct position_t {  
  byte w; //white to move 1, black - 0
  byte wrk, wrq, brk, brq; //castle ability
  byte pp; //number of field 1..63 of last two squares pawn move
  short b_step; //number of levels first move
  short l_step; //quantity of moves on level
  short cur_step; //current move on level
  short best_step; //best move on level
  step_t cut; //move for sorting (cut alpha-beta)
  byte check_on_table; //moving side under check    
  short weight_w; //weight of white figures
  short weight_b; //weight of black figures
  short weight_s; //statistic estimation of position, in favor of whites +
} pos[MAXDEPTH];


struct startpos_t {
  byte w; 
  byte wrk, wrq, brk, brq; 
  byte pp; 
  char pole[64];  
  int ply;  
} startpos;

byte poswk=0; //white king field
byte posbk=0; //black king field

int level; //number of current level of solving tree
unsigned long timelimith=5000; //limith of thinking time in ms
const int limits[10]={5,10,30,60,120,180,300,600,1800,3600};
const char* limitstrings[10]={"5 sec","10 sec","30 sec","1 min","2 min","3 min","5 min","10 min","30 min","1 hr"};
byte limit=0;
unsigned long starttime;
boolean endspiel=0;
boolean halt=0;
unsigned long count=0;
int depth;
boolean TRACE=0;
int maxstep;
boolean solving=0;
boolean gameover=0;
boolean autow=0;
boolean autob=1;
boolean debute;

String str_step(step_t);
#include "gui.h"

//****************************
void new_game(String fen="") {
  if (fen=="") fen=F("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -");  // 
  fenload(fen);
  for (int i=0;i<64;i++) startpos.pole[i]=pole[i];
  startpos.w=pos[0].w;                               
  startpos.wrk=pos[0].wrk;                               
  startpos.wrq=pos[0].wrq;                               
  startpos.brk=pos[0].brk;                               
  startpos.brq=pos[0].brq;                               
  startpos.w=pos[0].w;
  startpos.pp=pos[0].pp;
  startpos.ply=ply;  
  kingpositions();    
}
//****************************
void setup() {   
  Serial.begin(115200);  
  while (!Serial) ;
  Serial.println(F("Start"));   
  new_game();  
  cleardisplayboard();
  if (!rotate) { autow=0; autob=1; } else { autow=1; autob=0; }   
  guistart();      
  clearstatus();    
  //wactest();
  Serial.println(F("Command:"));  
}  
//****************************
void start_game() {
  for (int i=0;i<64;i++) pole[i]=startpos.pole[i];
  pos[0].w=startpos.w;                               
  pos[0].wrk=startpos.wrk;                               
  pos[0].wrq=startpos.wrq;                               
  pos[0].brk=startpos.brk;                               
  pos[0].brq=startpos.brq;                               
  pos[0].w=startpos.w;
  pos[0].pp=startpos.pp;  
  ply=startpos.ply;    
  kingpositions();    
}
//**********************************   
boolean fenload(String ss) {
 char s='x',i=0,j=0;  boolean load=false;   
  for (int i=0;i<64;i++) pole[i]=0;                               
  pos[0].w=1; 
  pos[0].wrk=0; pos[0].wrq=0;  pos[0].brk=0; pos[0].brq=0;
  pos[0].pp=0; 
  pos[0].cur_step=0; pos[0].b_step=MAXDEPTH; pos[0].l_step=0;
  int spaces=0;      
  for (int c=0; c<ss.length(); c++) {
    s=ss[c];       
    if (i>7) { i=0; j++; }        
    if (spaces==3&&int(s)>='a'&&int(s)<='h') {      
      c++;
      char s1=ss[c];
      if (int(s1)>='1'&&int(s1)<='8') {
        pos[0].pp=8*(7-(int(s1)-int('1')))+int(s)-int('a');        
      }
    } else {
    int l=j*8+i;  
    switch (s) {      
    case '/': i=0; break;  
    case 'p': pole[l]=-fp; i++; break;
    case 'P': pole[l]=fp; i++; break;
    case 'n': pole[l]=-fn; i++; break;
    case 'N': pole[l]=fn; i++; break;
    case 'b': if (spaces==0) { pole[l]=-fb; i++; } else
              if (spaces==1) { pos[0].w=0; load=true; }              
              break;    
    case 'B': pole[l]=fb; i++; break;
    case 'r': pole[l]=-fr; i++; break;
    case 'R': pole[l]=fr; i++; break;
    case 'q': if (spaces==0) { pole[l]=-fq; i++; } else pos[0].brq=1; 
              break;
    case 'Q': if (spaces==0) { pole[l]=fq;  i++; } else pos[0].wrq=1;
              break;
    case 'k': if (spaces==0) { pole[l]=-fk;  i++; } else pos[0].brk=1; 
              break;
    case 'K': if (spaces==0) { pole[l]=fk;  i++; } else pos[0].wrk=1;
              break;
    case '1': i++; break;
    case '2': i+=2; break;
    case '3': i+=3; break;
    case '4': i+=4; break;
    case '5': i+=5; break;
    case '6': i+=6; break;
    case '7': i+=7; break;
    case '8': i=0; j++; break;    
    case ' ': spaces++; break;    
    case 'w': if (spaces==1) { pos[0].w=1; load=true; } break;        
    }       
    }    
    if (spaces==4) break;    
  }  
  if (!load) Serial.println(F("Error"));
  if (pos[0].w) ply=0; else ply=1;
  steps[0].f1=0; steps[1].f1=0;
  return load;  
}
//****************************
void show_position() {    
  for (int i=0;i<8;i++) {
     Serial.println(F("-----------------------------------------"));       
      Serial.print("|");       
      for (int j=0;j<8;j++)    {        
        signed char f=pole[i*8+j];
        if (f>=0) { Serial.print("  "); Serial.print(fig_symb1[f]); Serial.print(" |"); }                     
         else { Serial.print(" -"); Serial.print(fig_symb1[-f]); Serial.print(" |"); }                     
      }   
      Serial.print("  ");              
      Serial.println(8-i);              
  }    
  Serial.println(F("-----------------------------------------"));       
  Serial.print(F("   a    b    c    d    e    f    g    h    "));       
  if (pos[0].w==0) Serial.print(F("Black")); else Serial.print(F("White"));       
  Serial.println();
}
//****************************
String str_pole(int i) {
  return String(char('a'+i%8)+String(8-i/8));  
}
//****************************
String str_step(step_t st) {
  String s="";
   if (st.f1==0) return s;
   if ((st.typecheck&B111)==2) s="0-0";
    else if ((st.typecheck&B111)==3) s="0-0-0";
   else  {    
    if (abs(st.f1)>1) s=s+fig_symb[abs(st.f1)];     
    s=s+str_pole(st.c1);      
    if (st.f2==0) s=s+"-";      
    if (st.f2!=0) s=s+"x";    
    s=s+str_pole(st.c2);     
   } 
   if ((st.typecheck&B111)>3) s=s+"="+fig_symb[(st.typecheck&B111)-2];
   if (st.typecheck&B1000) s=s+"+";   
   return s;
}
//****************************
void show_steps(int l) {
 Serial.print(F("Steps=")); Serial.println(String(pos[l].l_step-pos[l].b_step));
 for (int i=pos[l].b_step;i<pos[l].l_step;i++) { 
  Serial.print(str_step(steps[i])); Serial.print(" "); Serial.print(steps[i].weight); Serial.print(F("    "));
  if ((i+1)%3==0) Serial.println(); 
 }
 Serial.println();  
} 
//****************************  
//****************************  
//****************************  
//****************************  
//****************************  
//****************************
//****************************  
void movestep(int l, step_t &s) {             
  pole[s.c1]=0;
  pole[s.c2]=s.f1;          
  if (pos[l].w) { //white to move
   if (s.f1==fk) poswk=s.c2; 
   switch (s.typecheck&B111) {   
   case 0:     
    return;
   case 1: //En Passant
    pole[s.c2+8]=0;  
    break;
   case 2: //short castle
    pole[60]=0;
    pole[61]=fr;
    pole[62]=fk;
    pole[63]=0;   
    poswk=62;    
    break;
   case 3: //long castle
    pole[60]=0;
    pole[59]=fr;
    pole[58]=fk;
    pole[57]=0;
    pole[56]=0;  
    poswk=58;     
    break;
   default: 
    pole[s.c2]=(s.typecheck&B111)-2;   
   } 
  } else { //black to move   
   if (s.f1==-fk) posbk=s.c2; 
   switch ((s.typecheck&B111)) {   
   case 0:     
    return; 
   case 1: //En Passant
    pole[s.c2-8]=0;
    break;
   case 2: //short castle
    pole[4]=0;
    pole[5]=-fr;
    pole[6]=-fk;
    pole[7]=0;
    posbk=6;       
    break;
   case 3: //long castle
    pole[4]=0;
    pole[3]=-fr;
    pole[2]=-fk;
    pole[1]=0;
    pole[0]=0;   
    posbk=2;    
    break;
   default: 
    pole[s.c2]=2-(s.typecheck&B111);
   }
  }      
}
//****************************  
void backstep(int l, step_t &s) {     
  pole[s.c1]=s.f1;
  pole[s.c2]=s.f2;  
  if (pos[l].w) { //white to move
   if (s.f1==fk) poswk=s.c1; 
   switch (s.typecheck&B111) {
   case 0: return;
   case 1: //En Passant
    pole[s.c2]=0;
    pole[s.c2+8]=-fp;
    break;
   case 2: //short castle
    pole[60]=fk;
    pole[61]=0;
    pole[62]=0;
    pole[63]=fr;
    poswk=60;    
    break;
   case 3: //long castle
    pole[60]=fk;
    pole[59]=0;
    pole[58]=0;
    pole[57]=0;
    pole[56]=fr;
    poswk=60;    
    break;
   }
  } else { //black to move 
  if (s.f1==-fk) posbk=s.c1;
   switch (s.typecheck&B111) {
   case 0: return;
   case 1: //En Passant
    pole[s.c2]=0;
    pole[s.c2-8]=fp;
    break;
   case 2: //short castle
    pole[4]=-fk;
    pole[5]=0;
    pole[6]=0;
    pole[7]=-fr;
    posbk=4;    
    break;
   case 3: //long castle
    pole[4]=-fk;
    pole[3]=0;
    pole[2]=0;
    pole[1]=0;
    pole[0]=-fr;
    posbk=4;    
    break;
   }
  }             
}
//****************************  
void movepos(int l, step_t &s) {     
  pos[l+1].wrk=pos[l].wrk; pos[l+1].wrq=pos[l].wrq; 
  pos[l+1].brk=pos[l].brk; pos[l+1].brq=pos[l].brq;
  pos[l+1].pp=0;    
  if (pos[l].w) { // 
   if (pos[l].wrk||pos[l].wrq) {
    if (s.c1==60) {
      pos[l+1].wrk=0; pos[l+1].wrq=0;
    } else if (s.c1==63) pos[l+1].wrk=0;
    else if (s.c1==56) pos[l+1].wrq=0;
   }
   if ((s.typecheck&B111)==0&&s.f1==fp&&s.c2==s.c1-16)     
    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;      
   pos[l+1].weight_w=pos[l].weight_w; pos[l+1].weight_b=pos[l].weight_b;
   if (s.f2!=0) pos[l+1].weight_b-=fig_weight[-s.f2];
   if ((s.typecheck&B111)>3) pos[l+1].weight_w+=fig_weight[(s.typecheck&B111)-2]-100;          
   if (s.f1==fk&&endspiel)  
    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]);
   else  
    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]);
   if (s.f2!=0) pos[l+1].weight_s+=(int)pgm_read_word(&stat_weightb[-s.f2-1][s.c2]);   
  } else { // 
   if (pos[l].brk||pos[l].brq) {
    if (s.c1==4) {
      pos[l+1].brk=0; pos[l+1].brq=0;
    } else if (s.c1==7) pos[l+1].brk=0;
    else if (s.c1==0) pos[l+1].brq=0;
   }   
   if ((s.typecheck&B111)==0&&s.f1==-fp&&s.c2==s.c1+16) 
    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;    
   pos[l+1].weight_w=pos[l].weight_w; pos[l+1].weight_b=pos[l].weight_b;
   if (s.f2!=0) pos[l+1].weight_w-=fig_weight[s.f2];
   if ((s.typecheck&&B111)>3) pos[l+1].weight_b+=fig_weight[(s.typecheck&B111)-2]-100;         
   if (s.f1==-fk&&endspiel)  
    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]);
   else
    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]);
   if (s.f2!=0) pos[l+1].weight_s-=(int)pgm_read_word(&stat_weightw[s.f2-1][s.c2]);   
  }    
  count++; //estimated positions count
}
//****************************  
boolean check_w() {
  signed char f2=0;
  int j=0;
  if (pole[poswk]!=fk) {        
    for (int i=0;i<64;i++) if (pole[i]==fk) {  poswk=i; break; }      
  }  
  while (pgm_read_byte(&diag_step[poswk][j])!=99) {                
    if (pgm_read_byte(&diag_step[poswk][j])==88) f2=0; 
    else if (f2==0) {     
     f2=pole[pgm_read_byte(&diag_step[poswk][j])];
     if (f2==-fb||f2==-fq) return(true);
    }
    j++;
  }
  f2=0;  j=0;
  while (pgm_read_byte(&stra_step[poswk][j])!=99) {                     
    if (pgm_read_byte(&stra_step[poswk][j])==88) f2=0; 
    else if (f2==0) {         
     f2=pole[pgm_read_byte(&stra_step[poswk][j])];
     if (f2==-fr||f2==-fq) return(true);   
     if (j==0||pgm_read_byte(&stra_step[poswk][j])==88)
      if (f2==-fk) return(true);    
    }
    j++;
  }
  j=0;
  while (pgm_read_byte(&knight_step[poswk][j])!=99) {                
    if (pole[pgm_read_byte(&knight_step[poswk][j])]==-fn) return(true);                 
    j++;
  }
  if (row[poswk]<7) {
    if (column[poswk]>1&&pole[poswk-9]==-fp) return(true);
    if (column[poswk]<8&&pole[poswk-7]==-fp) return(true);
  }
  j=0;
  while (pgm_read_byte(&king_step[poswk][j])!=99) {                
    if (pole[pgm_read_byte(&king_step[poswk][j])]==-fk) return(true);                 
    j++;
  }  
  return(false);  
}
//****************************
boolean check_b() {  
  signed char f2=0;
  int j=0;
  if (pole[posbk]!=-fk) {        
    for (int i=0;i<64;i++) if (pole[i]==-fk) {  posbk=i; break; }      
  }    
  while (pgm_read_byte(&diag_step[posbk][j])!=99) {                
    if (pgm_read_byte(&diag_step[posbk][j])==88) f2=0; 
    else if (f2==0) {     
     f2=pole[pgm_read_byte(&diag_step[posbk][j])];
     if (f2==fb||f2==fq) return(true);    
    }
    j++;
  }
  f2=0;  j=0;
  while (pgm_read_byte(&stra_step[posbk][j])!=99) {                     
    if (pgm_read_byte(&stra_step[posbk][j])==88) f2=0; 
    else if (f2==0) {         
     f2=pole[pgm_read_byte(&stra_step[posbk][j])];
     if (f2==fr||f2==fq) return(true);    
     if (j==0||pgm_read_byte(&stra_step[posbk][j])==88)
      if (f2==fk) return(true);    
    }
    j++;
  }
  j=0;
  while (pgm_read_byte(&knight_step[posbk][j])!=99) {                
    if (pole[pgm_read_byte(&knight_step[posbk][j])]==fn) return(true);                 
    j++;
  }    
  if (row[posbk]>2) {
    if (column[posbk]>1&&pole[posbk+7]==fp) return(true);
    if (column[posbk]<8&&pole[posbk+9]==fp) return(true);
  }
  j=0;
  while (pgm_read_byte(&king_step[posbk][j])!=99) {                
    if (pole[pgm_read_byte(&king_step[posbk][j])]==fk) return(true);                 
    j++;
  }    
  return(false);  
}
//****************************

//****************************
void add_king(int l, int i) {
  signed char f1=pole[i];
  signed char f2;
  int j=0;
  while (pgm_read_byte(&king_step[i][j])!=99) {                
    f2=pole[pgm_read_byte(&king_step[i][j])];
    if (f2==0||f2<0&&f1>0||f2>0&&f1<0) {
     steps[pos[l].l_step].typecheck=0;      
     steps[pos[l].l_step].c1=i;      
     steps[pos[l].l_step].c2=pgm_read_byte(&king_step[i][j]);      
     steps[pos[l].l_step].f1=f1;      
     steps[pos[l].l_step].f2=f2;           
     pos[l].l_step++;            
    }             
    j++;
  }    
}
//****************************
void add_knight(int l, int i) {
  signed char f1=pole[i];
  signed char f2;
  int j=0;  
  while (pgm_read_byte(&knight_step[i][j])!=99) {                    
    f2=pole[pgm_read_byte(&knight_step[i][j])];
    if (f2==0||f2<0&&f1>0||f2>0&&f1<0) {
     steps[pos[l].l_step].typecheck=0;      
     steps[pos[l].l_step].c1=i;      
     steps[pos[l].l_step].c2=pgm_read_byte(&knight_step[i][j]);      
     steps[pos[l].l_step].f1=f1;      
     steps[pos[l].l_step].f2=f2;           
     pos[l].l_step++;                
    }             
    j++;
  }    
}
//****************************
void add_stra(int l, int i) {
  signed char f1=pole[i];
  signed char f2=0;
  int j=0;
  while (pgm_read_byte(&stra_step[i][j])!=99) {      
    if (pgm_read_byte(&stra_step[i][j])==88) f2=0;       
    else if (f2==0) {      
     f2=pole[pgm_read_byte(&stra_step[i][j])];
     if (f2==0||f2<0&&f1>0||f2>0&&f1<0) {
      steps[pos[l].l_step].typecheck=0;      
      steps[pos[l].l_step].c1=i;      
      steps[pos[l].l_step].c2=pgm_read_byte(&stra_step[i][j]);      
      steps[pos[l].l_step].f1=f1;      
      steps[pos[l].l_step].f2=f2;           
      
      pos[l].l_step++;            
     }          
    }
    j++;
  }
}
//****************************
void add_diag(int l, int i) {
  signed char f1=pole[i];
  signed char f2=0;
  int j=0;
  while (pgm_read_byte(&diag_step[i][j])!=99) {                
    if (pgm_read_byte(&diag_step[i][j])==88) f2=0; 
    else if (f2==0) {     
     f2=pole[pgm_read_byte(&diag_step[i][j])];
     if (f2==0||f2<0&&f1>0||f2>0&&f1<0) {
      steps[pos[l].l_step].typecheck=0;      
      steps[pos[l].l_step].c1=i;      
      steps[pos[l].l_step].c2=pgm_read_byte(&diag_step[i][j]);      
      steps[pos[l].l_step].f1=f1;      
      steps[pos[l].l_step].f2=f2;           
      pos[l].l_step++;            
     }         
    }
    j++;
  }    
}
//****************************
void add_one(int l, int c1, int c2) {
  steps[pos[l].l_step].typecheck=0;      
  steps[pos[l].l_step].c1=c1;      
  steps[pos[l].l_step].c2=c2;      
  steps[pos[l].l_step].f1=pole[c1];      
  steps[pos[l].l_step].f2=pole[c2];           
  pos[l].l_step++;                
}
//****************************
void sort_steps(int l) { //moves massive sort by weight
step_t buf;  
   for (int i=pos[l].b_step;i<pos[l].l_step-1;i++) { 
    int maxweight=steps[i].weight;
    int maxj=i;
    for (int j=i+1;j<pos[l].l_step;j++)  {
     if (steps[j].weight>maxweight) {
      maxweight=steps[j].weight; maxj=j;
     }      
    }    
    if (maxweight==0&&l>0) return;    
    if (maxj==i) continue;    
    buf=steps[i];
    steps[i]=steps[maxj];
    steps[maxj]=buf;    
   }    
}
//****************************  
void generate_steps(int l) { 
 if (l>0) pos[l].b_step=pos[l-1].l_step; else pos[l].b_step=ply+MAXDEPTH;
 pos[l].cur_step=pos[l].b_step; pos[l].l_step=pos[l].b_step;  
 int check;
 signed char f;  
 if (pole[poswk]!=fk) {      
   for (int i=0;i<64;i++) if (pole[i]==fk) {  poswk=i; break; }     
 } 
 if (pole[posbk]!=-fk) {      
     for (int i=0;i<64;i++) if (pole[i]==-fk) {  posbk=i; break; }        
 } 
 if (l>0) {
   if ((steps[pos[l-1].cur_step].typecheck&B1000)==0) {               
    if (pos[l].w) pos[l].check_on_table=check_w(); else pos[l].check_on_table=check_b();        
    if (pos[l].check_on_table) steps[pos[l-1].cur_step].typecheck=steps[pos[l-1].cur_step].typecheck|B1000;
   } else pos[l].check_on_table=1; 
  } else if (pos[0].w) pos[0].check_on_table=check_w(); else pos[0].check_on_table=check_b();         
 for (int ii=0;ii<64;ii++) {
  int i;
  if (pos[l].w) i=ii; else i=63-ii;
  f=pole[i];      
  if (f==0||f<0&&pos[l].w||f>0&&!pos[l].w) continue;  
  if (pos[l].l_step>MAXSTEPS-30) break;
  switch (abs(f)) {   
   case fn: add_knight(l,i);break;   
   case fb: add_diag(l,i); break;
   case fr: add_stra(l,i); break;   
   case fq: add_stra(l,i); add_diag(l,i); break;   
  }
 }  
  for (int ii=0;ii<64;ii++) {
   int i;
   if (pos[l].w) i=ii; else i=63-ii;
   f=pole[i];      
   if (f==0||f<0&&pos[l].w||f>0&&!pos[l].w) continue;   
   if (pos[l].l_step>MAXSTEPS-30) break;
   switch (abs(f)) {   
   case fk: add_king(l,i); break;           
   case fp:
      if (f==fp) {
       if (row[i]<7&&pole[i-8]==0) add_one(l,i,i-8); 
       if (row[i]==2&&pole[i-8]==0&&pole[i-16]==0) add_one(l,i,i-16);        
       if (row[i]==7) {
        if (pole[i-8]==0) {
         add_one(l,i,i-8); steps[pos[l].l_step-1].typecheck=4;      
         add_one(l,i,i-8); steps[pos[l].l_step-1].typecheck=5;      
         add_one(l,i,i-8); steps[pos[l].l_step-1].typecheck=6;      
         add_one(l,i,i-8); steps[pos[l].l_step-1].typecheck=7;               
        } 
        if (column[i]>1&&pole[i-9]<0) {
         add_one(l,i,i-9); steps[pos[l].l_step-1].typecheck=4;      
         add_one(l,i,i-9); steps[pos[l].l_step-1].typecheck=5;      
         add_one(l,i,i-9); steps[pos[l].l_step-1].typecheck=6;      
         add_one(l,i,i-9); steps[pos[l].l_step-1].typecheck=7;               
        }
        if (column[i]<8&&pole[i-7]<0) {
         add_one(l,i,i-7); steps[pos[l].l_step-1].typecheck=4;      
         add_one(l,i,i-7); steps[pos[l].l_step-1].typecheck=5;      
         add_one(l,i,i-7); steps[pos[l].l_step-1].typecheck=6;      
         add_one(l,i,i-7); steps[pos[l].l_step-1].typecheck=7;      
        }     
      } else {
       if (column[i]>1&&pole[i-9]<0) add_one(l,i,i-9); 
       if (column[i]<8&&pole[i-7]<0) add_one(l,i,i-7);        
      }
    } else if (f==-fp) {
      if (row[i]>2&&pole[i+8]==0) add_one(l,i,i+8); 
      if (row[i]==7&&pole[i+8]==0&&pole[i+16]==0) add_one(l,i,i+16); 
      if (row[i]==2) {
        if (pole[i+8]==0) {
         add_one(l,i,i+8); steps[pos[l].l_step-1].typecheck=4;      
         add_one(l,i,i+8); steps[pos[l].l_step-1].typecheck=5;      
         add_one(l,i,i+8); steps[pos[l].l_step-1].typecheck=6;      
         add_one(l,i,i+8); steps[pos[l].l_step-1].typecheck=7;               
        } 
        if (column[i]>1&&pole[i+7]>0) {
         add_one(l,i,i+7); steps[pos[l].l_step-1].typecheck=4;      
         add_one(l,i,i+7); steps[pos[l].l_step-1].typecheck=5;      
         add_one(l,i,i+7); steps[pos[l].l_step-1].typecheck=6;      
         add_one(l,i,i+7); steps[pos[l].l_step-1].typecheck=7;               
        }
        if (column[i]<8&&pole[i+9]>0) {
         add_one(l,i,i+9); steps[pos[l].l_step-1].typecheck=4;      
         add_one(l,i,i+9); steps[pos[l].l_step-1].typecheck=5;      
         add_one(l,i,i+9); steps[pos[l].l_step-1].typecheck=6;      
         add_one(l,i,i+9); steps[pos[l].l_step-1].typecheck=7;               
        }     
      } else {
       if (column[i]>1&&pole[i+7]>0) add_one(l,i,i+7); 
       if (column[i]<8&&pole[i+9]>0) add_one(l,i,i+9);            
      }
     } 
    } //switch
  } //   
  
  if (pos[l].pp!=0&&pole[pos[l].pp]==0) { //en passant  !!!
   if (pos[l].w==1) {
    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;}
    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;}
   } else {
    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;}
    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;}
   }
  }

 if (pos[l].w==1&&!pos[l].check_on_table) { //white catle
  if (pos[l].wrk) { //short     
   if (pole[60]==fk&&pole[61]==0&&pole[62]==0&&pole[63]==fr) {
    pole[60]=0; pole[61]=fk; poswk=61; check=check_w(); pole[60]=fk; poswk=60; pole[61]=0;    
    if (!check) {    
     steps[pos[l].l_step].typecheck=2;      
     steps[pos[l].l_step].c1=60;      
     steps[pos[l].l_step].c2=62;      
     steps[pos[l].l_step].f1=fk;      
     steps[pos[l].l_step].f2=0;           
     pos[l].l_step++;                      
    } 
   }
  }  
  if (pos[l].wrq) { //long
   if (pole[60]==fk&&pole[59]==0&&pole[58]==0&&pole[57]==0&&pole[56]==fr) {
    pole[60]=0; pole[59]=fk; poswk=59; check=check_w(); pole[60]=fk; poswk=60; pole[59]=0;    
    if (!check) {        
     steps[pos[l].l_step].typecheck=3;      
     steps[pos[l].l_step].c1=60;      
     steps[pos[l].l_step].c2=58;      
     steps[pos[l].l_step].f1=fk;      
     steps[pos[l].l_step].f2=0;           
     pos[l].l_step++;                      
    } 
   }
  }
 } else if (pos[l].w==0&&!pos[l].check_on_table) { //black castle  
  if (pos[l].brk) { //short
   if (pole[4]==-fk&&pole[5]==0&&pole[6]==0&&pole[7]==-fr) {
    pole[4]=0; pole[5]=-fk; posbk=5; check=check_b(); pole[4]=-fk; posbk=4; pole[5]=0;   
    if (!check) {    
     steps[pos[l].l_step].typecheck=2;      
     steps[pos[l].l_step].c1=4;      
     steps[pos[l].l_step].c2=6;      
     steps[pos[l].l_step].f1=-fk;      
     steps[pos[l].l_step].f2=0;           
     pos[l].l_step++;                      
    } 
   }
  }
  if (pos[l].brq) { //long
   if (pole[4]==-fk&&pole[3]==0&&pole[2]==0&&pole[1]==0&&pole[0]==-fr) {    
    pole[4]=0; pole[3]=-fk; posbk=3; check=check_b(); pole[4]=-fk; posbk=4; pole[3]=0;   
    if (!check) {    
     steps[pos[l].l_step].typecheck=3;      
     steps[pos[l].l_step].c1=4;      
     steps[pos[l].l_step].c2=2;      
     steps[pos[l].l_step].f1=-fk;      
     steps[pos[l].l_step].f2=0;           
     pos[l].l_step++;                      
    }
   }  
  }
 }  
 for (int i=pos[l].b_step;i<pos[l].l_step;i++) {       
  steps[i].typecheck=steps[i].typecheck&B111;
  steps[i].weight=abs(steps[i].f2);  
  if (abs(steps[i].typecheck&&B111)>3) steps[i].weight+=fig_weight[abs(steps[i].typecheck&&B111)-2];    
  steps[i].weight<<=2;
  if (l>0) { //add to weight of best level move 
       if (pos[l].cut.c2==steps[i].c2&&pos[l].cut.c1==steps[i].c1) steps[i].weight+=5; //best move
       if (steps[i].c2==steps[pos[l-1].cur_step].c2) steps[i].weight+=8; //taking last moves figure                    
  } 
 } //i     
 sort_steps(l);  
 
}
//****************************
int evaluate(int l) { //calculating position weight proportional
int res;  
  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); 
   else res=5000L*(pos[l].weight_b-pos[l].weight_w-pos[l].weight_s)/(pos[l].weight_w+pos[l].weight_b+2000);          
  if (debute) res+=random(30); 
  return res; 
} 
//****************************  
boolean checkd_w() {
  signed char f2=0;
  int j=0;
  while (pgm_read_byte(&diag_step[poswk][j])!=99) {                
    if (pgm_read_byte(&diag_step[poswk][j])==88) f2=0; 
    else if (f2==0) {     
     f2=pole[pgm_read_byte(&diag_step[poswk][j])];
     if (f2==-fb||f2==-fq) return(true);
    }
    j++;
  }
  f2=0;  j=0;
  while (pgm_read_byte(&stra_step[poswk][j])!=99) {                     
    if (pgm_read_byte(&stra_step[poswk][j])==88) f2=0; 
    else if (f2==0) {         
     f2=pole[pgm_read_byte(&stra_step[poswk][j])];
     if (f2==-fr||f2==-fq) return(true);   
     if (j==0||pgm_read_byte(&stra_step[poswk][j])==88)
      if (f2==-fk) return(true);    
    }
    j++;
  }  
  return(false);  
}
//****************************
boolean checkd_b() {  
  signed char f2=0;
  int j=0;
  while (pgm_read_byte(&diag_step[posbk][j])!=99) {                
    if (pgm_read_byte(&diag_step[posbk][j])==88) f2=0; 
    else if (f2==0) {     
     f2=pole[pgm_read_byte(&diag_step[posbk][j])];
     if (f2==fb||f2==fq) return(true);    
    }
    j++;
  }
  f2=0;  j=0;
  while (pgm_read_byte(&stra_step[posbk][j])!=99) {                     
    if (pgm_read_byte(&stra_step[posbk][j])==88) f2=0; 
    else if (f2==0) {         
     f2=pole[pgm_read_byte(&stra_step[posbk][j])];
     if (f2==fr||f2==fq) return(true);    
     if (j==0||pgm_read_byte(&stra_step[posbk][j])==88)
      if (f2==fk) return(true);    
    }
    j++;
  }  
  return(false);  
}
//****************************
int active(step_t& s) { //determines if move active before move
int j;      
  if (s.f2!=0||(s.typecheck&B111)>3) return 1; //taking or promotion
  if (abs(s.f2)==fk) return -1; //king moves not active, castling too
  switch (s.f1) {  
  case fp: 
     if (row[s.c2]>5) return 1; //en passant
     if (column[s.c2]>1&&posbk==s.c2-9||column[s.c2]<8&&posbk==s.c2-7) return 1; //check by pawn
     return -1;     
  case -fp: 
     if (row[s.c2]<4) return 1; //en passant
     if (column[s.c2]>1&&poswk==s.c2+7||column[s.c2]<8&&posbk==s.c2+9) return 1; //check by pawn
     return -1;          
  case fn:      
    j=0;
    while (pgm_read_byte(&knight_step[s.c2][j])!=99) {                    
     if (pole[pgm_read_byte(&knight_step[s.c2][j])]==-fk) return 1; //check by knight
     j++;
    }      
    return 0;     
  case -fn:         
    j=0;
    while (pgm_read_byte(&knight_step[s.c2][j])!=99) {                    
     if (pole[pgm_read_byte(&knight_step[s.c2][j])]==fk) return 1; //check by knight
     j++;
    }      
    return 0;     
  case fb: 
    if (diag1[s.c2]!=diag1[posbk]&&diag2[s.c2]!=diag2[posbk]) return -1; //not king diagonal
    return 0;
  case -fb: 
    if (diag1[s.c2]!=diag1[poswk]&&diag2[s.c2]!=diag2[poswk]) return -1; //not king diagonal
    return 0;
  case fr: 
    if (row[s.c2]!=row[posbk]&&column[s.c2]!=column[posbk]) return -1; //not horiz-vert of king
    return 0;
  case -fr: 
    if (row[s.c2]!=row[poswk]&&column[s.c2]!=column[poswk]) return -1; //not horiz-vert of king
    return 0;
  case fq: 
    if (diag1[s.c2]!=diag1[posbk]&&diag2[s.c2]!=diag2[posbk]&&        //not king diagonal  
        row[s.c2]!=row[posbk]&&column[s.c2]!=column[posbk]) return -1; //not horiz-vert of king
    return 0;
  case -fq: 
    if (diag1[s.c2]!=diag1[poswk]&&diag2[s.c2]!=diag2[poswk]&&        //not king diagonal
        row[s.c2]!=row[poswk]&&column[s.c2]!=column[poswk]) return -1; //not horiz-vert of king
    return 0;
  } //switch     
  return 0; 
}
//****************************  
int quiescence(int l, int alpha, int beta, int depthleft) {       
  if (depthleft<=0||l>MAXDEPTH-1) { 
    if (l>depth) depth=l;
    return evaluate(l);
  }
 // Serial.println(l);
  int score=-20000;             
  generate_steps(l);  
  if (pos[l].l_step>MAXSTEPS-30) return(evaluate(l));   
  //if (pos[l].l_step>maxstep) maxstep=pos[l].l_step;
  
  if (!pos[l].check_on_table) {   
    int weight=evaluate(l); 
    if (weight >= score) score=weight; 
    if (score>alpha) alpha=score;    
    if (alpha>=beta) return alpha;                
  }                      
  int check,checked,act; 
  for (int i=pos[l].b_step;i<pos[l].l_step;i++) {       
   act=1;
   if (!pos[l].check_on_table) {
    act=active(steps[i]);    
    if (act==-1)  continue;    
   }
   movestep(l,steps[i]);        
   check=0;   
   if (act==0) {
    if (pos[l].w) check=checkd_b(); else check=checkd_w();       
    if (check) steps[i].typecheck=steps[i].typecheck|B1000;
     if (!check) { backstep(l,steps[i]); continue; }      
   }   
   if (pos[l].w) checked=check_w(); else checked=check_b();     
   if (checked) { backstep(l,steps[i]);  continue; } //if check opens - move restricted
   
   if (check&&depthleft==1&&l<MAXDEPTH-1) depthleft++;     
   
   pos[l].cur_step=i;                       
   
   movepos(l,steps[i]);   
   steps[ply+l]=steps[i];
   int tmp=-quiescence(l+1,-beta,-alpha,depthleft-1);   
   backstep(l,steps[i]);   
   if (tmp>score) score=tmp;
   if (score>alpha) {
    alpha=score;      
    pos[l].best_step=i;                        
    pos[l].cut=steps[i];                            
   }
   if (alpha>=beta ) return alpha;    
  } 
  if (score==-20000) {
    if (pos[l].check_on_table) {
      score=-10000+l; 
    }
  }       
  return score;
}
//****************************  
void print_best(step_t& s) {
  String wei=String(getcoeff()*s.weight/100.,2);
  if (s.weight>9000) wei="+M"+String((10001-s.weight)/2); 
  int tim=(millis()-starttime)/1000;   
  Serial.print(str_step(pos[0].cut)+" ("+wei+") "+get_time(tim)+" ");  
} 
//****************************  
int draw_repeat(int l) { 
 if (l+ply<=12) return 0;
 for (int i=0;i<4;i++) {
  int li=ply+l-i; 
  if (steps[li].c1!=steps[li-4].c1||steps[li].c2!=steps[li-4].c2||
      steps[li].c1!=steps[li-8].c1||steps[li].c2!=steps[li-8].c2) return 0;
 }
 if (TRACE>0) Serial.println("repeat!"); 
 return 1;
}
//****************************  
int alphaBeta(int l, int alpha, int beta, int depthleft) {
 int score=-20000, check, tmp;      
   if (depthleft<=0||l>=MAXDEPTH) {
      int fd=4; //4    
      if (l<5&&steps[pos[0].cur_step].typecheck&B1000) fd+=2;   //   
      if (steps[pos[l-1].cur_step].f2!=0) fd+=2;  //  
      return quiescence(l,alpha,beta,fd);                    
   }   
   if (l>0) generate_steps(l);         
   if (pos[l].l_step>MAXSTEPS-30) return(evaluate(l));   
   //if (pos[l].l_step>maxstep) maxstep=pos[l].l_step;
   for (int i=pos[l].b_step;i<pos[l].l_step;i++) {       
    if (l==0) depth=depthleft;                      
    movestep(l,steps[i]);        
    if (pos[l].w) check=check_w(); else check=check_b();        
    if (check) { backstep(l,steps[i]);  continue; } //if check opens - move restricted    
    pos[l].cur_step=i;
    movepos(l,steps[i]);  
    steps[ply+l]=steps[i];
    if (TRACE>l) {
     if (l==0) {              
       Serial.print(str_step(steps[i])); Serial.print("  ");       
     } else {         
       Serial.println();             
       for (int ll=0;ll<l;ll++) Serial.print("      "); 
       Serial.print(String(l+1)+"- "+str_step(steps[i]));       
     }
    } //TRACE               
    tmp=-alphaBeta(l+1,-beta,-alpha,depthleft-1);   
    backstep(l,steps[i]);   
    if (draw_repeat(l)) tmp=0;     
    if (tmp>score) score=tmp;
    steps[i].weight=tmp;        
    if (score>alpha&&!halt) {
      alpha=score;      
      pos[l].best_step=i;                        
      pos[l].cut=steps[i];                        
      if (l==0) {        
        if (depthleft<10) Serial.print(" ");
        if (depth<10) Serial.print(" ");
        Serial.print(String(depthleft)+"/"+String(depth)+"  ");
        print_best(steps[i]);                
        Serial.println();
      }
    }
    if (TRACE>l) {
     if (l==0) {         
        Serial.println("        "+String(tmp)+"   "+String(depth));                    
     } else {         
        Serial.print(" = "+String(tmp));                
     }
    }              
    if (alpha>=beta) return alpha;                    
    if (halt||(l<3&&millis()-starttime>timelimith)) {  //time out or stop
      halt=1;
      return score;                        
    }
    if (millis()-guitime>100) gui();
   } //all moves   
   if (score==-20000) {
    if (pos[l].check_on_table) {
      score=-10000+l; steps[pos[l-1].cur_step].typecheck=steps[pos[l-1].cur_step].typecheck|B1000; 
    } else score=0;
   }       
   return score;
}
//****************************  
//****************************  
boolean is_draw() { //determines if draw on desk
  boolean draw=false;
  int cn=0,cbw=0,cbb=0,co=0,cb=0,cw=0;
  for (int i=0;i<64;i++) {  
    if (abs(pole[i])==1) co++;  
    if (abs(pole[i])>3&&abs(pole[i])<6) co++; //calculationg pawns, rooks, queens
    if (abs(pole[i])==6) continue;  //without kings
    if (abs(pole[i])==2) cn++; //number of knights
    if (abs(pole[i])==3&&(column[i]+row[i])%2==0) cbb++; //number of whitefields bishops
    if (abs(pole[i])==3&&(column[i]+row[i])%2==1) cbw++; //number of blackfields bishops
    if (pole[i]==3) cw++; //number of white bishops
    if (pole[i]==-3) cb++; //number of black bishops
  }
  if (cn==1&&co+cbb+cbw==0) draw=true;  //one knight only
  if (cbb+cbw==1&&co+cn==0) draw=true;  //one bishop only
  if (co+cn+cbb==0||co+cn+cbw==0) draw=true; //    
  if (co+cn==0&&cb==1&&cw==1) draw=true; //two bihops diffrent color
  if (draw) return draw;
  int lastmove=0;
  for (int i=0;i<ply;i++) //     
   if (abs(steps[i].c1)==fp||steps[i].f2!=0||(steps[i].typecheck&B111)!=0) lastmove=i;  
  if (lastmove<ply-100) return 1; //50 moves rule draw
  if (lastmove>ply-11) return 0; //     
  return 0; //!!!!!!!!!!!!!!!!!!!!      
  int ply0=ply;
  char poleb[64]; //
  while (lastmove<ply0-11) {
   start_game();           
   for (int i=0;i<=lastmove;i++) { //       
     pos[0].cur_step=i;
     movestep(0,steps[i]);   
     movepos(0,steps[i]);   
     pos[1].w=!pos[0].w;        
     pos[0]=pos[1];   
   }   
   for (int i=0;i<64;i++) poleb[i]=pole[i]; //   
   int repeats=0;

   lastmove++;
  }   
  start_game();           
  for (int i=0;i<ply0;i++) { //  
    pos[0].cur_step=i;
    movestep(0,steps[i]);   
    movepos(0,steps[i]);   
    pos[1].w=!pos[0].w;        
    pos[0]=pos[1];   
  }
  ply=ply0;
  
  return draw;  
}
//****************************
boolean is_debute() {
 int diff=0; 
 for (int i=0;i<64;i++) if (pole[i]!=(char) pgm_read_byte(&polestart[i])) diff++;
 debute=0;
 if (diff<13) debute=1;
 return debute;                                
}
//****************************  
int generate_legal() {
  kingpositions();
  generate_steps(0);
  int legal=0;
  int check;
  for (int i=pos[0].b_step;i<pos[0].l_step;i++) {     
    pos[0].cur_step=i;
    movestep(0,steps[i]);   
    if (pos[0].w) check=check_w();  else check=check_b();           
    //pos[0].check_on_table=check;    
    if (!check) legal++;         
    if (!check) steps[i].weight=0; else steps[i].weight=-30000;
    backstep(0,steps[i]);
  }    
  sort_steps(0);    
  pos[0].l_step=pos[0].b_step+legal; //illegal moves delete
  return(legal);  
}
//****************************  
void kingpositions() {
 for (int i=0;i<64;i++) { //kings positions definition
   if (pole[i]==fk) poswk=i;  
   if (pole[i]==-fk) posbk=i;
  }         
}  
//****************************  
int solve() {
step_t best;    
  starttime=millis();  
  if (is_draw()) { Serial.println(" DRAW!"); return 0; } //draw
  kingpositions();
  pos[0].weight_w=0;pos[0].weight_b=0; 
  for (int i=0;i<64;i++) { //enspile and figures weights definition 
    if (pole[i]<0) {
      pos[0].weight_b+=fig_weight[-pole[i]];      
    } else if (pole[i]>0) { 
      pos[0].weight_w+=fig_weight[pole[i]]; //full start weight 8000           
    }        
  }    
  if (pos[0].weight_w+pos[0].weight_b<3500) endspiel=true; else endspiel=false;    //3500?  
  is_debute();  
  //Serial.println(pos[0].weight_w);
  //Serial.println(pos[0].weight_b);
  pos[0].weight_s=0;
  pos[0].cut.f1=0; pos[0].cut.weight=0; 
  for (int i=0;i<64;i++) { //get statistic estimation
   int f=pole[i];
   if (!f) continue;
   if (abs(f)==fk&&endspiel) {
     if (f<0) 
       pos[0].weight_s-=(int)pgm_read_word(&stat_weightb[6][i]);                               
     else 
       pos[0].weight_s+=(int)pgm_read_word(&stat_weightw[6][i]);                                 
   } else {                
     if (f<0) 
      pos[0].weight_s-=(int)pgm_read_word(&stat_weightb[-f-1][i]);                               
     else 
      pos[0].weight_s+=(int)pgm_read_word(&stat_weightw[f-1][i]);                                     
   }      
  }  
  int startscore=evaluate(0);
  count=0; //maxstep=0;   
  for (int i=1;i<MAXDEPTH;i++) {
   if (i%2) pos[i].w=!pos[0].w; else pos[i].w=pos[0].w;    
   pos[i].pp=0;
  }   
  best.f1=0;
  int samebest=0;  
  int legal=generate_legal(); 
  if (legal==0) 
   if (pos[0].check_on_table) { Serial.println(" CHECKMATE!"); return -2; } // 
    else { Serial.println(" PAT!"); return 0; } // 
    
  if (legal==1)  { //ove answere
    pos[0].cut=steps[pos[0].b_step];
    movestep(0,pos[0].cut);   
    int v=evaluate(0);
    backstep(0,pos[0].cut);
    pos[0].cut.weight=v; 
    return 1;  
  }
  
  halt=0;
  BAction.Show("STOP");     
  BMenu.Hide();  
  randomSeed(millis());
  erasestatus();  
  //status_c1=-1; status_c2=-1;
  solving=1;  
  int ALPHA=-20000; 
  int BETA=20000;   
  level=2; //2 
  for (int x=0;x<MAXDEPTH;x++) { 
    pos[x].cut.f1=0; pos[x].cut.c2=-1;     
  } //            
  int score;      
  while (level<=10) {
   if (TRACE>0) {
    Serial.print(F("******* LEVEL=")); Serial.print(level);
    Serial.println();       
   }      
   for (int x=1;x<MAXDEPTH;x++) { 
    pos[x].cut.f1=0; pos[x].cut.c2=-1;     
   } //    0 
   for (int i=pos[0].b_step;i<pos[0].l_step;i++) {     //       
    pos[0].cur_step=i;
    movestep(0,steps[i]);   
    int check=0;
    if (pos[0].w) check=check_b(); else check=check_w();           
    if (check) steps[i].typecheck=steps[i].typecheck|B1000; 
    steps[i].weight+=evaluate(0)+(steps[i].typecheck&B1000)*30;    
    if (steps[i].f2!=0) steps[i].weight-=steps[i].f1;        
    backstep(0,steps[i]);
   }  
   steps[pos[0].b_step].weight+=10000; //first - always first
   sort_steps(0);        
   for (int i=pos[0].b_step;i<pos[0].l_step;i++) steps[i].weight=-8000;  //weights down
   
//   show_steps(0);
//   delay(100000000000000000000);  
   
   score=alphaBeta(0,ALPHA,BETA,level);   
   unsigned long tim=millis()-starttime;        
   boolean out=0;
   ALPHA=score-100;
   BETA=score+100;      
   if (score>=BETA) { out++; BETA=20000; }         
   if (score<=ALPHA) { out++; ALPHA=-20000; }   
   sort_steps(0);    //                      
   if (best.f1==steps[pos[0].b_step].f1&&best.c1==steps[pos[0].b_step].c1
       &&best.c2==steps[pos[0].b_step].c2&&best.typecheck==steps[pos[0].b_step].typecheck) {
    samebest++;
    if (samebest>=2&&score>=startscore+200&&tim>timelimith/4) break;     
   } else { best=steps[pos[0].b_step]; samebest=0; }
   if (score>9900||pos[0].cut.weight<-9900||tim>timelimith||halt) break;         
   
   if (!out) level++;      
  }
  Serial.print("Move=");
  print_best(pos[0].cut);  
  Serial.println(" count="+String(count)+" nps="+String(1000*count/(millis()-starttime)));
  //Serial.println(" maxstep="+String(maxstep));  
  halt=1;
  show_status();  
  solving=0;    
  if (pos[0].cut.weight<-9900) return -1; 
  return 1;  
}
//****************************
void wactest() {
char w[150];  String ss=""; 
  timelimith=120000;
  TRACE=0;
  for (int i=155;i<=300;i++) {
    strcpy_P(w, (char*)pgm_read_word(&wacs[i-1])); 
    ss=w;
    new_game(ss);       
    show_position();  
    clearstatus();
    show_board();  
    Serial.println(ss);
    Serial.println();
  }  
}
//**********************************
float getcoeff() {
  float coeff=(pos[0].weight_b+pos[0].weight_w+2000)/5000.0;
  //Serial.println(coeff,2);
  return coeff;
}
//**********************************
void show_status() {  
  String wei;
  
  if (pos[0].cut.weight>9000) wei="M"+String((10001-pos[0].cut.weight)/2); 
  else if (pos[0].cut.weight<-9000) wei="-M"+String((10001+pos[0].cut.weight)/2); 
   else wei=String(getcoeff()*pos[0].cut.weight/100.0,2); 
  if (pos[0].cut.weight>0) wei="+"+wei;   
  uint16_t c=GRAY;
  if (halt) { 
    wei=wei+" "+String(1000*count/(millis()-starttime)); 
    showstatus(get_time((millis()-starttime)/1000)+" "+String(level)+"/"+String(depth),str_step(pos[0].cut),wei,GRAY,WHITE); 
  } else {   
   showstatus(get_time((millis()-starttime)/1000)+"  "+String(level),str_step(pos[0].cut),wei);    
  } 
}
//********************************** 
void closemenu() {
  menu=0; 
  BMenu.Show("MENU");                         
  BBack.Hide();               
  BTime.Hide();                    
  BNew.Hide();                    
  BAuto.Hide();                    
  BRotate.Hide();                    
  BLoad.Hide();                    
  BSave.Hide();                    
  clearmenu();
  show_steps();
  clearstatus();     
  BAction.Show("START");  
}
//********************************** 
void check_gameend() {
   kingpositions();        
    String st;
    if (is_draw()) { gameover=1; st=F("draw!"); }
     else if (generate_legal()==0) 
     if (pos[0].check_on_table) { gameover=1; st=F("checkmate!"); } // 
      else { gameover=1; st=F("pat!"); } // 
    if (gameover)  showstatus(statusbuf1,st,statusbuf3,GRAY,RED); 
}
//********************************** 
void eepromsave() {
 EEPROM.put(0,limit);
 EEPROM.put(1,autow);
 EEPROM.put(2,autob);
 EEPROM.put(3,rotate);
 EEPROM.put(4,sound);
 EEPROM.put(5,ply);
 EEPROM.put(10,startpos);
 for (int i=0;i<ply;i++) 
  EEPROM.put(100+i*sizeof(step_t),steps[i]);
}
//********************************** 
void eepromload() {
 EEPROM.get(0,limit);
 EEPROM.get(1,autow);
 EEPROM.get(2,autob);
 EEPROM.get(3,rotate);
 EEPROM.get(4,sound); 
 EEPROM.get(10,startpos);
 start_game(); 
 EEPROM.get(5,ply); 
 for (int i=0;i<ply;i++) 
  EEPROM.get(100+i*sizeof(step_t),steps[i]);
 int pl=ply;
 for (int i=0;i<pl;i++) {
   pos[0].cur_step=i;
   if (pos[0].w==1) pos[1].w=1; else pos[1].w=0;    
   if (steps[i].f1!=0) {     
     movestep(0,steps[i]);   
     movepos(0,steps[i]);               
    } 
   pos[0]=pos[1];         
 } 
 ply=pl;
 if (ply%2==0) pos[0].w=1; else pos[0].w=0; 
}
//********************************** 
void gui() {
char w[150]; 
 if (Serial.available()) {
      String s="";
      while (Serial.available()) s=s+char(Serial.read());
      s.trim();     
      if (solving) {
       if (!halt) { 
        s.toUpperCase();   
        if (s=="STOP") { halt=1; Serial.println("STOPPED"); }     
       } 
      } else { //!solving
       if (s.indexOf("TIME")==0||s.indexOf("time")==0) {
        long tim=s.substring(4).toInt();
        if (tim!=0) timelimith=tim*1000;
        if (timelimith/60000>0) {
         Serial.print("timelimith = "+String(timelimith/60000)+" min ");
         int sec=(timelimith%60000)/1000;
         if (sec>0) Serial.println(String(sec)+" sec"); else Serial.println();  
        } else  Serial.println("timelimith = "+String(timelimith/1000)+" sec");    
       } else {
        if (s.indexOf("/")==-1) { 
         int n=s.toInt();
         if (n>0&&n<=300) {
          strcpy_P(w, (char*)pgm_read_word(&wacs[n-1])); 
          s=w;
         } else if (s=="0") s=F("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -"); 
         else return;
        }
        new_game(s); 
        gameover=0;      
        if (pos[0].w) { autow=1; autob=0; }  else { autob=1; autow=0; }
        initboard();
        show_position();  
        clearstatus();
        show_board();  
        Serial.println(s);        
       }      
      } 
      Serial.println(F("Command:"));
 } //serial
 if (gettouch()) {
  if (solving) {
   if (BAction.IsPressed()) { //calculation stop
     beep(100); 
     if (!halt) {
      halt=1;
      pause=1;
      BAction.Hide();        
     } 
   }   
  } else { //solving 
   if (BAction.IsPressed()) {        
     beep(100); 
     if (status_c1!=-1&&status_c2!=-1) { //player move try
      generate_legal();
      int g=0, gn=-1;      
      for (int i=pos[0].b_step;i<pos[0].l_step;i++) {
       if (steps[i].c1==status_c1&&steps[i].c2==status_c2) { g++; gn=i; }                
      }      
      if (!g) {
       beep(300);
       erasestatus();
      } else {
        pos[0].cur_step=gn;
        movestep(0,steps[gn]);   
        movepos(0,steps[gn]);   
        steps[ply]=steps[gn];        
        pos[1].w=!pos[0].w;        
        pos[0]=pos[1];   
        ply++;
        //show_position();
        show_board();       
        show_steps();    
        erasestatus();
        check_gameend();        
        BAction.Show("START");
        BMenu.Show("MENU");               
        pause=0;      
      }
     } else {
      pause=0;      
      BAction.Show("START");
     }
   } else if (BMenu.IsPressed()) {         
    beep(100); 
    if (!menu) {
     menu=1;   
     BAction.Hide();
     erasestatus();      
     clearmenu();     
     BMenu.Show("EXIT");
     if (ply>1) BBack.Show("BACK"); else BBack.Hide();                              
     BTime.Show(limitstrings[limit]);
     BNew.Show("NEW");                         
     String sa="";
     if (autow) sa="W";
     if (autob) sa=sa+"B";
     if (sa=="") sa="-";
     sa="AUTO:"+sa;
     BAuto.Show(sa);                         
     BRotate.Show("ROTATE");                         
     BLoad.Show();                         
     BSave.Show();                         
    } else { //menu
     closemenu();      
    }   
  } else if (BTime.IsPressed()) {        
     beep(100); 
     limit+=1; if (limit>9) limit=0;
     timelimith=limits[limit]*1000;
     //Serial.println(timelimith);
     BTime.Show(limitstrings[limit]);     
  } else if (BBack.IsPressed()) {        
     beep(100); 
     int pl=ply-2;
     if (pl<0) pl=0;           
     start_game();     
     for (int i=0;i<pl;i++) {
      pos[0].cur_step=i;
      if (pos[0].w==1) pos[1].w=1; else pos[1].w=0;    
      if (steps[i].f1!=0) {     
       movestep(0,steps[i]);   
       movepos(0,steps[i]);               
      } 
      pos[0]=pos[1];         
     } 
     ply=pl;
     if (ply%2==0) pos[0].w=1; else pos[0].w=0;
     closemenu();
     erasestatus();
     show_board();
     show_color();
     show_steps();          
  } else if (BNew.IsPressed()) {        
     beep(100);      
     new_game();
     cleardisplayboard();      
     show_board();
     border();
     closemenu();             
     erasestatus();     
     gameover=0;     
  } else if (BAuto.IsPressed()) {        
    beep(100);      
    if (!autow&&!autob) autob=1;   
     else if (!autow&&autob) { autow=1; autob=0; }  
      else if (autow&&!autob) { autow=1; autob=1; }  
       else { autow=0; autob=0; }  
    String sa="";
    if (autow) sa="W";
    if (autob) sa=sa+"B";
    if (sa=="") sa="-";
    sa="AUTO:"+sa;
    BAuto.Show(sa);                            
    show_color();
  } else if (BRotate.IsPressed()) {        
    beep(100);        
    BRotate.Show();                         
    if (rotate) rotate=0; else rotate=1;    
    erasestatus(); 
    border();
    cleardisplayboard();    
    show_board();
    show_color();
  } else if (BSave.IsPressed()) {        
    beep(100);        
    eepromsave();    
    BSave.Show();
    closemenu();             
    erasestatus();     
  } else if (BLoad.IsPressed()) {        
    beep(100);        
    eepromload();        
    BLoad.Show();
    closemenu();
    erasestatus();
    cleardisplayboard();      
    show_board();
    show_color();
    show_steps();          
    gameover=0;      
  } else {  
    signed char c=field_pressed();
    if (!menu&&c!=-1) {     
     if (status_c1==-1) { 
      status_c1=c; status_step(status_c1,1,getColor(220,0,0)); 
     }  else if (status_c2==-1) { 
      status_c2=c; status_step(status_c2,1,getColor(0,180,0));       
     }   
     if (status_c1!=-1&&status_c2!=-1&&c!=status_c2) erasestatus();      
    } 
   }      
  
  } //solving  
 } //gettouch 
 if (solving&&millis()-statustime>999) { show_status(); statustime=millis(); }
 if (!pause&&!menu&&!solving&&!gameover) {  
  if (pos[0].w&&autow||!pos[0].w&&autob) {
   halt=0;
   TRACE=0;  
   gameover=0;      
   int res=solve();  
   //Serial.println(res);
   if (res==1) {    
    movestep(0,pos[0].cut);   
    movepos(0,pos[0].cut);   
    steps[ply]=pos[0].cut;
    pos[0]=pos[1];   
    ply++;
    //show_position();
    show_board();       
    show_steps();     
    erasestatus();
    check_gameend();   
   } else { 
    String st=F("draw!");
    if (res==-1)  st=F("give up!"); 
     else if (res==-2) st=F("checkmate!"); 
    for (int k=0;k<11;k++) statusbuf2[k]='-'; 
    showstatus(statusbuf1,st,statusbuf3,GRAY,RED); 
    gameover=1;
   }
   BAction.Show("START");
   BMenu.Show("MENU");    
  } else { // 
  }
 }
 guitime=millis();
} 
//****************************
void loop() {
 gui();
 delay(100);
}
//****************************

gui.h:
Code:
#define mcufriend480
//#define adafruit320

#ifdef mcufriend480 
 //(MCUFRIEND screen 480x320)
 #include <UTFTGLUE.h>
 MCUFRIEND_kbv tft;
 #define screen_width 480 
 #define screen_height 320 
 #define mapx1 980
 #define mapx2 110
 #define mapy1 145
 #define mapy2 902
#endif

#ifdef adafruit320
 //(screen 320x240)
 #include <Adafruit_TFTLCD.h> 
 Adafruit_TFTLCD tft;
 #define screen_width 320 
 #define screen_height 240 
 #define mapx1 930
 #define mapx2 170
 #define mapy1 145
 #define mapy2 914
#endif 

#include "TouchScreen.h"
int XP = 6, YP = A1, XM = A2, YM = 7;  
TouchScreen ts(XP, YP, XM, YM, 300);   
TSPoint tp;  

int touchx,touchy,touched;         
#define MINPRESSURE 10
#define MAXPRESSURE 1000
// #define PinBuzz 44
#define PinBuzz 23

boolean rotate=0;
boolean sound=0;
boolean menu=0;
boolean pause=0;
unsigned long guitime=0;
unsigned long statustime=0;

char poledisp[64]; // 
char statusbuf1[11],statusbuf2[11],statusbuf3[11];
char status_c1, status_c2;

const uint8_t fig24[6][72] PROGMEM={
{0x0, 0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x1E, 0x0,  0x0,  0x3F, 0x0,  0x80, 0x7F, 0x0,  0x80, 0x7F, 0x0,
0x80, 0x7F, 0x0,  0x0,  0x3F, 0x0,  0x0,  0x1C, 0x0,  0x0,  0x1C, 0x0,  0x80, 0xFF, 0x0,  0x80, 0xFF, 0x0,  0x0,  0x1C, 0x0,  0x0,  0x1C, 0x0,
0x0,  0x3E, 0x0,  0x0,  0x7F, 0x0,  0x80, 0xFF, 0x0,  0xC0, 0xFF, 0x1,  0xE0, 0xFF, 0x3,  0xE0, 0xFF, 0x3,  0xE0, 0xFF, 0x3,  0x0,  0x0,  0x0
}, //pawn
{0x0, 0x0,  0x0,  0x0,  0x6E, 0x0,  0x0,  0xFF, 0x0,  0x80, 0xFF, 0x1,  0x80, 0xFF, 0x3,  0xC0, 0xFF, 0x7,  0xE0, 0xFF, 0xF,  0xE0, 0xF9, 0xF,
0xF0, 0xF8, 0xF,  0xF0, 0xF8, 0xF,  0x60, 0xFC, 0xF,  0x0,  0xFE, 0xF,  0x0,  0xFF, 0xF,  0x0,  0xFF, 0x7,  0x0,  0xFF, 0x3,  0x0,  0xFF, 0x1,
0x0,  0xFE, 0x0,  0x0,  0x7C, 0x0,  0x0,  0x38, 0x0,  0x0,  0x38, 0x0,  0x0,  0x7C, 0x0,  0xF0, 0xFF, 0xF,  0xF0, 0xFF, 0xF,  0x0,  0x0,  0x0
}, //knight
{0x0, 0x0,  0x0,  0x0,  0x3C, 0x0,  0x0,  0x7E, 0x0,  0x0,  0x7E, 0x0,  0x0,  0x3C, 0x0,  0x0,  0x18, 0x0,  0x80, 0xFF, 0x1,  0xC0, 0xFF, 0x3,
0xE0, 0xFF, 0x7,  0xE0, 0xFF, 0x7,  0xE0, 0xFF, 0x7,  0xE0, 0xFF, 0x7,  0xE0, 0xFF, 0x7,  0xE0, 0xFF, 0x7,  0xE0, 0xFF, 0x7,  0xE0, 0xFF, 0x7,
0xE0, 0xFF, 0x7,  0xC0, 0xFF, 0x3,  0x80, 0xFF, 0x1,  0x0,  0xFF, 0x0,  0x8,  0x7E, 0x10, 0x1C, 0x3C, 0x38, 0xFE, 0xFF, 0x7F, 0x0,  0x0,  0x0
}, //bishop
{0x0, 0x0,  0x0,  0xF0, 0x3C, 0xF,  0xF0, 0x3C, 0xF,  0xF0, 0xFF, 0xF,  0xE0, 0xFF, 0x7,  0xC0, 0xFF, 0x3,  0xC0, 0xFF, 0x3,  0xC0, 0xFF, 0x3,
0xC0, 0xFF, 0x3,  0xC0, 0xFF, 0x3,  0xC0, 0xFF, 0x3,  0xC0, 0xFF, 0x3,  0xC0, 0xFF, 0x3,  0xC0, 0xFF, 0x3,  0xC0, 0xFF, 0x3,  0xC0, 0xFF, 0x3,
0xC0, 0xFF, 0x3,  0xC0, 0xFF, 0x3,  0xC0, 0xFF, 0x3,  0xC0, 0xFF, 0x3,  0xE0, 0xFF, 0x7,  0xF0, 0xFF, 0xF,  0xF0, 0xFF, 0xF,  0x0,  0x0,  0x0
}, //rook
{0x0, 0x0,  0x0,  0xEE, 0xBD, 0x77, 0xEE, 0xBD, 0x77, 0xC6, 0x18, 0x63, 0xC6, 0x18, 0x63, 0xC6, 0x18, 0x63, 0xCC, 0x18, 0x33, 0xCC, 0x18, 0x33,
0xCC, 0x18, 0x33, 0xCC, 0x18, 0x33, 0xCC, 0x18, 0x33, 0x98, 0x99, 0x19, 0x98, 0x99, 0x19, 0x98, 0x99, 0x19, 0x98, 0x99, 0x19, 0x98, 0x99, 0x19,
0x30, 0xFF, 0xC,  0xB0, 0xFF, 0xD,  0xF0, 0xFF, 0xF,  0xE0, 0xFF, 0x7,  0xE0, 0xFF, 0x7,  0xF0, 0xFF, 0xF,  0xF0, 0xFF, 0xF,  0x0,  0x0,  0x0
}, //queen
{0x0, 0x0,  0x0,  0x0,  0x18, 0x0,  0xF0, 0x18, 0xF,  0xF8, 0x99, 0x1F, 0xFC, 0xDB, 0x3F, 0xFE, 0xFF, 0x7F, 0xFE, 0xFF, 0x7F, 0xFE, 0xFF, 0x7F,
0xFE, 0xFF, 0x7F, 0xFE, 0xFF, 0x7F, 0xFE, 0xFF, 0x7F, 0xFE, 0xFF, 0x7F, 0xFE, 0xFF, 0x7F, 0xFE, 0xFF, 0x3F, 0xFC, 0xFF, 0x1F, 0xF8, 0xFF, 0x1F,
0xF0, 0xFF, 0xF,  0xE0, 0xFF, 0x7,  0xE0, 0xFF, 0x7,  0xC0, 0xFF, 0x3,  0xE0, 0xFF, 0x7,  0xF0, 0xFF, 0xF,  0xF0, 0xFF, 0xF,  0x0,  0x0,  0x0
} //king
};

const uint8_t fig24_cont[6][72] PROGMEM={
{0x0, 0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x1C, 0x0,  0x0,  0x22, 0x0,  0x0,  0x41, 0x0,  0x80, 0x80, 0x0,  0x80, 0x80, 0x0,
0x80, 0x80, 0x0,  0x0,  0x41, 0x0,  0x0,  0x22, 0x0,  0xC0, 0xE3, 0x1,  0x40, 0x0,  0x1,  0x40, 0x0,  0x1,  0xC0, 0xE3, 0x1,  0x0,  0x22, 0x0,
0x0,  0x41, 0x0,  0x80, 0x80, 0x0,  0x40, 0x0,  0x1,  0x20, 0x0,  0x2,  0x10, 0x0,  0x4,  0x10, 0x0,  0x4,  0x10, 0x0,  0x4,  0xF0, 0xFF, 0x7
}, //pawn
{0x0, 0x6E, 0x0,  0x0,  0x91, 0x0,  0x80, 0x0,  0x1,  0x40, 0x2,  0x2,  0x40, 0x0,  0x4,  0x20, 0x0,  0x8,  0x10, 0x0,  0x10, 0x10, 0x6,  0x10,
0x8,  0x5,  0x10, 0x8,  0x5,  0x10, 0x90, 0x2,  0x10, 0x60, 0x1,  0x10, 0x80, 0x0,  0x10, 0x80, 0x0,  0x8,  0x80, 0x0,  0x4,  0x80, 0x0,  0x2,
0x0,  0x1,  0x1,  0x0,  0x82, 0x0,  0x0,  0x44, 0x0,  0x0,  0x44, 0x0,  0xF8, 0x83, 0x1F, 0x8,  0x0,  0x10, 0x8,  0x0,  0x10, 0xF8, 0xFF, 0x1F
}, //knight
{0x0, 0x3C, 0x0,  0x0,  0x42, 0x0,  0x0,  0x81, 0x0,  0x0,  0x81, 0x0,  0x0,  0x42, 0x0,  0x80, 0xE7, 0x1,  0x40, 0x0,  0x2,  0x20, 0x18, 0x4,
0x10, 0x18, 0x8,  0x10, 0x18, 0x8,  0x10, 0x18, 0x8,  0x90, 0xFF, 0x9,  0x90, 0xFF, 0x9,  0x10, 0x18, 0x8,  0x10, 0x18, 0x8,  0x10, 0x18, 0x8,
0x10, 0x18, 0x8,  0x20, 0x18, 0x4,  0x40, 0x18, 0x2,  0x88, 0x0,  0x11, 0x14, 0x81, 0x28, 0xE2, 0xC3, 0x47, 0x1,  0x0,  0x80, 0xFF, 0xFF, 0xFF
}, //bishop
{0xF8, 0x7E, 0x1F, 0x8,  0xC3, 0x10, 0x8,  0xC3, 0x10, 0x8,  0x0,  0x10, 0x10, 0x0,  0x8,  0xE0, 0xFF, 0x7,  0x20, 0x0,  0x4,  0x20, 0x0,  0x4,
0x20, 0x0,  0x4,  0x20, 0x0,  0x4,  0x20, 0x0,  0x4,  0x20, 0x0,  0x4,  0x20, 0x0,  0x4,  0x20, 0x0,  0x4,  0x20, 0x0,  0x4,  0x20, 0x0,  0x4,
0x20, 0x0,  0x4,  0x20, 0x0,  0x4,  0x20, 0x0,  0x4,  0xE0, 0xFF, 0x7,  0x10, 0x0,  0x8,  0x8,  0x0,  0x10, 0x8,  0x0,  0x10, 0xF8, 0xFF, 0x1F
}, //rook
{0xEF, 0xBD, 0xF7, 0x11, 0x42, 0x88, 0x11, 0x42, 0x88, 0x29, 0xA5, 0x94, 0x29, 0xA5, 0x94, 0x29, 0xA5, 0x94, 0x32, 0xA5, 0x4C, 0x32, 0xA5, 0x4C,
0x32, 0xA5, 0x4C, 0x32, 0xA5, 0x4C, 0x32, 0xA5, 0x4C, 0x64, 0x66, 0x26, 0x64, 0x66, 0x26, 0x64, 0x66, 0x26, 0x64, 0x66, 0x26, 0x64, 0x66, 0x26,
0xC8, 0x0,  0x13, 0x48, 0x0,  0x12, 0x8,  0x0,  0x10, 0x10, 0x0,  0x8,  0xF0, 0xFF, 0xF,  0x8,  0x0,  0x10, 0x8,  0x0,  0x10, 0xF8, 0xFF, 0x1F
}, //queen
{0x0, 0x18, 0x0,  0xF0, 0x24, 0xF,  0x8,  0xA5, 0x10, 0x4,  0x66, 0x20, 0x2,  0x24, 0x40, 0x1,  0x24, 0x80, 0x1,  0x18, 0x80, 0x1,  0x18, 0x80,
0x1,  0x18, 0x80, 0x1,  0x18, 0x80, 0x1,  0x18, 0x80, 0x1,  0x18, 0x80, 0x1,  0x18, 0x80, 0x1,  0x18, 0x40, 0x2,  0x18, 0x20, 0x4,  0x18, 0x20,
0xE8, 0xFF, 0x17, 0x10, 0x0,  0x8,  0x10, 0x0,  0x8,  0x20, 0x0,  0x4,  0xF0, 0xFF, 0xF,  0x8,  0x0,  0x10, 0x8,  0x0,  0x10, 0xF8, 0xFF, 0x1F
} //king
};

const uint8_t fig32[6][128] PROGMEM={
{0x0, 0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,
0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0xF0, 0xF,  0x0,  0x0,  0xF8, 0x1F, 0x0,
0x0,  0xFC, 0x3F, 0x0,  0x0,  0xFC, 0x3F, 0x0,  0x0,  0xFC, 0x3F, 0x0,  0x0,  0xF8, 0x1F, 0x0,
0x0,  0xF0, 0xF,  0x0,  0x0,  0xE0, 0x7,  0x0,  0x0,  0xFF, 0xFF, 0x0,  0x0,  0xFF, 0xFF, 0x0,
0x0,  0xFF, 0xFF, 0x0,  0x0,  0xE0, 0x7,  0x0,  0x0,  0xF0, 0xF,  0x0,  0x0,  0xF0, 0xF,  0x0,
0x0,  0xF8, 0x1F, 0x0,  0x0,  0xF8, 0x1F, 0x0,  0x0,  0xFC, 0x3F, 0x0,  0x0,  0xFE, 0x7F, 0x0,
0x0,  0xFE, 0x7F, 0x0,  0x0,  0xFF, 0xFF, 0x0,  0x0,  0xFF, 0xFF, 0x0,  0x80, 0xFF, 0xFF, 0x1,
0x80, 0xFF, 0xFF, 0x1,  0x80, 0xFF, 0xFF, 0x1,  0x80, 0xFF, 0xFF, 0x1,  0x0,  0x0,  0x0,  0x0
}, 
{0x0, 0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0xC0, 0xC,  0x0,  0x0,  0xE0, 0x1C, 0x0,
0x0,  0xF8, 0x3F, 0x0,  0x0,  0xFE, 0x7F, 0x0,  0x0,  0xFF, 0xFF, 0x0,  0x80, 0xFF, 0xFF, 0x1,
0xC0, 0xFF, 0xFF, 0x3,  0xE0, 0xFF, 0xFF, 0x7,  0xF0, 0xFF, 0xFF, 0xF,  0xF0, 0xBF, 0xFF, 0x1F,
0xF0, 0x81, 0xFF, 0x1F, 0xE0, 0xC0, 0xFF, 0x1F, 0x0,  0xE0, 0xFF, 0x1F, 0x0,  0xF0, 0xFF, 0x1F,
0x0,  0xF8, 0xFF, 0x1F, 0x0,  0xFC, 0xFF, 0x1F, 0x0,  0xFE, 0xFF, 0xF,  0x0,  0xFE, 0xFF, 0x7,
0x0,  0xFE, 0xFF, 0x1,  0x0,  0xFE, 0xFF, 0x0,  0x0,  0xFE, 0x7F, 0x0,  0x0,  0xFE, 0x3F, 0x0,
0x0,  0xFE, 0x1F, 0x0,  0x0,  0xFC, 0x1F, 0x0,  0x0,  0xF8, 0xF,  0x0,  0x0,  0xF0, 0xF,  0x0,
0x0,  0xFF, 0xFF, 0x0,  0x80, 0xFF, 0xFF, 0x1,  0x80, 0xFF, 0xFF, 0x1,  0x0,  0x0,  0x0,  0x0
}, {
0x0,  0x0,  0x0,  0x0,  0x0,  0xE0, 0x7,  0x0,  0x0,  0xF0, 0xF,  0x0,  0x0,  0xF8, 0x1F, 0x0,
0x0,  0xFC, 0x3F, 0x0,  0x0,  0xF8, 0x1F, 0x0,  0x0,  0xF0, 0xF,  0x0,  0x0,  0xE0, 0x7,  0x0,
0x0,  0xFE, 0x7F, 0x0,  0x0,  0xFF, 0xFF, 0x0,  0x80, 0xFF, 0xFF, 0x1,  0x80, 0xFF, 0xFF, 0x1,
0x80, 0xFF, 0xFF, 0x1,  0x80, 0xFF, 0xFF, 0x1,  0x80, 0xFF, 0xFF, 0x1,  0x80, 0xFF, 0xFF, 0x1,
0x80, 0xFF, 0xFF, 0x1,  0x80, 0xFF, 0xFF, 0x1,  0x80, 0xFF, 0xFF, 0x1,  0x80, 0xFF, 0xFF, 0x1,
0x80, 0xFF, 0xFF, 0x1,  0x80, 0xFF, 0xFF, 0x1,  0x80, 0xFF, 0xFF, 0x1,  0x0,  0xFF, 0xFF, 0x0,
0x0,  0xFE, 0x7F, 0x0,  0x0,  0xFC, 0x3F, 0x0,  0x20, 0xF8, 0x1F, 0x4,  0x70, 0xF0, 0xF,  0xE,
0xF8, 0xFF, 0xFF, 0x1F, 0xF8, 0xFF, 0xFF, 0x1F, 0xF8, 0xFF, 0xFF, 0x1F, 0x0,  0x0,  0x0,  0x0
}, {
 0x0, 0x0,  0x0,  0x0,  0xE0, 0xE3, 0xC7, 0x7,  0xE0, 0xE3, 0xC7, 0x7,  0xE0, 0xE3, 0xC7, 0x7,
0xE0, 0xFF, 0xFF, 0x7,  0xE0, 0xFF, 0xFF, 0x7,  0xE0, 0xFF, 0xFF, 0x7,  0xC0, 0xFF, 0xFF, 0x3,
0x80, 0xFF, 0xFF, 0x1,  0x0,  0xFF, 0xFF, 0x0,  0x0,  0xFF, 0xFF, 0x0,  0x0,  0xFF, 0xFF, 0x0,
0x0,  0xFF, 0xFF, 0x0,  0x0,  0xFF, 0xFF, 0x0,  0x0,  0xFF, 0xFF, 0x0,  0x0,  0xFF, 0xFF, 0x0,
0x0,  0xFF, 0xFF, 0x0,  0x0,  0xFF, 0xFF, 0x0,  0x0,  0xFF, 0xFF, 0x0,  0x0,  0xFF, 0xFF, 0x0,
0x0,  0xFF, 0xFF, 0x0,  0x0,  0xFF, 0xFF, 0x0,  0x0,  0xFF, 0xFF, 0x0,  0x0,  0xFF, 0xFF, 0x0,
0x80, 0xFF, 0xFF, 0x1,  0xC0, 0xFF, 0xFF, 0x3,  0xE0, 0xFF, 0xFF, 0x7,  0xF0, 0xFF, 0xFF, 0xF,
0xF0, 0xFF, 0xFF, 0xF,  0xF0, 0xFF, 0xFF, 0xF,  0xF0, 0xFF, 0xFF, 0xF,  0x0,  0x0,  0x0,  0x0
}, {
0x0,  0x0,  0x0,  0x0,  0x0,  0x80, 0x1,  0x0,  0x0,  0xC6, 0x63, 0x0,  0x0,  0xCF, 0xF3, 0x0,
0xC,  0x8F, 0xF1, 0x30, 0x1E, 0x86, 0x61, 0x78, 0x1E, 0xC6, 0x63, 0x78, 0xC,  0xCF, 0xF3, 0x30,
0xC,  0xCF, 0xF3, 0x30, 0x1E, 0xCF, 0xF3, 0x78, 0x1E, 0xCF, 0xF3, 0x78, 0x1C, 0xCF, 0xF3, 0x38,
0x3C, 0x8E, 0x71, 0x3C, 0x3C, 0xCE, 0x73, 0x3C, 0x38, 0xEE, 0x77, 0x1C, 0x38, 0xFE, 0x7F, 0x1E,
0x38, 0xFF, 0xFF, 0x1E, 0x78, 0xFF, 0xFF, 0x1E, 0xF0, 0xFF, 0xFF, 0xF,  0xF0, 0xFF, 0xFF, 0xF,
0xF0, 0xFF, 0xFF, 0xF,  0xF0, 0xFF, 0xFF, 0xF,  0xF0, 0xFF, 0xFF, 0x7,  0xE0, 0xFF, 0xFF, 0x7,
0xC0, 0xFF, 0xFF, 0x3,  0xC0, 0xFF, 0xFF, 0x3,  0x80, 0xFF, 0xFF, 0x1,  0x0,  0xFF, 0xFF, 0x0,
0x0,  0xFF, 0xFF, 0x0,  0x80, 0xFF, 0xFF, 0x1,  0x80, 0xFF, 0xFF, 0x1,  0x0,  0x0,  0x0,  0x0
}, {
0x0,  0x0,  0x0,  0x0,  0x0,  0x80, 0x1,  0x0,  0x0,  0xC0, 0x3,  0x0,  0x0,  0xC0, 0x3,  0x0,
0xE0, 0x81, 0x81, 0x7,  0xF8, 0x87, 0xE1, 0x1F, 0xFC, 0xCF, 0xF3, 0x3F, 0xFE, 0xDF, 0xFB, 0x7F,
0xFE, 0xFF, 0xFF, 0x7F, 0xFE, 0xFF, 0xFF, 0x7F, 0xFE, 0xFF, 0xFF, 0x7F, 0xFE, 0xFF, 0xFF, 0x7F,
0xFE, 0xFF, 0xFF, 0x7F, 0xFE, 0xFF, 0xFF, 0x7F, 0xFE, 0xFF, 0xFF, 0x7F, 0xFE, 0xFF, 0xFF, 0x7F,
0xFE, 0xFF, 0xFF, 0x7F, 0xFE, 0xFF, 0xFF, 0x7F, 0xFC, 0xFF, 0xFF, 0x3F, 0xF8, 0xFF, 0xFF, 0x1F,
0xF8, 0xFF, 0xFF, 0x1F, 0xF0, 0xFF, 0xFF, 0xF,  0xF0, 0xFF, 0xFF, 0xF,  0xE0, 0xFF, 0xFF, 0x7,
0xC0, 0xFF, 0xFF, 0x3,  0xC0, 0xFF, 0xFF, 0x3,  0x80, 0xFF, 0xFF, 0x1,  0x0,  0xFF, 0xFF, 0x0,
0x0,  0xFF, 0xFF, 0x0,  0x80, 0xFF, 0xFF, 0x1,  0x80, 0xFF, 0xFF, 0x1,  0x0,  0x0,  0x0,  0x0
}
};

const uint8_t fig32_cont[6][128] PROGMEM={
{0x0, 0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,
0x0,  0x0,  0x0,  0x0,  0x0,  0xF0, 0xF,  0x0,  0x0,  0x8,  0x10, 0x0,  0x0,  0x4,  0x20, 0x0,
0x0,  0x2,  0x40, 0x0,  0x0,  0x2,  0x40, 0x0,  0x0,  0x2,  0x40, 0x0,  0x0,  0x4,  0x20, 0x0,
0x0,  0x8,  0x10, 0x0,  0x80, 0x1F, 0xF8, 0x1,  0x80, 0x0,  0x0,  0x1,  0x80, 0x0,  0x0,  0x1,
0x80, 0x0,  0x0,  0x1,  0x80, 0x1F, 0xF8, 0x1,  0x0,  0x8,  0x10, 0x0,  0x0,  0x8,  0x10, 0x0,
0x0,  0x4,  0x20, 0x0,  0x0,  0x4,  0x20, 0x0,  0x0,  0x2,  0x40, 0x0,  0x0,  0x1,  0x80, 0x0,
0x0,  0x1,  0x80, 0x0,  0x80, 0x0,  0x0,  0x1,  0x80, 0x0,  0x0,  0x1,  0x40, 0x0,  0x0,  0x2,
0x40, 0x0,  0x0,  0x2,  0x40, 0xFF, 0xFF, 0x2,  0x40, 0x0,  0x0,  0x2,  0xC0, 0xFF, 0xFF, 0x3
}, {
0x0,  0x0,  0x0,  0x0,  0x0,  0xC0, 0xC,  0x0,  0x0,  0x20, 0x13, 0x0,  0x0,  0x18, 0x23, 0x0,
0x0,  0x6,  0x60, 0x0,  0x0,  0x19, 0x90, 0x0,  0x80, 0x18, 0x88, 0x1,  0x40, 0x0,  0x40, 0x2,
0x20, 0x0,  0x20, 0x6,  0x10, 0x0,  0x0,  0x9,  0x8,  0x0,  0x80, 0x18, 0x8,  0x40, 0x0,  0x24,
0x8,  0x7E, 0x0,  0x22, 0x10, 0x21, 0x0,  0x20, 0xE0, 0x10, 0x0,  0x20, 0x0,  0x8,  0x0,  0x20,
0x0,  0x4,  0x0,  0x20, 0x0,  0x2,  0x0,  0x20, 0x0,  0x1,  0x0,  0x10, 0x0,  0x1,  0x0,  0x8,
0x0,  0x1,  0x0,  0x6,  0x0,  0x1,  0x0,  0x1,  0x0,  0x1,  0x80, 0x0,  0x0,  0x1,  0x40, 0x0,
0x0,  0x1,  0x20, 0x0,  0x0,  0x2,  0x20, 0x0,  0x0,  0x4,  0x10, 0x0,  0x0,  0xF,  0xF0, 0x0,
0x80, 0x0,  0x0,  0x1,  0x40, 0xFF, 0xFF, 0x2,  0x40, 0x0,  0x0,  0x2,  0xC0, 0xFF, 0xFF, 0x3
}, {
0x0,  0xE0, 0x7,  0x0,  0x0,  0x10, 0x8,  0x0,  0x0,  0x8,  0x10, 0x0,  0x0,  0x4,  0x20, 0x0,
0x0,  0x2,  0x40, 0x0,  0x0,  0x4,  0x20, 0x0,  0x0,  0x8,  0x10, 0x0,  0x0,  0x1E, 0x78, 0x0,
0x0,  0x1,  0x80, 0x0,  0x80, 0x80, 0x1,  0x1,  0x40, 0x80, 0x1,  0x2,  0x40, 0x80, 0x1,  0x2,
0x40, 0x80, 0x1,  0x2,  0x40, 0x80, 0x1,  0x2,  0x40, 0x80, 0x1,  0x2,  0x40, 0xFE, 0x7F, 0x2,
0x40, 0xFE, 0x7F, 0x2,  0x40, 0xFE, 0x7F, 0x2,  0x40, 0x80, 0x1,  0x2,  0x40, 0x80, 0x1,  0x2,
0x40, 0x80, 0x1,  0x2,  0x40, 0x80, 0x1,  0x2,  0x40, 0x80, 0x1,  0x2,  0x80, 0x80, 0x1,  0x1,
0x0,  0x81, 0x81, 0x0,  0x20, 0x82, 0x41, 0x4,  0x50, 0x4,  0x20, 0xA,  0x88, 0xF,  0xF0, 0x11,
0x4,  0x0,  0x0,  0x20, 0x4,  0x0,  0x0,  0x20, 0x4,  0x0,  0x0,  0x20, 0xFC, 0xFF, 0xFF, 0x3F
}, {
0xF0,  0xF7, 0xEF, 0xF,  0x10, 0x14, 0x28, 0x8,  0x10, 0x14, 0x28, 0x8,  0x10, 0x1C, 0x38, 0x8,
0x10, 0x0,  0x0,  0x8,  0x90, 0x81, 0x81, 0x9,  0x90, 0xFF, 0xFF, 0x9,  0x20, 0x0,  0x0,  0x4,
0x40, 0x0,  0x0,  0x2,  0x80, 0x0,  0x0,  0x1,  0x80, 0x0,  0x0,  0x1,  0x80, 0x0,  0x0,  0x1,
0x80, 0x0,  0x0,  0x1,  0x80, 0x0,  0x0,  0x1,  0x80, 0x0,  0x0,  0x1,  0x80, 0x0,  0x0,  0x1,
0x80, 0x0,  0x0,  0x1,  0x80, 0x0,  0x0,  0x1,  0x80, 0x0,  0x0,  0x1,  0x80, 0x0,  0x0,  0x1,
0x80, 0x0,  0x0,  0x1,  0x80, 0x0,  0x0,  0x1,  0x80, 0x0,  0x0,  0x1,  0x80, 0x0,  0x0,  0x1,
0x40, 0xFE, 0x7F, 0x2,  0x20, 0x0,  0x0,  0x4,  0x10, 0x0,  0x0,  0x8,  0x8,  0x0,  0x0,  0x10,
0xE8, 0xFF, 0xFF, 0x17, 0x8,  0x0,  0x0,  0x10, 0x8,  0x0,  0x0,  0x10, 0xF8, 0xFF, 0xFF, 0x1F
}, {
0x0,  0x80, 0x1,  0x0,  0x0,  0x46, 0x62, 0x0,  0x0,  0x29, 0x94, 0x0,  0x8C, 0x30, 0xC,  0x31,
0x92, 0x50, 0xA,  0x49, 0x21, 0x49, 0x92, 0x84, 0x21, 0x29, 0x94, 0x84, 0x92, 0x30, 0xC,  0x49,
0x92, 0x30, 0xC,  0x49, 0xA1, 0x30, 0xC,  0x85, 0xA1, 0x30, 0xC,  0x85, 0xA2, 0x30, 0xC,  0x45,
0x42, 0x51, 0x8A, 0x42, 0x42, 0x31, 0x8C, 0x42, 0x44, 0x11, 0x88, 0x22, 0x44, 0x1,  0x80, 0x21,
0xC4, 0x0,  0x0,  0x21, 0x84, 0x0,  0x0,  0x21, 0x8,  0xE0, 0x7,  0x10, 0x8,  0x1E, 0x78, 0x10,
0xC8, 0x1,  0x80, 0x13, 0x8,  0x80, 0x1,  0x10, 0x8,  0xC2, 0x43, 0x8,  0x10, 0x87, 0xE1, 0x8,
0x20, 0x2,  0x40, 0x4,  0x20, 0x0,  0x0,  0x4,  0x40, 0x0,  0x0,  0x2,  0x80, 0x0,  0x0,  0x1,
0x80, 0xFE, 0x7F, 0x1,  0x40, 0x0,  0x0,  0x2,  0x40, 0x0,  0x0,  0x2,  0xC0, 0xFF, 0xFF, 0x3  
}, {
 0x0, 0x80, 0x1,  0x0,  0x0,  0x40, 0x2,  0x0,  0x0,  0x20, 0x4,  0x0,  0xE0, 0x21, 0x84, 0x7,
0x18, 0x46, 0x62, 0x18, 0x4,  0x48, 0x12, 0x20, 0x2,  0x30, 0xC,  0x40, 0x1,  0x30, 0xC,  0x80,
0x1,  0x60, 0x6,  0x80, 0x1,  0xC0, 0x3,  0x80, 0x1,  0x80, 0x1,  0x80, 0x1,  0x80, 0x1,  0x80,
0x1,  0x80, 0x1,  0x80, 0x1,  0x80, 0x1,  0x80, 0x1,  0x80, 0x1,  0x80, 0x1,  0x80, 0x1,  0x80,
0x1,  0x80, 0x1,  0x80, 0x1,  0x80, 0x1,  0x80, 0x2,  0x80, 0x1,  0x40, 0x4,  0x80, 0x1,  0x20,
0x4,  0x80, 0x1,  0x20, 0x8,  0xE0, 0x7,  0x10, 0x8,  0x1C, 0x38, 0x10, 0xD0, 0x3,  0xC0, 0xB,
0x20, 0x80, 0x1,  0x4,  0x20, 0xC6, 0x63, 0x4,  0x40, 0x80, 0x1,  0x2,  0x80, 0x0,  0x0,  0x1,
0x80, 0xFE, 0x5F, 0x1,  0x40, 0x0,  0x0,  0x2,  0x40, 0x0,  0x0,  0x2,  0xC0, 0xFF, 0xFF, 0x3
}
};

uint16_t BLACK,BLUE,RED,GREEN,CYAN,MAGENTA,YELLOW,WHITE,GRAY,DARK,GRAY2,BLACKF,WHITEF;

//********************************** 
class Button {
public:
int bx,by,bw,bh,bshift;
String bs;
const uint8_t* bp;
 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);
 void Show(int shift); 
 void Show(String s); 
 void Hide();
 boolean IsPressed();
private:
boolean active;
 void ishow(uint16_t textcolor,uint16_t backcolor);
};
Button::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) {
  if (screen_height==320) {
   bx=x; by=y; bw=w; bh=h; 
  } else {
   bx=x1; by=y1; bw=w1; bh=h1;  
  }
  bs=s; bp=p; bshift=shift;
};
void Button::Show(int shift=0) {
 bshift=shift; 
 active=true;
 ishow(WHITE,DARK);  
};
void Button::Show(String s) {
 bs=s; 
 active=true;
 ishow(WHITE,DARK);  
};
void Button::Hide() { 
 active=false; 
 ishow(GRAY,DARK);  
};
boolean Button::IsPressed() {  
  if (active&&abs(bx+bw/2-touchx)<bw/2&&abs(by+bh/2-touchy)<bh/2) {
    ishow(WHITE,GRAY); 
    touchx=0; touchy=0;        
    return true;
  } 
  return false;
};  
void Button::ishow(uint16_t textcolor,uint16_t backcolor) {  
  tft.fillRoundRect(bx+2,by+2,bw,bh,3,GRAY2);               
  tft.fillRoundRect(bx,by,bw,bh,3,backcolor);               
  tft.setTextColor(textcolor);
  if (screen_height==320) {
   tft.setTextSize(2);    
   tft.setCursor(bx+(bw-bs.length()*12)/2,by+(bh-12)/2);       
  }  else {
   tft.setTextSize(1);    
   tft.setCursor(bx+(bw-bs.length()*6)/2,by+(bh-8)/2);           
  }
  if (bp!=NULL) { 
   tft.drawBitmap(1+bx+(bw-16)/2, by+(bh-16)/2, bp+bshift*32, 16, 16,textcolor);          
  } 
  else  tft.print(bs);    
}

Button BAction(354, 280, 100, 30, 252, 210, 60, 20, "START");
Button BMenu(354, 20, 100, 30, 252, 20, 60, 20, "MENU");
Button BBack(354, 58, 100, 30, 252, 47, 60, 20, "BACK");
Button BTime(354, 96, 100, 30, 252, 74, 60, 20, "5 s");
Button BNew(354, 134, 100, 30, 252, 101, 60, 20, "NEW");
Button BAuto(354, 172, 100, 30, 252, 128, 60, 20, "AUTO:B");
Button BRotate(354, 210, 100, 30, 252, 155, 60, 20, "ROTATE");
Button BSave(354, 248, 100, 30, 252, 182, 60, 20, "SAVE");
Button BLoad(354, 286, 100, 30, 252, 209, 60, 20, "LOAD");

//********************************** 
void drawBitmap(int16_t x, int16_t y,
            const uint8_t *bitmap, int16_t w, int16_t h,
            uint16_t color) {
  int16_t i, j, byteWidth = (w + 7) / 8;  
  for(j=0; j<h; j++) {
    for(i=0; i<w; i++ ) {      
        if(pgm_read_byte(bitmap + j * byteWidth + i / 8) & (1 << (i % 8))) {        
        tft.drawPixel(x+i, y+j, color);
      }      
    }
  }
}
//****************************
uint16_t getColor(uint8_t red, uint8_t green, uint8_t blue)
{
  red   >>= 3;
  green >>= 2;
  blue  >>= 3;
  return (red << 11) | (green << 5) | blue;
}
//****************************
void show_fig(int c) {
uint16_t colorf,color,color_cont;  
   colorf=BLACKF;   
   int i=column[c]-1; 
   int j=8-row[c];
   if ((i+j+2)%2==0) colorf=WHITEF;           
   int jj=j, ii=i;
   if (rotate) { jj=7-j; ii=7-i; }   
   color=BLACK; color_cont=getColor(128,128,100); 
   if (pole[c]>0) { color=WHITE; color_cont=BLACK; }
   if (screen_height==320) {
    tft.fillRect(ii*39+10,jj*39,39,39,colorf);    
    tft.drawRect(ii*39+10,jj*39,39,39,GRAY);  
    if (pole[c]!=0) {
     drawBitmap(ii*39+14, jj*39+5,&fig32[abs(pole[c])-1][0], 32, 32,color);          
     drawBitmap(ii*39+14, jj*39+5,&fig32_cont[abs(pole[c])-1][0], 32, 32,color_cont);                 
    }
   } else { //height 240
    tft.fillRect(ii*28+12,jj*28,29,29,colorf);    
    tft.drawRect(ii*28+12,jj*28,29,29,GRAY);  
    if (pole[c]!=0) {
     drawBitmap(ii*28+14, jj*28+3,&fig24[abs(pole[c])-1][0], 24, 24,color);          
     drawBitmap(ii*28+14, jj*28+3,&fig24_cont[abs(pole[c])-1][0], 24, 24,color_cont);                 
    } 
   }
}
//****************************
void show_color() { 
int posx, posyw, posyb, rad;  
if (screen_height==320) {  
  posx=334; posyw=290; posyb=24; rad=5;   
 } else { //240
  posx=244; posyw=214; posyb=20; rad=4;
 }
 if (rotate) { int r=posyb; posyb=posyw; posyw=r; }
 tft.fillCircle(posx,posyb,rad,BLACK); tft.fillCircle(posx,posyw,rad,BLACK);
 if (pos[0].w) tft.fillCircle(posx,posyw,rad,GRAY); else  tft.drawCircle(posx,posyb,rad,GRAY); 
 uint16_t col=BLACK;
 int r2=rad*2;
 if (autow) col=DARK;
 tft.drawRect(posx-rad,posyw+r2,r2,r2,col); 
 col=BLACK;
 if (autob) col=DARK;
 tft.drawRect(posx-rad,posyb+r2,r2,r2,col); 
} 
//****************************
void show_board() { 
  for (int i=0;i<64;i++) { 
    if (poledisp[i]!=pole[i]) show_fig(i);      
    poledisp[i]=pole[i];
  }
  show_color();   
}
//****************************
void border() {
  tft.setTextColor(GRAY,BLACK);
  tft.setTextSize(1);  
  if (screen_height==320) {
   for (int j=1;j<9;j++) {
    tft.setCursor(1,j*39-22);  
    if (rotate) tft.print(j); else tft.print(9-j);
   }
   for (byte i=1;i<9;i++) { 
    tft.setCursor(i*39-11,312);    
    if (rotate) tft.print(char(96+9-i)); else tft.print(char(96+i));  
   }               
  } else { //240      
   for (int j=1;j<9;j++) {
    tft.setCursor(2,j*28-15);  
    if (rotate) tft.print(j); else tft.print(9-j);
   }
   for (byte i=1;i<9;i++) { 
    tft.setCursor(i*28-1,228);    
    if (rotate) tft.print(char(96+9-i)); else tft.print(char(96+i));  
   }                 
  }
}
//****************************
void cleardisplayboard() {
  for (int i=0;i<64;i++) poledisp[i]=-100; //          
}
//****************************
void initboard() {        
  cleardisplayboard();
  tft.fillScreen(BLACK);        
  border();    
  tft.setTextSize(1);  
  if (screen_height==320) {  
   tft.setCursor(337,1);  tft.setTextColor(WHITE);    
   // tft.print(F("Arduino Mega Chess II"));     
   tft.print(F("Damian's Chess Computer"));     
  } else { //240   
   tft.setCursor(242,1); tft.setTextColor(WHITE);      
   tft.print(F("Arduino Mega"));  
   tft.setCursor(252,10);
   tft.print(F("Chess II"));  
  }
}
//****************************
void show_steps() {
  if (screen_height==320) {
   tft.fillRect(330,56,135,150,GRAY2);               
  }
   else {
   tft.fillRect(240,44,74,114,GRAY2);               
  } 
  tft.setTextColor(GRAY);    
  tft.setTextSize(2);    
  int st=0; 
  if (ply>8) st=ply-8;
  if (st<0) st=0;    
  for (int i=st;i<ply;i++) {
    if (i%2==0) {
     tft.setTextSize(1);   
     if (screen_height==320)   
      tft.setCursor(332,(i-st)*18+64);    
     else 
      tft.setCursor(244,(i-st)*14+48);    
     tft.print(String(i/2+1)+".");
    }
    if (screen_height==320) {  
     tft.setTextSize(2);    
     tft.setCursor(360,(i-st)*18+60);    
    } else {
     tft.setTextSize(1);    
     tft.setCursor(268,(i-st)*14+48);    
    }       
    tft.print(str_step(steps[i])); 
  }
  
  
    
}
//****************************
void definecolors() {
 BLACK  =0x0000;
 BLUE   =0x07FF;  //0x001F;
 RED    =0xF800;
 GREEN  =0x07E0;
 CYAN   =0x07FF;
 MAGENTA=0xF81F;
 YELLOW =0xFFE0;
 WHITE  =0xFFFF;
 GRAY   =0x7BEF;
 DARK   =getColor(32,32,32); 
 GRAY2   =getColor(16,16,16); 
 BLACKF  =getColor(94,58,0); 
 WHITEF  =getColor(180,114,0); 
}
//****************************
void beep(int leng) {
  analogWrite(PinBuzz, 20);
  delay(2); 
  if (!sound) analogWrite(PinBuzz, 0);  
  delay(leng); 
  analogWrite(PinBuzz, 0);   
}  
//****************************
void guistart() {
  tft.reset();  
  tft.begin(tft.readID()); 
  tft.setRotation(1);     
  definecolors();
  initboard();
  BAction.Show("START");
  BMenu.Show("MENU");    
  show_board();
}  
//****************************  
String get_time(int tim) {  
  char sz[10];        
  //sprintf(sz, "%02d:%02d:%02d", tim/3600,(tim%3600)/60,tim%60);      
  sprintf(sz, "%d:%02d",tim/60,tim%60);      
  String s=sz; s.trim();
  return String(sz);
}
//****************************
void clearstatus() {
  if (screen_height==320) {
    tft.fillRect(330,210,135,60,GRAY2);             
  } else {
    tft.fillRect(242,169,70,36,GRAY2);             
  }
  for (int j=0;j<11;j++) { statusbuf1[j]=' '; statusbuf2[j]=' '; statusbuf3[j]=' '; }  
  guitime=millis();
  statustime=guitime;
  status_c1=-1;
  status_c2=-1;
}
//****************************
void print_changed(String s, char* b, uint16_t c) {
  for (int i=0;i<11;i++) {
    if (b[i]!=s[i]) {     
     tft.setTextColor(c,GRAY2);
     tft.print(s[i]); 
    } else {     
     tft.setTextColor(GRAY2,GRAY2);
     tft.print(" "); 
    }
    b[i]=s[i];
  }  
}
//****************************
void status_step(char c,byte show,uint16_t col=0) {
uint16_t color,color2;  
  if (c<0||c>63) return;
  color=BLACKF;   
  int i=column[c]-1; 
  int j=8-row[c];  
  if ((i+j+2)%2==0) color=WHITEF;           
  color2=GRAY;   
  if (show) { color=col; color2=color; }
  int jj=j, ii=i;
  if (rotate) { jj=7-j; ii=7-i; }     
  if (screen_height==320) {
   tft.drawRect(ii*39+10,jj*39,39,39,color2);        
   tft.drawRect(ii*39+11,jj*39+1,37,37,color);        
  } else { //height 240
   tft.drawRect(ii*28+12,jj*28,29,29,color2);    
   tft.drawRect(ii*28+13,jj*28+1,27,27,color);    
  }       
}
//****************************
void showstatus(String s1, String s2, String s3, uint16_t c1=GRAY, uint16_t c2=GRAY, uint16_t c3=GRAY) {  
  tft.setTextWrap(1);
  tft.setTextColor(GRAY);    
  if (screen_height==320) {
   tft.setTextSize(2);      
   tft.setCursor(334,213); print_changed(s1,statusbuf1,c1);
   tft.setCursor(334,233); print_changed(s2,statusbuf2,c2);
   tft.setCursor(334,253); print_changed(s3,statusbuf3,c3);
  } else {
   tft.setTextSize(1);      
   tft.setCursor(244,172); print_changed(s1,statusbuf1,c1);
   tft.setCursor(244,184); print_changed(s2,statusbuf2,c2);
   tft.setCursor(244,196); print_changed(s3,statusbuf3,c3);
  }  
  if (status_c1!=pos[0].cut.c1||status_c2!=pos[0].cut.c2) {
    if (status_c1!=-1) { status_step(status_c1,0); status_step(status_c2,0); }
    status_c1=pos[0].cut.c1;
    status_c2=pos[0].cut.c2;
    status_step(status_c1,1,getColor(220,0,0));
    status_step(status_c2,1,getColor(0,180,0));
   }
}
//****************************
boolean gettouch() {
  //digitalWrite(13, HIGH);
  tp = ts.getPoint();
  //digitalWrite(13, LOW);   
  // if sharing pins, you'll need to fix the directions of the touchscreen pins  
  pinMode(XM, OUTPUT);  
  pinMode(YP, OUTPUT);      
  int x=map(tp.y,mapx1,mapx2,0,screen_width-1);
  int y=map(tp.x,mapy1,mapy2,0,screen_height-1);
  touched=0;
  if ((abs(x-touchx)>5||abs(y-touchy)>5)&&tp.z>MINPRESSURE&&tp.z<MAXPRESSURE) {    
    touched=1;  
    touchx=x;
    touchy=y; 
    //tft.drawPixel(x,y,GREEN);
    //Serial.println(tp.y);
    //Serial.println(tp.x);
  }
  return touched;    
}
//****************************
void erasestatus() {
  if (status_c1>-1) status_step(status_c1,0); 
  if (status_c2>-1) status_step(status_c2,0);
  status_c1=-1;  
  status_c2=-1;         
}
//**********************************   
signed char field_pressed() {
 signed char c;
 if (screen_height==320) {
  c=(touchx-10)/39+8*(touchy/39);    
 } else {
  c=(touchx-10)/28+8*(touchy/28);   
 }
 if (c<0||c>63) c=-1; else if (rotate) c=63-c;
 if (c!=-1&&status_c1==-1) 
  if ((pos[0].w&&pole[c]<=0)||(!pos[0].w&&pole[c]>=0)) c=-1;
 if (c!=-1&&status_c1!=-1&&c==status_c1) c=-1;  
 //Serial.println(c);
 return c;
}
//****************************
void clearmenu() {
 if (screen_height==320) {
   tft.fillRect(330,56,135,220,BLACK);               
   tft.fillRect(350,276,115,43,BLACK);               
  } else {
   tft.fillRect(240,40,80,166,BLACK);               
   tft.fillRect(250,206,69,33,BLACK);               
  }   
}
//****************************

logic.h:
Code:
const signed char fp=1; //pawn
const signed char fn=2; //knight
const signed char fb=3; //bishop
const signed char fr=4; //rook
const signed char fq=5; //queen
const signed char fk=6; //king
const int fig_weight[]={0,100,320,330,500,900,0};
const char fig_symb[]="  NBRQK";
const char fig_symb1[]=" pNBRQK";

char pole[64]; //

const byte column[64] ={
  1, 2, 3, 4, 5, 6, 7, 8,
  1, 2, 3, 4, 5, 6, 7, 8,
  1, 2, 3, 4, 5, 6, 7, 8,
  1, 2, 3, 4, 5, 6, 7, 8,
  1, 2, 3, 4, 5, 6, 7, 8,
  1, 2, 3, 4, 5, 6, 7, 8,
  1, 2, 3, 4, 5, 6, 7, 8,
  1, 2, 3, 4, 5, 6, 7, 8  
};
const byte row[64] = { 
  8, 8, 8, 8, 8, 8, 8, 8,
  7, 7, 7, 7, 7, 7, 7, 7,
  6, 6, 6, 6, 6, 6, 6, 6,
  5, 5, 5, 5, 5, 5, 5, 5,
  4, 4, 4, 4, 4, 4, 4, 4,
  3, 3, 3, 3, 3, 3, 3, 3,
  2, 2, 2, 2, 2, 2, 2, 2,
  1, 1, 1, 1, 1, 1, 1, 1  
};
const byte diag1[64] ={
  1, 2, 3, 4, 5, 6, 7, 8,
  2, 3, 4, 5, 6, 7, 8, 9,
  3, 4, 5, 6, 7, 8, 9,10,
  4, 5, 6, 7, 8, 9,10,11,
  5, 6, 7, 8, 9,10,11,12,
  6, 7, 8, 9,10,11,12,13,
  7, 8, 9,10,11,12,13,14,
  8, 9,10,11,12,13,14,15  
};
const byte diag2[64] ={
  8, 7, 6, 5, 4, 3, 2, 1,
  9, 8, 7, 6, 5, 4, 3, 2,
 10, 9, 8, 7, 6, 5, 4, 3,
 11,10, 9, 8, 7, 6, 5, 4,
 12,11,10, 9, 8, 7, 6, 5,
 13,12,11,10, 9, 8, 7, 6,
 14,13,12,11,10, 9, 8, 7,
 15,14,13,12,11,10, 9, 8  
};

const char polestart[64] PROGMEM={
 -fr,-fn,-fb,-fq,-fk,-fb,-fn,-fr,
 -fp,-fp,-fp,-fp,-fp,-fp,-fp,-fp,
   0,  0,  0,  0,  0,  0,  0,  0,
   0,  0,  0,  0,  0,  0,  0,  0,
   0,  0,  0,  0,  0,  0,  0,  0,
   0,  0,  0,  0,  0,  0,  0,  0,
  fp, fp, fp, fp, fp, fp, fp, fp,
  fr, fn, fb, fq, fk, fb, fn, fr
};  

const short stat_weightw[7][64] PROGMEM={
  { 0,  0,  0,  0,  0,  0,  0,  0, //pawn
  100,100,100,100,100,100,100,100,  // 50, 50, 50, 50, 50, 50, 50, 50,
   20, 30, 40, 50, 50, 40, 30, 20,  // 10, 10, 20, 30, 30, 20, 10, 10,
    5,  5, 10, 25, 25, 10,  5,  5,
    0,  0,  0, 20, 20,  0,  0,  0,
    5, -5,-10,  0,  0,-10, -5,  5,
    5, 10, 10,-20,-20, 10, 10,  5,  //  5, 10, 10,-20,-20, 10, 10,  5,
    0,  0,  0,  0,  0,  0,  0,  0},
  
 {-50,-40,-30,-30,-30,-30,-40,-50, //knife
  -40,-20,  0,  0,  0,  0,-20,-40,
  -30,  0, 10, 15, 15, 10,  0,-30,
  -30,  5, 15, 20, 20, 15,  5,-30,
  -30,  0, 15, 20, 20, 15,  0,-30,
  -30,  5, 10, 15, 15, 10,  5,-30,
  -40,-20,  0,  5,  5,  0,-20,-40,
  -50,-40,-30,-30,-30,-30,-40,-50}, 
  
 {-20,-10,-10,-10,-10,-10,-10,-20, //bishop
  -10,  0,  0,  0,  0,  0,  0,-10,
  -10,  0,  5, 10, 10,  5,  0,-10,
  -10,  5,  5, 10, 10,  5,  5,-10,
  -10,  0, 10, 10, 10, 10,  0,-10,
  -10, 10, 10, 10, 10, 10, 10,-10,
  -10,  5,  0,  0,  0,  0,  5,-10,
  -20,-10,-10,-10,-10,-10,-10,-20},  

 {  0,  0,  0,  0,  0,  0,  0,  0, //rook
    5, 10, 10, 10, 10, 10, 10,  5,
   -5,  0,  0,  0,  0,  0,  0, -5,
   -5,  0,  0,  0,  0,  0,  0, -5,
   -5,  0,  0,  0,  0,  0,  0, -5,
   -5,  0,  0,  0,  0,  0,  0, -5,
   -5,  0,  0,  0,  0,  0,  0, -5,
    0,  0,  0,  5,  5,  0,  0,  0},
  
 {-20,-10,-10, -5, -5,-10,-10,-20, //queen
  -10,  0,  0,  0,  0,  0,  0,-10,
  -10,  0,  5,  5,  5,  5,  0,-10,
   -5,  0,  5,  5,  5,  5,  0, -5,
    0,  0,  5,  5,  5,  5,  0, -5,
  -10,  5,  5,  5,  5,  5,  0,-10,
  -10,  0,  5,  0,  0,  0,  0,-10,
  -20,-10,-10, -5, -5,-10,-10,-20},  

 {-30,-40,-40,-50,-50,-40,-40,-30, //kingw
  -30,-40,-40,-50,-50,-40,-40,-30,
  -30,-40,-40,-50,-50,-40,-40,-30,
  -30,-40,-40,-50,-50,-40,-40,-30,
  -20,-30,-30,-40,-40,-30,-30,-20,
  -10,-20,-20,-20,-20,-20,-20,-10,
   10, 10,-10,-10,-10,-10, 10, 10,  
   10, 40, 30,  0,  0,  0, 50, 10}, 

 {-50,-40,-30,-20,-20,-30,-40,-50, //king endspiel
  -30,-20,-10,  0,  0,-10,-20,-30,
  -30,-10, 20, 30, 30, 20,-10,-30,
  -30,-10, 30, 40, 40, 30,-10,-30,
  -30,-10, 30, 40, 40, 30,-10,-30,
  -30,-10, 20, 30, 30, 20,-10,-30,
  -30,-30,  0,  0,  0,  0,-30,-30,
  -50,-30,-30,-30,-30,-30,-30,-50}  
};

const short stat_weightb[7][64] PROGMEM={
  { 0,  0,  0,  0,  0,  0,  0,  0, //pawn
    5, 10, 10,-20,-20, 10, 10,  5,
    5, -5,-10,  0,  0,-10, -5,  5,
    0,  0,  0, 20, 20,  0,  0,  0,
    5,  5, 10, 25, 25, 10,  5,  5,  
   20, 30, 40, 50, 50, 40, 30, 20,  
  100,100,100,100,100,100,100,100,  
    0,  0,  0,  0,  0,  0,  0,  0},
  
 {-50,-40,-30,-30,-30,-30,-40,-50, //knife
  -40,-20,  0,  0,  0,  0,-20,-40,
  -30,  5, 10, 15, 15, 10,  5,-30,
  -30,  0, 15, 20, 20, 15,  0,-30,
  -30,  5, 15, 20, 20, 15,  5,-30, 
  -30,  0, 10, 15, 15, 10,  0,-30,
  -40,-20,  0,  5,  5,  0,-20,-40,
  -50,-40,-30,-30,-30,-30,-40,-50}, 
  
 {-20,-10,-10,-10,-10,-10,-10,-20, //bishop
  -10,  5,  0,  0,  0,  0,  5,-10,
  -10, 10, 10, 10, 10, 10, 10,-10,
  -10,  0, 10, 10, 10, 10,  0,-10,
  -10,  5,  5, 10, 10,  5,  5,-10,
  -10,  0,  5, 10, 10,  5,  0,-10, 
  -10,  0,  0,  0,  0,  0,  0,-10,
  -20,-10,-10,-10,-10,-10,-10,-20},  

 {  0,  0,  0,  5,  5,  0,  0,  0, //rook     
   -5,  0,  0,  0,  0,  0,  0, -5,
   -5,  0,  0,  0,  0,  0,  0, -5,
   -5,  0,  0,  0,  0,  0,  0, -5,
   -5,  0,  0,  0,  0,  0,  0, -5,
   -5,  0,  0,  0,  0,  0,  0, -5,
    5, 10, 10, 10, 10, 10, 10,  5,   
    0,  0,  0,  0,  0,  0,  0,  0},
  
 {-20,-10,-10, -5, -5,-10,-10,-20, //queen 
  -10,  0,  5,  0,  0,  0,  0,-10,
  -10,  5,  5,  5,  5,  5,  0,-10,
    0,  0,  5,  5,  5,  5,  0, -5,
   -5,  0,  5,  5,  5,  5,  0, -5,
  -10,  0,  5,  5,  5,  5,  0,-10,
  -10,  0,  0,  0,  0,  0,  0,-10,
  -20,-10,-10, -5, -5,-10,-10,-20},  

 { 10, 40, 30,  0,  0,  0, 50, 10, //kingb
  10, 10,-10,-10,-10,-10, 10, 10, 
  -10,-20,-20,-20,-20,-20,-20,-10,
  -20,-30,-30,-40,-40,-30,-30,-20,  
  -30,-40,-40,-50,-50,-40,-40,-30, 
  -30,-40,-40,-50,-50,-40,-40,-30,
  -30,-40,-40,-50,-50,-40,-40,-30,
  -30,-40,-40,-50,-50,-40,-40,-30},

 {-50,-30,-30,-30,-30,-30,-30,-50,  //kingb endspiel
  -30,-30,  0,  0,  0,  0,-30,-30,
  -30,-10, 20, 30, 30, 20,-10,-30,
  -30,-10, 30, 40, 40, 30,-10,-30,
  -30,-10, 30, 40, 40, 30,-10,-30,
  -30,-10, 20, 30, 30, 20,-10,-30,
  -30,-20,-10,  0,  0,-10,-20,-30,
  -50,-40,-30,-20,-20,-30,-40,-50} 
};

//88 - end of raw
//99 - end of all
const byte diag_step[64][17] PROGMEM={
 {9,18,27,36,45,54,63,99}, //0
 {10,19,28,37,46,55,88,8,99}, //1
 {11,20,29,38,47,88,9,16,99}, //2
 {12,21,30,39,88,10,17,24,99}, //3 
 {13,22,31,88,11,18,25,32,99}, //4 
 {14,23,88,12,19,26,33,40,99}, //5 
 {15,88,13,20,27,34,41,48,99}, //6 
 {14,21,28,35,42,49,56,99}, //7 
 {17,26,35,44,53,62,88,1,99}, //8 
 {18,27,36,45,54,63,88,16,88,0,88,2,99}, //9 
 {19,28,37,46,55,88,17,24,88,1,88,3,99}, //10 
 {20,29,38,47,88,18,25,32,88,2,88,4,99}, //11 
 {21,30,39,88,19,26,33,40,88,3,88,5,99}, //12 
 {22,31,88,20,27,34,41,48,88,4,88,6,99}, //13 
 {23,88,21,28,35,42,49,56,88,5,88,7,99}, //14 
 {22,29,36,43,50,57,88,6,99}, //15 
 {25,34,43,52,61,88,9,2,99}, //16 
 {26,35,44,53,62,88,24,88,8,88,10,3,99}, //17 
 {27,36,45,54,63,88,25,32,88,9,0,88,11,4,99}, //18 
 {28,37,46,55,88,26,33,40,88,10,1,88,12,5,99}, //19 
 {29,38,47,88,27,34,41,48,88,11,2,88,13,6,99}, //20 
 {30,39,88,28,35,42,49,56,88,12,3,88,14,7,99}, //21 
 {31,88,29,36,43,50,57,88,13,4,88,15,99}, //22 
 {30,37,44,51,58,88,14,5,99}, //23 
 {33,42,51,60,88,17,10,3,99}, //24 
 {34,43,52,61,88,32,88,16,88,18,11,4,99}, //25 
 {35,44,53,62,88,33,40,88,17,8,88,19,12,5,99}, //26 
 {36,45,54,63,88,34,41,48,88,18,9,0,88,20,13,6,99}, //27 
 {37,46,55,88,35,42,49,56,88,19,10,1,88,21,14,7,99}, //28 
 {38,47,88,36,43,50,57,88,20,11,2,88,22,15,99}, //29 
 {39,88,37,44,51,58,88,21,12,3,88,23,99}, //30 
 {38,45,52,59,88,22,13,4,99}, //31 
 {41,50,59,88,25,18,11,4,99}, //32 
 {42,51,60,88,40,88,24,88,26,19,12,5,99}, //33 
 {43,52,61,88,41,48,88,25,16,88,27,20,13,6,99}, //34 
 {44,53,62,88,42,49,56,88,26,17,8,88,28,21,14,7,99}, //35 
 {45,54,63,88,43,50,57,88,27,18,9,0,88,29,22,15,99}, //36 
 {46,55,88,44,51,58,88,28,19,10,1,88,30,23,99}, //37 
 {47,88,45,52,59,88,29,20,11,2,88,31,99}, //38 
 {46,53,60,88,30,21,12,3,99}, //39 
 {49,58,88,33,26,19,12,5,99}, //40
 {50,59,88,48,88,32,88,34,27,20,13,6,99}, //41 
 {51,60,88,49,56,88,33,24,88,35,28,21,14,7,99}, //42 
 {52,61,88,50,57,88,34,25,16,88,36,29,22,15,99}, //43 
 {53,62,88,51,58,88,35,26,17,8,88,37,30,23,99}, //44 
 {54,63,88,52,59,88,36,27,18,9,0,88,38,31,99}, //45 
 {55,88,53,60,88,37,28,19,10,1,88,39,99}, //46 
 {54,61,88,38,29,20,11,2,99}, //47 
 {57,88,41,34,27,20,13,6,99}, //48 
 {58,88,56,88,40,88,42,35,28,21,14,7,99}, //49 
 {59,88,57,88,41,32,88,43,36,29,22,15,99}, //50
 {60,88,58,88,42,33,24,88,44,37,30,23,99}, //51 
 {61,88,59,88,43,34,25,16,88,45,38,31,99}, //52 
 {62,88,60,88,44,35,26,17,8,88,46,39,99}, //53 
 {63,88,61,88,45,36,27,18,9,0,88,47,99}, //54 
 {62,88,46,37,28,19,10,1,99}, //55 
 {49,42,35,28,21,14,7,99}, //56 
 {48,88,50,43,36,29,22,15,99}, //57 
 {49,40,88,51,44,37,30,23,99}, //58 
 {50,41,32,88,52,45,38,31,99}, //59 
 {51,42,33,24,88,53,46,39,99}, //60   
 {52,43,34,25,16,88,54,47,99}, //61 
 {53,44,35,26,17,8,88,55,99}, //62 
 {54,45,36,27,18,9,0,99} //63  ++++++
};

const byte stra_step[64][18] PROGMEM={
 {1,2,3,4,5,6,7,88,8,16,24,32,40,48,56,99}, //0
 {2,3,4,5,6,7,88,9,17,25,33,41,49,57,88,0,99}, //1
 {3,4,5,6,7,88,10,18,26,34,42,50,58,88,1,0,99}, //2
 {4,5,6,7,88,11,19,27,35,43,51,59,88,2,1,0,99}, //3
 {5,6,7,88,12,20,28,36,44,52,60,88,3,2,1,0,99}, //4
 {6,7,88,13,21,29,37,45,53,61,88,4,3,2,1,0,99}, //5
 {7,88,14,22,30,38,46,54,62,88,5,4,3,2,1,0,99}, //6
 {15,23,31,39,47,55,63,88,6,5,4,3,2,1,0,99}, //7
 {9,10,11,12,13,14,15,88,16,24,32,40,48,56,88,0,99}, //8
 {10,11,12,13,14,15,88,17,25,33,41,49,57,88,8,88,1,99}, //9
 {11,12,13,14,15,88,18,26,34,42,50,58,88,9,8,88,2,99}, //10
 {12,13,14,15,88,19,27,35,43,51,59,88,10,9,8,88,3,99}, //11
 {13,14,15,88,20,28,36,44,52,60,88,11,10,9,8,88,4,99}, //12
 {14,15,88,21,29,37,45,53,61,88,12,11,10,9,8,88,5,99}, //13
 {15,88,22,30,38,46,54,62,88,13,12,11,10,9,8,88,6,99}, //14
 {23,31,39,47,55,63,88,14,13,12,11,10,9,8,88,7,99}, //15
 {17,18,19,20,21,22,23,88,24,32,40,48,56,88,8,0,99}, //16
 {18,19,20,21,22,23,88,25,33,41,49,57,88,16,88,9,1,99}, //17
 {19,20,21,22,23,88,26,34,42,50,58,88,17,16,88,10,2,99}, //18
 {20,21,22,23,88,27,35,43,51,59,88,18,17,16,88,11,3,99}, //19
 {21,22,23,88,28,36,44,52,60,88,19,18,17,16,88,12,4,99}, //20
 {22,23,88,29,37,45,53,61,88,20,19,18,17,16,88,13,5,99}, //21
 {23,88,30,38,46,54,62,88,21,20,19,18,17,16,88,14,6,99}, //22
 {31,39,47,55,63,88,22,21,20,19,18,17,16,88,15,7,99}, //23
 {25,26,27,28,29,30,31,88,32,40,48,56,88,16,8,0,99}, //24
 {26,27,28,29,30,31,88,33,41,49,57,88,24,88,17,9,1,99}, //25
 {27,28,29,30,31,88,34,42,50,58,88,25,24,88,18,10,2,99}, //26
 {28,29,30,31,88,35,43,51,59,88,26,25,24,88,19,11,3,99}, //27
 {29,30,31,88,36,44,52,60,88,27,26,25,24,88,20,12,4,99}, //28
 {30,31,88,37,45,53,61,88,28,27,26,25,24,88,21,13,5,99}, //29
 {31,88,38,46,54,62,88,29,28,27,26,25,24,88,22,14,6,99}, //30
 {39,47,55,63,88,30,29,28,27,26,25,24,88,23,15,7,99}, //31
 {33,34,35,36,37,38,39,88,40,48,56,88,24,16,8,0,99}, //32
 {34,35,36,37,38,39,88,41,49,57,88,32,88,25,17,9,1,99}, //33
 {35,36,37,38,39,88,42,50,58,88,33,32,88,26,18,10,2,99}, //34
 {36,37,38,39,88,43,51,59,88,34,33,32,88,27,19,11,3,99}, //35
 {37,38,39,88,44,52,60,88,35,34,33,32,88,28,20,12,4,99}, //36
 {38,39,88,45,53,61,88,36,35,34,33,32,88,29,21,13,5,99}, //37
 {39,88,46,54,62,88,37,36,35,34,33,32,88,30,22,14,6,99}, //38
 {47,55,63,88,38,37,36,35,34,33,32,88,31,23,15,7,99}, //39
 {41,42,43,44,45,46,47,88,48,56,88,32,24,16,8,0,99}, //40
 {42,43,44,45,46,47,88,49,57,88,40,88,33,25,17,9,1,99}, //41
 {43,44,45,46,47,88,50,58,88,41,40,88,34,26,18,10,2,99}, //42
 {44,45,46,47,88,51,59,88,42,41,40,88,35,27,19,11,3,99}, //43
 {45,46,47,88,52,60,88,43,42,41,40,88,36,28,20,12,4,99}, //44
 {46,47,88,53,61,88,44,43,42,41,40,88,37,29,21,13,5,99}, //45
 {47,88,54,62,88,45,44,43,42,41,40,88,38,30,22,14,6,99}, //46
 {55,63,88,46,45,44,43,42,41,40,88,39,31,23,15,7,99}, //47
 {49,50,51,52,53,54,55,88,56,88,40,32,24,16,8,0,99}, //48
 {50,51,52,53,54,55,88,57,88,48,88,41,33,25,17,9,1,99}, //49
 {51,52,53,54,55,88,58,88,49,48,88,42,34,26,18,10,2,99}, //50
 {52,53,54,55,88,59,88,50,49,48,88,43,35,27,19,11,3,99}, //51
 {53,54,55,88,60,88,51,50,49,48,88,44,36,28,20,12,4,99}, //52
 {54,55,88,61,88,52,51,50,49,48,88,45,37,29,21,13,5,99}, //53
 {55,88,62,88,53,52,51,50,49,48,88,46,38,30,22,14,6,99}, //54
 {63,88,54,53,52,51,50,49,48,88,47,39,31,23,15,7,99}, //55
 {57,58,59,60,61,62,63,88,48,40,32,24,16,8,0,99}, //56
 {58,59,60,61,62,63,88,56,88,49,41,33,25,17,9,1,99}, //57
 {59,60,61,62,63,88,57,56,88,50,42,34,26,18,10,2,99}, //58
 {60,61,62,63,88,58,57,56,88,51,43,35,27,19,11,3,99}, //59
 {61,62,63,88,59,58,57,56,88,52,44,36,28,20,12,4,99}, //60
 {62,63,88,60,59,58,57,56,88,53,45,37,29,21,13,5,99}, //61
 {63,88,61,60,59,58,57,56,88,54,46,38,30,22,14,6,99}, //62
 {62,61,60,59,58,57,56,88,55,47,39,31,23,15,7,99} //63
};

const byte knight_step[64][9] PROGMEM={
 {10,17,99}, //0
 {11,18,16,99}, //1
 {12,19,17,8,99}, //2
 {13,20,18,9,99}, //3
 {14,21,19,10,99}, //4
 {15,22,20,11,99}, //5
 {23,21,12,99}, //6
 {22,13,99}, //7
 {2,18,25,99}, //8
 {3,19,26,24,99}, //9
 {4,20,27,25,16,0,99}, //10
 {5,21,28,26,17,1,99}, //11
 {6,22,29,27,18,2,99}, //12
 {7,23,30,28,19,3,99}, //13
 {31,29,20,4,99}, //14
 {30,21,5,99}, //15
 {1,10,26,33,99}, //16
 {2,11,27,34,32,0,99}, //17
 {3,12,28,35,33,24,8,1,99}, //18
 {4,13,29,36,34,25,9,2,99}, //19
 {5,14,30,37,35,26,10,3,99}, //20
 {6,15,31,38,36,27,11,4,99}, //21
 {7,39,37,28,12,5,99}, //22
 {38,29,13,6,99}, //23
 {9,18,34,41,99}, //24
 {10,19,35,42,40,8,99}, //25
 {11,20,36,43,41,32,16,9,99}, //26
 {12,21,37,44,42,33,17,10,99}, //27
 {13,22,38,45,43,34,18,11,99}, //28
 {14,23,39,46,44,35,19,12,99}, //29
 {15,47,45,36,20,13,99}, //30
 {46,37,21,14,99}, //31
 {17,26,42,49,99}, //32
 {18,27,43,50,48,16,99}, //33
 {19,28,44,51,49,40,24,17,99}, //34
 {20,29,45,52,50,41,25,18,99}, //35
 {21,30,46,53,51,42,26,19,99}, //36
 {22,31,47,54,52,43,27,20,99}, //37
 {23,55,53,44,28,21,99}, //38
 {54,45,29,22,99}, //39
 {25,34,50,57,99}, //40
 {26,35,51,58,56,24,99}, //41
 {27,36,52,59,57,48,32,25,99}, //42
 {28,37,53,60,58,49,33,26,99}, //43
 {29,38,54,61,59,50,34,27,99}, //44
 {30,39,55,62,60,51,35,28,99}, //45
 {31,63,61,52,36,29,99}, //46
 {62,53,37,30,99}, //47
 {33,42,58,99}, //48
 {34,43,59,32,99}, //49
 {35,44,60,56,40,33,99}, //50
 {36,45,61,57,41,34,99}, //51
 {37,46,62,58,42,35,99}, //52
 {38,47,63,59,43,36,99}, //53
 {39,60,44,37,99}, //54
 {61,45,38,99}, //55
 {41,50,99}, //56
 {40,42,51,99}, //57
 {43,52,48,41,99}, //58
 {44,53,49,42,99}, //59
 {45,54,50,43,99}, //60
 {46,55,51,44,99}, //61
 {47,52,45,99}, //62
 {53,46,99} //63  +++++
};

const byte king_step[64][9] PROGMEM={
 {1,9,8,99}, //0
 {2,10,9,8,0,99}, //1
 {3,11,10,9,1,99}, //2
 {4,12,11,10,2,99}, //3
 {5,13,12,11,3,99}, //4
 {6,14,13,12,4,99}, //5
 {7,15,14,13,5,99}, //6
 {15,14,6,99}, //7
 {1,9,17,16,0,99}, //8
 {2,10,18,17,16,8,0,1,99}, //9
 {3,11,19,18,17,9,1,2,99}, //10
 {4,12,20,19,18,10,2,3,99}, //11
 {5,13,21,20,19,11,3,4,99}, //12
 {6,14,22,21,20,12,4,5,99}, //13
 {7,15,23,22,21,13,5,6,99}, //14
 {23,22,14,6,7,99}, //15
 {9,17,25,24,8,99}, //16
 {10,18,26,25,24,16,8,9,99}, //17
 {11,19,27,26,25,17,9,10,99}, //18
 {12,20,28,27,26,18,10,11,99}, //19
 {13,21,29,28,27,19,11,12,99}, //20
 {14,22,30,29,28,20,12,13,99}, //21
 {15,23,31,30,29,21,13,14,99}, //22
 {31,30,22,14,15,99}, //23
 {17,25,33,32,16,99 }, //24
 {18,26,34,33,32,24,16,17,99}, //25
 {19,27,35,34,33,25,17,18,99}, //26
 {20,28,36,35,34,26,18,19,99}, //27
 {21,29,37,36,35,27,19,20,99}, //28
 {22,30,38,37,36,28,20,21,99}, //29
 {23,31,39,38,37,29,21,22,99}, //30
 {39,38,30,22,23,99}, //31
 {25,33,41,40,24,99}, //32
 {26,34,42,41,40,32,24,25,99}, //33
 {27,35,43,42,41,33,25,26,99}, //34
 {28,36,44,43,42,34,26,27,99}, //35
 {29,37,45,44,43,35,27,28,99}, //36
 {30,38,46,45,44,36,28,29,99}, //37
 {31,39,47,46,45,37,29,30,99}, //38
 {47,46,38,30,31,99}, //39
 {33,41,49,48,32,99}, //40
 {34,42,50,49,48,40,32,33,99}, //41
 {35,43,51,50,49,41,33,34,99}, //42
 {36,44,52,51,50,42,34,35,99}, //43
 {37,45,53,52,51,43,35,36,99}, //44
 {38,46,54,53,52,44,36,37,99}, //45
 {39,47,55,54,53,45,37,38,99}, //46
 {55,54,46,38,39,99}, //47
 {41,49,57,56,40,99}, //48
 {42,50,58,57,56,48,40,41,99}, //49
 {43,51,59,58,57,49,41,42,99}, //50
 {44,52,60,59,58,50,42,43,99}, //51
 {45,53,61,60,59,51,43,44,99}, //52
 {46,54,62,61,60,52,44,45,99}, //53
 {47,55,63,62,61,53,45,46,99}, //54
 {63,62,54,46,47,99}, //55
 {49,57,48,99}, //56
 {50,58,56,48,49,99}, //57
 {51,59,57,49,50,99}, //58
 {52,60,58,50,51,99}, //59
 {53,61,59,51,52,99}, //60
 {54,62,60,52,53,99}, //61
 {55,63,61,53,54,99}, //62
 {62,54,55,99} //63  +++++
};

wac.h:
Code:
const char wac1[] PROGMEM= "2rr3k/pp3pp1/1nnqbN1p/3pN3/2pP4/2P3Q1/PPB4P/R4RK1 w - - bm Qg6; id ""WAC.001""; d5+m2";
const char wac2[] PROGMEM="8/7p/5k2/5p2/p1p2P2/Pr1pPK2/1P1R3P/8 b - - bm Rxb2; id ""WAC.002""; d18+4";
const char wac3[] PROGMEM="5rk1/1ppb3p/p1pb4/6q1/3P1p1r/2P1R2P/PP1BQ1P1/5RKN w - - bm Rg3; id ""WAC.003""; d5+3";
const char wac4[] PROGMEM="r1bq2rk/pp3pbp/2p1p1pQ/7P/3P4/2PB1N2/PP3PPR/2KR4 w - - bm Qxh7+; id ""WAC.004""; d5+m2";
const char wac5[] PROGMEM="5k2/6pp/p1qN4/1p1p4/3P4/2PKP2Q/PP3r2/3R4 b - - bm Qc4+; id ""WAC.005""; d5+m2";
const char wac6[] PROGMEM="7k/p7/1R5K/6r1/6p1/6P1/8/8 w - - bm Rb7; id ""WAC.006""; d5+7";
const char wac7[] PROGMEM="rnbqkb1r/pppp1ppp/8/4P3/6n1/7P/PPPNPPP1/R1BQKBNR b KQkq - bm Ne3; id ""WAC.007""; d5+3";
const char wac8[] PROGMEM="r4q1k/p2bR1rp/2p2Q1N/5p2/5p2/2P5/PP3PPP/R5K1 w - - bm Rf7; id ""WAC.008""; d5+7 d11+m8";
const char wac9[] PROGMEM="3q1rk1/p4pp1/2pb3p/3p4/6Pr/1PNQ4/P1PB1PP1/4RRK1 b - - bm Bh2+; id ""WAC.009""; d5+m5";
const char wac10[] PROGMEM="2br2k1/2q3rn/p2NppQ1/2p1P3/Pp5R/4P3/1P3PPP/3R2K1 w - - bm Rxh7; id ""WAC.010""; d5+4";
const char wac11[] PROGMEM="r1b1kb1r/3q1ppp/pBp1pn2/8/Np3P2/5B2/PPP3PP/R2Q1RK1 w kq - bm Bxc6; id ""WAC.011""; d5+3";
const char wac12[] PROGMEM="4k1r1/2p3r1/1pR1p3/3pP2p/3P2qP/P4N2/1PQ4P/5R1K b - - bm Qxf3+; id ""WAC.012""; d5+m2";
const char wac13[] PROGMEM="5rk1/pp4p1/2n1p2p/2Npq3/2p5/6P1/P3P1BP/R4Q1K w - - bm Qxf8+; id ""WAC.013""; d5+1.5";
const char wac14[] PROGMEM="r2rb1k1/pp1q1p1p/2n1p1p1/2bp4/5P2/PP1BPR1Q/1BPN2PP/R5K1 w - - bm Qxh7+; id ""WAC.014""; d5+m4";
const char wac15[] PROGMEM="1R6/1brk2p1/4p2p/p1P1Pp2/P7/6P1/1P4P1/2R3K1 w - - bm Rxb7; id ""WAC.015""; d5+7";
const char wac16[] PROGMEM="r4rk1/ppp2ppp/2n5/2bqp3/8/P2PB3/1PP1NPPP/R2Q1RK1 w - - bm Nc3; id ""WAC.016""; d5+2";
const char wac17[] PROGMEM="1k5r/pppbn1pp/4q1r1/1P3p2/2NPp3/1QP5/P4PPP/R1B1R1K1 w - - bm Ne5; id ""WAC.017""; d5+1";
const char wac18[] PROGMEM="R7/P4k2/8/8/8/8/r7/6K1 w - - bm Rh8; id ""WAC.018""; d6+6";
const char wac19[] PROGMEM="r1b2rk1/ppbn1ppp/4p3/1QP4q/3P4/N4N2/5PPP/R1B2RK1 w - - bm c6; id ""WAC.019""; d6+0.7";    
const char wac20[] PROGMEM="r2qkb1r/1ppb1ppp/p7/4p3/P1Q1P3/2P5/5PPP/R1B2KNR b kq - bm Bb5; id ""WAC.020""; d6+7";
const char wac21[] PROGMEM="5rk1/1b3p1p/pp3p2/3n1N2/1P6/P1qB1PP1/3Q3P/4R1K1 w - - bm Qh6; id ""WAC.021""; d5+6";
const char wac22[] PROGMEM="r1bqk2r/ppp1nppp/4p3/n5N1/2BPp3/P1P5/2P2PPP/R1BQK2R w KQkq - bm Ba2 Nxf7; id ""WAC.022""; Nxf7 d5+0.5";
const char wac23[] PROGMEM="r3nrk1/2p2p1p/p1p1b1p1/2NpPq2/3R4/P1N1Q3/1PP2PPP/4R1K1 w - - bm g4; id ""WAC.023""; d5+4";
const char wac24[] PROGMEM="6k1/1b1nqpbp/pp4p1/5P2/1PN5/4Q3/P5PP/1B2B1K1 b - - bm Bd4; id ""WAC.024""; d5+7";
const char wac25[] PROGMEM="3R1rk1/8/5Qpp/2p5/2P1p1q1/P3P3/1P2PK2/8 b - - bm Qh4+; id ""WAC.025""; d5+12";
const char wac26[] PROGMEM="3r2k1/1p1b1pp1/pq5p/8/3NR3/2PQ3P/PP3PP1/6K1 b - - bm Bf5; id ""WAC.026""; d5+1.2";
const char wac27[] PROGMEM="7k/pp4np/2p3p1/3pN1q1/3P4/Q7/1r3rPP/2R2RK1 w - - bm Qf8+; id ""WAC.027""; d5+m2";
const char wac28[] PROGMEM="1r1r2k1/4pp1p/2p1b1p1/p3R3/RqBP4/4P3/1PQ2PPP/6K1 b - - bm Qe1+; id ""WAC.028""; d5+3";
const char wac29[] PROGMEM="r2q2k1/pp1rbppp/4pn2/2P5/1P3B2/6P1/P3QPBP/1R3RK1 w - - bm c6; id ""WAC.029""; d5+1";
const char wac30[] PROGMEM="1r3r2/4q1kp/b1pp2p1/5p2/pPn1N3/6P1/P3PPBP/2QRR1K1 w - - bm Nxd6; id ""WAC.030""; d7+0.7";
const 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";
const char wac32[] PROGMEM="6k1/p4p1p/1p3np1/2q5/4p3/4P1N1/PP3PPP/3Q2K1 w - - bm Qd8+; id ""WAC.032""; d5+1.7";
const char wac33[] PROGMEM="8/p1q2pkp/2Pr2p1/8/P3Q3/6P1/5P1P/2R3K1 w - - bm Qe5+ Qf4; id ""WAC.033""; d6+5";
const char wac34[] PROGMEM="7k/1b1r2p1/p6p/1p2qN2/3bP3/3Q4/P5PP/1B1R3K b - - bm Bg1; id ""WAC.034""; d5+2.7";
const char wac35[] PROGMEM="r3r2k/2R3pp/pp1q1p2/8/3P3R/7P/PP3PP1/3Q2K1 w - - bm Rxh7+; id ""WAC.035""; d5+m4";
const char wac36[] PROGMEM="3r4/2p1rk2/1pQq1pp1/7p/1P1P4/P4P2/6PP/R1R3K1 b - - bm Re1+; id ""WAC.036""; d5+4";
const char wac37[] PROGMEM="2r5/2rk2pp/1pn1pb2/pN1p4/P2P4/1N2B3/nPR1KPPP/3R4 b - - bm Nxd4+; id ""WAC.037""; d5+1";
const 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"; 
const char wac39[] PROGMEM="r1br2k1/pp2bppp/2nppn2/8/2P1PB2/2N2P2/PqN1B1PP/R2Q1R1K w - - bm Na4; id ""WAC.039""; d5+2.3";
const char wac40[] PROGMEM="3r1r1k/1p4pp/p4p2/8/1PQR4/6Pq/P3PP2/2R3K1 b - - bm Rc8; id ""WAC.040""; d5+3.8";
const char wac41[] PROGMEM="1k6/5RP1/1P6/1K6/6r1/8/8/8 w - - bm Ka5 Kc5 b7; id ""WAC.041""; Ka5 d6+16";
const char wac42[] PROGMEM="r1b1r1k1/pp1n1pbp/1qp3p1/3p4/1B1P4/Q3PN2/PP2BPPP/R4RK1 w - - bm Ba5; id ""WAC.042""; d5+3";
const char wac43[] PROGMEM="r2q3k/p2P3p/1p3p2/3QP1r1/8/B7/P5PP/2R3K1 w - - bm Be7 Qxa8; id ""WAC.043""; Be7 d6+12";
const char wac44[] PROGMEM="3rb1k1/pq3pbp/4n1p1/3p4/2N5/2P2QB1/PP3PPP/1B1R2K1 b - - bm dxc4; id ""WAC.044""; d6+2";
const char wac45[] PROGMEM="7k/2p1b1pp/8/1p2P3/1P3r2/2P3Q1/1P5P/R4qBK b - - bm Qxa1; id ""WAC.045""; d6+5";
const char wac46[] PROGMEM="r1bqr1k1/pp1nb1p1/4p2p/3p1p2/3P4/P1N1PNP1/1PQ2PP1/3RKB1R w K - bm Nb5; id ""WAC.046""; d5+0.5";
const char wac47[] PROGMEM="r1b2rk1/pp2bppp/2n1pn2/q5B1/2BP4/2N2N2/PP2QPPP/2R2RK1 b - - bm Nxd4; id ""WAC.047""; d5+0.3";
const char wac48[] PROGMEM="1rbq1rk1/p1p1bppp/2p2n2/8/Q1BP4/2N5/PP3PPP/R1B2RK1 b - - bm Rb4; id ""WAC.048""; d5+1.7";
const char wac49[] PROGMEM="2b3k1/4rrpp/p2p4/2pP2RQ/1pP1Pp1N/1P3P1P/1q6/6RK w - - bm Qxh7+; id ""WAC.049""; d7+m6";
const char wac50[] PROGMEM="k4r2/1R4pb/1pQp1n1p/3P4/5p1P/3P2P1/r1q1R2K/8 w - - bm Rxb6+; id ""WAC.050""; d5+m3";
const char wac51[] PROGMEM="r1bq1r2/pp4k1/4p2p/3pPp1Q/3N1R1P/2PB4/6P1/6K1 w - - bm Rg4+; id ""WAC.051""; d5+9 d11+m8";
const char wac52[] PROGMEM="r1k5/1p3q2/1Qpb4/3N1p2/5Pp1/3P2Pp/PPPK3P/4R3 w - - bm Re7 c4; id ""WAC.052""; Re7 d5+4";
const char wac53[] PROGMEM="6k1/6p1/p7/3Pn3/5p2/4rBqP/P4RP1/5QK1 b - - bm Re1; id ""WAC.053""; d5+4";
const char wac54[] PROGMEM="r3kr2/1pp4p/1p1p4/7q/4P1n1/2PP2Q1/PP4P1/R1BB2K1 b q - bm Qh1+; id ""WAC.054"";";
const char wac55[] PROGMEM="r3r1k1/pp1q1pp1/4b1p1/3p2B1/3Q1R2/8/PPP3PP/4R1K1 w - - bm Qxg7+; id ""WAC.055""; d8+m4";
const char wac56[] PROGMEM="r1bqk2r/pppp1ppp/5n2/2b1n3/4P3/1BP3Q1/PP3PPP/RNB1K1NR b KQkq - bm Bxf2+; id ""WAC.056""; d5+4";
const char wac57[] PROGMEM="r3q1kr/ppp5/3p2pQ/8/3PP1b1/5R2/PPP3P1/5RK1 w - - bm Rf8+; id ""WAC.057""; d5+m3";
const char wac58[] PROGMEM="8/8/2R5/1p2qp1k/1P2r3/2PQ2P1/5K2/8 w - - bm Qd1+; id ""WAC.058""; d5+7";
const char wac59[] PROGMEM="r1b2rk1/2p1qnbp/p1pp2p1/5p2/2PQP3/1PN2N1P/PB3PP1/3R1RK1 w - - bm Nd5; id ""WAC.059""; d5+4";
const char wac60[] PROGMEM="rn1qr1k1/1p2np2/2p3p1/8/1pPb4/7Q/PB1P1PP1/2KR1B1R w - - bm Qh8+; id ""WAC.060""; d5+m2";
const char wac61[] PROGMEM="3qrbk1/ppp1r2n/3pP2p/3P4/2P4P/1P3Q2/PB6/R4R1K w - - bm Qf7+; id ""WAC.061""; d5+m2";
const char wac62[] PROGMEM="6r1/3Pn1qk/p1p1P1rp/2Q2p2/2P5/1P4P1/P3R2P/5RK1 b - - bm Rxg3+; id ""WAC.062""; d6+0";
const char wac63[] PROGMEM="r1brnbk1/ppq2pp1/4p2p/4N3/3P4/P1PB1Q2/3B1PPP/R3R1K1 w - - bm Nxf7; id ""WAC.063""; d5+2";
const char wac64[] PROGMEM="8/6pp/3q1p2/3n1k2/1P6/3NQ2P/5PP1/6K1 w - - bm g4+; id ""WAC.064""; d5+m2";
const char wac65[] PROGMEM="1r1r1qk1/p2n1p1p/bp1Pn1pQ/2pNp3/2P2P1N/1P5B/P6P/3R1RK1 w - - bm Ne7+; id ""WAC.065""; d5+9";
const char wac66[] PROGMEM="1k1r2r1/ppq5/1bp4p/3pQ3/8/2P2N2/PP4P1/R4R1K b - - bm Qxe5; id ""WAC.066""; d5+4";
const char wac67[] PROGMEM="3r2k1/p2q4/1p4p1/3rRp1p/5P1P/6PK/P3R3/3Q4 w - - bm Rxd5; id ""WAC.067""; d5+4";
const char wac68[] PROGMEM="6k1/5ppp/1q6/2b5/8/2R1pPP1/1P2Q2P/7K w - - bm Qxe3; id ""WAC.068""; d5+6";
const char wac69[] PROGMEM="2k5/pppr4/4R3/4Q3/2pp2q1/8/PPP2PPP/6K1 w - - bm f3 h3; id ""WAC.069""; f3 d7+6";
const char wac70[] PROGMEM="2kr3r/pppq1ppp/3p1n2/bQ2p3/1n1PP3/1PN1BN1P/1PP2PP1/2KR3R b - - bm Na2+; id ""WAC.070""; d5+4";
const char wac71[] PROGMEM="2kr3r/pp1q1ppp/5n2/1Nb5/2Pp1B2/7Q/P4PPP/1R3RK1 w - - bm Nxa7+; id ""WAC.071""; d8+3";
const char wac72[] PROGMEM="r3r1k1/pp1n1ppp/2p5/4Pb2/2B2P2/B1P5/P5PP/R2R2K1 w - - bm e6; id ""WAC.072""; d5+2";
const char wac73[] PROGMEM="r1q3rk/1ppbb1p1/4Np1p/p3pP2/P3P3/2N4R/1PP1Q1PP/3R2K1 w - - bm Qd2; id ""WAC.073""; d5+3.5";
const char wac74[] PROGMEM="5r1k/pp4pp/2p5/2b1P3/4Pq2/1PB1p3/P3Q1PP/3N2K1 b - - bm Qf1+; id ""WAC.074""; d5+7";
const char wac75[] PROGMEM="r3r1k1/pppq1ppp/8/8/1Q4n1/7P/PPP2PP1/RNB1R1K1 b - - bm Qd6; id ""WAC.075""; d5+4";
const char wac76[] PROGMEM="r1b1qrk1/2p2ppp/pb1pnn2/1p2pNB1/3PP3/1BP5/PP2QPPP/RN1R2K1 w - - bm Bxf6; id ""WAC.076""; d5+2";
const char wac77[] PROGMEM="3r2k1/ppp2ppp/6q1/b4n2/3nQB2/2p5/P4PPP/RN3RK1 b - - bm Ng3; id ""WAC.077""; d5+8";
const char wac78[] PROGMEM="r2q3r/ppp2k2/4nbp1/5Q1p/2P1NB2/8/PP3P1P/3RR1K1 w - - bm Ng5+; id ""WAC.078""; d5+4.5";
const char wac79[] PROGMEM="r3k2r/pbp2pp1/3b1n2/1p6/3P3p/1B2N1Pq/PP1PQP1P/R1B2RK1 b kq - bm Qxh2+; id ""WAC.079""; d5+m3";
const char wac80[] PROGMEM="r4rk1/p1B1bpp1/1p2pn1p/8/2PP4/3B1P2/qP2QP1P/3R1RK1 w - - bm Ra1; id ""WAC.080""; d9+3";
const char wac81[] PROGMEM="r4rk1/1bR1bppp/4pn2/1p2N3/1P6/P3P3/4BPPP/3R2K1 b - - bm Bd6; id ""WAC.081""; d5+0.5";
const char wac82[] PROGMEM="3rr1k1/pp3pp1/4b3/8/2P1B2R/6QP/P3q1P1/5R1K w - - bm Bh7+; id ""WAC.082""; d5+8";
const char wac83[] PROGMEM="3rr1k1/ppqbRppp/2p5/8/3Q1n2/2P3N1/PPB2PPP/3R2K1 w - - bm Qxd7; id ""WAC.083""; d5+3.5";
const char wac84[] PROGMEM="r2q1r1k/2p1b1pp/p1n5/1p1Q1bN1/4n3/1BP1B3/PP3PPP/R4RK1 w - - bm Qg8+; id ""WAC.084""; d5+m2";
const char wac85[] PROGMEM="kr2R3/p4r2/2pq4/2N2p1p/3P2p1/Q5P1/5P1P/5BK1 w - - bm Na6; id ""WAC.085""; d5+6 d7+10";
const char wac86[] PROGMEM="8/p7/1ppk1n2/5ppp/P1PP4/2P1K1P1/5N1P/8 b - - bm Ng4+; id ""WAC.086""; d5+0.5";
const char wac87[] PROGMEM="8/p3k1p1/4r3/2ppNpp1/PP1P4/2P3KP/5P2/8 b - - bm Rxe5; id ""WAC.087""; d8+6";
const char wac88[] PROGMEM="r6k/p1Q4p/2p1b1rq/4p3/B3P3/4P3/PPP3P1/4RRK1 b - - bm Rxg2+; id ""WAC.088""; d5+m5";
const char wac89[] PROGMEM="1r3b1k/p4rpp/4pp2/3q4/2ppbPPQ/6RK/PP5P/2B1NR2 b - - bm g5; id ""WAC.089""; d5+7";
const char wac90[] PROGMEM="3qrrk1/1pp2pp1/1p2bn1p/5N2/2P5/P1P3B1/1P4PP/2Q1RRK1 w - - bm Nxg7; id ""WAC.090""; d5+2.5";
const char wac91[] PROGMEM="2qr2k1/4b1p1/2p2p1p/1pP1p3/p2nP3/PbQNB1PP/1P3PK1/4RB2 b - - bm Be6; id ""WAC.091""; d6+1";
const char wac92[] PROGMEM="r4rk1/1p2ppbp/p2pbnp1/q7/3BPPP1/2N2B2/PPP4P/R2Q1RK1 b - - bm Bxg4; id ""WAC.092""; d9+0.7";
const char wac93[] PROGMEM="r1b1k1nr/pp3pQp/4pq2/3pn3/8/P1P5/2P2PPP/R1B1KBNR w KQkq - bm Bh6; id ""WAC.093""; d5+1";
const char wac94[] PROGMEM="8/k7/p7/3Qp2P/n1P5/3KP3/1q6/8 b - - bm e4+; id ""WAC.094""; d5+9";
const char wac95[] PROGMEM="2r5/1r6/4pNpk/3pP1qp/8/2P1QP2/5PK1/R7 w - - bm Ng4+; id ""WAC.095""; d5+9";
const char wac96[] PROGMEM="r1b4k/ppp2Bb1/6Pp/3pP3/1qnP1p1Q/8/PPP3P1/1K1R3R w - - bm Qd8+ b3; id ""WAC.096""; d5+2 d14+m9";
const char wac97[] PROGMEM="6k1/5p2/p5np/4B3/3P4/1PP1q3/P3r1QP/6RK w - - bm Qa8+; id ""WAC.097"";";
const char wac98[] PROGMEM="1r3rk1/5pb1/p2p2p1/Q1n1q2p/1NP1P3/3p1P1B/PP1R3P/1K2R3 b - - bm Nxe4; id ""WAC.098""; d5+5";
const char wac99[] PROGMEM="r1bq1r1k/1pp1Np1p/p2p2pQ/4R3/n7/8/PPPP1PPP/R1B3K1 w - - bm Rh5; id ""WAC.099""; d5+m2";
const 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";
const char wac101[] PROGMEM="5rk1/p5pp/8/8/2Pbp3/1P4P1/7P/4RN1K b - - bm Bc3; id ""WAC.101""; d10+1.5";
const char wac102[] PROGMEM="2Q2n2/2R4p/1p1qpp1k/8/3P3P/3B2P1/5PK1/r7 w - - bm Qxf8+; id ""WAC.102""; d5+m3";
const char wac103[] PROGMEM="6k1/2pb1r1p/3p1PpQ/p1nPp3/1q2P3/2N2P2/PrB5/2K3RR w - - bm Qxg6+; id ""WAC.103""; d5+m4";
const char wac104[] PROGMEM="b4r1k/pq2rp2/1p1bpn1p/3PN2n/2P2P2/P2B3K/1B2Q2N/3R2R1 w - - bm Qxh5; id ""WAC.104""; d5+m3";
const char wac105[] PROGMEM="r2r2k1/pb3ppp/1p1bp3/7q/3n2nP/PP1B2P1/1B1N1P2/RQ2NRK1 b - - bm Bxg3 Qxh4; id ""WAC.105""; Qxh4 d7+m8 d8+m6";
const char wac106[] PROGMEM="4rrk1/pppb4/7p/3P2pq/3Qn3/P5P1/1PP4P/R3RNNK b - - bm Nf2+; id ""WAC.106""; d5+9";
const char wac107[] PROGMEM="5n2/pRrk2p1/P4p1p/4p3/3N4/5P2/6PP/6K1 w - - bm Nb5; id ""WAC.107""; d5+3";
const char wac108[] PROGMEM="r5k1/1q4pp/2p5/p1Q5/2P5/5R2/4RKPP/r7 w - - bm Qe5; id ""WAC.108""; d5+3";
const char wac109[] PROGMEM="rn2k1nr/pbp2ppp/3q4/1p2N3/2p5/QP6/PB1PPPPP/R3KB1R b KQkq - bm c3; id ""WAC.109""; d7+0.5";
const char wac110[] PROGMEM="2kr4/bp3p2/p2p2b1/P7/2q5/1N4B1/1PPQ2P1/2KR4 b - - bm Be3; id ""WAC.110""; d5+7";
const char wac111[] PROGMEM="6k1/p5p1/5p2/2P2Q2/3pN2p/3PbK1P/7P/6q1 b - - bm Qf1+; id ""WAC.111""; d5+10";
const char wac112[] PROGMEM="r4kr1/ppp5/4bq1b/7B/2PR1Q1p/2N3P1/PP3P1P/2K1R3 w - - bm Rxe6; id ""WAC.112""; d5+2.5";
const char wac113[] PROGMEM="rnbqkb1r/1p3ppp/5N2/1p2p1B1/2P5/8/PP2PPPP/R2QKB1R b KQkq - bm Qxf6; id ""WAC.113""; d5+1";
const char wac114[] PROGMEM="r1b1rnk1/1p4pp/p1p2p2/3pN2n/3P1PPq/2NBPR1P/PPQ5/2R3K1 w - - bm Bxh7+; id ""WAC.114""; d5+2.5";
const char wac115[] PROGMEM="4N2k/5rpp/1Q6/p3q3/8/P5P1/1P3P1P/5K2 w - - bm Nd6; id ""WAC.115""; d5+2.5";
const char wac116[] PROGMEM="r2r2k1/2p2ppp/p7/1p2P1n1/P6q/5P2/1PB1QP1P/R5RK b - - bm Rd2; id ""WAC.116""; d8+2";
const char wac117[] PROGMEM="3r1rk1/q4ppp/p1Rnp3/8/1p6/1N3P2/PP3QPP/3R2K1 b - - bm Ne4; id ""WAC.117""; d5+6";
const char wac118[] PROGMEM="r5k1/pb2rpp1/1p6/2p4q/5R2/2PB2Q1/P1P3PP/5R1K w - - bm Rh4; id ""WAC.118""; d5+4";
const char wac119[] PROGMEM="r2qr1k1/p1p2ppp/2p5/2b5/4nPQ1/3B4/PPP3PP/R1B2R1K b - - bm Qxd3; id ""WAC.119""; d5+4";
const char wac120[] PROGMEM="r4rk1/1bn2qnp/3p1B1Q/p2P1pP1/1pp5/5N1P/PPB2P2/2KR3R w - - bm Rhg1 g6; id ""WAC.120""; g6 d7+3";
const char wac121[] PROGMEM="6k1/5p1p/2bP2pb/4p3/2P5/1p1pNPPP/1P1Q1BK1/1q6 b - - bm Bxf3+; id ""WAC.121""; d5+11";
const char wac122[] PROGMEM="1k6/ppp4p/1n2pq2/1N2Rb2/2P2Q2/8/P4KPP/3r1B2 b - - bm Rxf1+; id ""WAC.122""; d5+12";
const 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";
const char wac124[] PROGMEM="6k1/3r4/2R5/P5P1/1P4p1/8/4rB2/6K1 b - - bm g3; id ""WAC.124""; d5+2";
const char wac125[] PROGMEM="r1bqr1k1/pp3ppp/1bp5/3n4/3B4/2N2P1P/PPP1B1P1/R2Q1RK1 b - - bm Bxd4+; id ""WAC.125""; d5+3";
const char wac126[] PROGMEM="r5r1/pQ5p/1qp2R2/2k1p3/4P3/2PP4/P1P3PP/6K1 w - - bm Rxc6+; id ""WAC.126""; d5+4";
const char wac127[] PROGMEM="2k4r/1pr1n3/p1p1q2p/5pp1/3P1P2/P1P1P3/1R2Q1PP/1RB3K1 w - - bm Rxb7; id ""WAC.127""; d5+3";
const char wac128[] PROGMEM="6rk/1pp2Qrp/3p1B2/1pb1p2R/3n1q2/3P4/PPP3PP/R6K w - - bm Qg6; id ""WAC.128""; d5+2";
const char wac129[] PROGMEM="3r1r1k/1b2b1p1/1p5p/2p1Pp2/q1B2P2/4P2P/1BR1Q2K/6R1 b - - bm Bf3; id ""WAC.129""; d5+1.3";
const char wac130[] PROGMEM="6k1/1pp3q1/5r2/1PPp4/3P1pP1/3Qn2P/3B4/4R1K1 b - - bm Qh6 Qh8; id ""WAC.130""; Qh6 d5+1";
const char wac131[] PROGMEM="2rq1bk1/p4p1p/1p4p1/3b4/3B1Q2/8/P4PpP/3RR1K1 w - - bm Re8; id ""WAC.131""; d6+2";
const char wac132[] PROGMEM="4r1k1/5bpp/2p5/3pr3/8/1B3pPq/PPR2P2/2R2QK1 b - - bm Re1; id ""WAC.132""; d5+m3";
const char wac133[] PROGMEM="r1b1k2r/1pp1q2p/p1n3p1/3QPp2/8/1BP3B1/P5PP/3R1RK1 w kq - bm Bh4; id ""WAC.133""; d5+3";
const char wac134[] PROGMEM="3r2k1/p6p/2Q3p1/4q3/2P1p3/P3Pb2/1P3P1P/2K2BR1 b - - bm Rd1+; id ""WAC.134""; d5+m4";
const char wac135[] PROGMEM="3r1r1k/N2qn1pp/1p2np2/2p5/2Q1P2N/3P4/PP4PP/3R1RK1 b - - bm Nd4; id ""WAC.135""; d5+1.3";
const char wac136[] PROGMEM="6kr/1q2r1p1/1p2N1Q1/5p2/1P1p4/6R1/7P/2R3K1 w - - bm Rc8+; id ""WAC.136""; Qf6 d6+m6 Rc8+ d8+m3";
const char wac137[] PROGMEM="3b1rk1/1bq3pp/5pn1/1p2rN2/2p1p3/2P1B2Q/1PB2PPP/R2R2K1 w - - bm Rd7; id ""WAC.137""; d5+2";
const char wac138[] PROGMEM="r1bq3r/ppppR1p1/5n1k/3P4/6pP/3Q4/PP1N1PP1/5K1R w - - bm h5; id ""WAC.138""; d5+m7 d8+m5";
const char wac139[] PROGMEM="rnb3kr/ppp2ppp/1b6/3q4/3pN3/Q4N2/PPP2KPP/R1B1R3 w - - bm Nf6+; id ""WAC.139""; d5+m4";
const char wac140[] PROGMEM="r2b1rk1/pq4p1/4ppQP/3pB1p1/3P4/2R5/PP3PP1/5RK1 w - - bm Bc7 Rc7; id ""WAC.140""; Rc7 d5+9";
const char wac141[] PROGMEM="4r1k1/p1qr1p2/2pb1Bp1/1p5p/3P1n1R/1B3P2/PP3PK1/2Q4R w - - bm Qxf4; id ""WAC.141""; d10+19 d12+m6";
const char wac142[] PROGMEM="r2q3n/ppp2pk1/3p4/5Pr1/2NP1Qp1/2P2pP1/PP3K2/4R2R w - - bm Re8 f6+; id ""WAC.142""; f6+ d5+3";
const char wac143[] PROGMEM="5b2/pp2r1pk/2pp1pRp/4rP1N/2P1P3/1P4QP/P3q1P1/5R1K w - - bm Rxh6+; id ""WAC.143""; d5+m3";
const char wac144[] PROGMEM="r2q1rk1/pp3ppp/2p2b2/8/B2pPPb1/7P/PPP1N1P1/R2Q1RK1 b - - bm d3; id ""WAC.144""; d5+1.6";
const char wac145[] PROGMEM="r1bq4/1p4kp/3p1n2/p4pB1/2pQ4/8/1P4PP/4RRK1 w - - bm Re8; id ""WAC.145""; d8+15";
const char wac146[] PROGMEM="8/8/2Kp4/3P1B2/2P2k2/5p2/8/8 w - - bm Bc8 Bd3 Bh3; id ""WAC.146""; Bc8 d5+2";
const char wac147[] PROGMEM="r2r2k1/ppqbppbp/2n2np1/2pp4/6P1/1P1PPNNP/PBP2PB1/R2QK2R b KQ - bm Nxg4; id ""WAC.147""; d5+1.7";
const char wac148[] PROGMEM="2r1k3/6pr/p1nBP3/1p3p1p/2q5/2P5/P1R4P/K2Q2R1 w - - bm Rxg7; id ""WAC.148""; d5+9";
const char wac149[] PROGMEM="6k1/6p1/2p4p/4Pp2/4b1qP/2Br4/1P2RQPK/8 b - - bm Bxg2; id ""WAC.149""; d5+2";
const 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";
const char wac151[] PROGMEM="8/3b2kp/4p1p1/pr1n4/N1N4P/1P4P1/1K3P2/3R4 w - - bm Nc3; id ""WAC.151""; d5+1";
const char wac152[] PROGMEM="1br2rk1/1pqb1ppp/p3pn2/8/1P6/P1N1PN1P/1B3PP1/1QRR2K1 w - - bm Ne4; id ""WAC.152""; d5+2";
const char wac153[] PROGMEM="2r3k1/q4ppp/p3p3/pnNp4/2rP4/2P2P2/4R1PP/2R1Q1K1 b - - bm Nxd4; id ""WAC.153""; d5+2";
const char wac154[] PROGMEM="r1b2rk1/2p2ppp/p7/1p6/3P3q/1BP3bP/PP3QP1/RNB1R1K1 w - - bm Qxf7+; id ""WAC.154""; d5+m2";
const char wac155[] PROGMEM="5bk1/1rQ4p/5pp1/2pP4/3n1PP1/7P/1q3BB1/4R1K1 w - - bm d6; id ""WAC.155""; d5+2.5";
const char wac156[] PROGMEM="r1b1qN1k/1pp3p1/p2p3n/4p1B1/8/1BP4Q/PP3KPP/8 w - - bm Qxh6+; id ""WAC.156""; d5+m2";
const char wac157[] PROGMEM="5rk1/p4ppp/2p1b3/3Nq3/4P1n1/1p1B2QP/1PPr2P1/1K2R2R w - - bm Ne7+; id ""WAC.157""; d7+1.5";
const char wac158[] PROGMEM="5rk1/n1p1R1bp/p2p4/1qpP1QB1/7P/2P3P1/PP3P2/6K1 w - - bm Rxg7+; id ""WAC.158""; d5+m3";
const char wac159[] PROGMEM="r1b2r2/5P1p/ppn3pk/2p1p1Nq/1bP1PQ2/3P4/PB4BP/1R3RK1 w - - bm Ne6+; id ""WAC.159""; d5+6";
const char wac160[] PROGMEM="qn1kr2r/1pRbb3/pP5p/P2pP1pP/3N1pQ1/3B4/3B1PP1/R5K1 w - - bm Qxd7+; id ""WAC.160""; d5+m2";
const char wac161[] PROGMEM="3r3k/3r1P1p/pp1Nn3/2pp4/7Q/6R1/Pq4PP/5RK1 w - - bm Qxd8+; id ""WAC.161""; d5+m4";
const char wac162[] PROGMEM="r3kbnr/p4ppp/2p1p3/8/Q1B3b1/2N1B3/PP3PqP/R3K2R w KQkq - bm Bd5; id ""WAC.162""; d5+1.2";
const char wac163[] PROGMEM="5rk1/2p4p/2p4r/3P4/4p1b1/1Q2NqPp/PP3P1K/R4R2 b - - bm Qg2+; id ""WAC.163""; d12+m11";
const char wac164[] PROGMEM="8/6pp/4p3/1p1n4/1NbkN1P1/P4P1P/1PR3K1/r7 w - - bm Rxc4+; id ""WAC.164""; d5+3.5";
const char wac165[] PROGMEM="1r5k/p1p3pp/8/8/4p3/P1P1R3/1P1Q1qr1/2KR4 w - - bm Re2; id ""WAC.165""; d5+3.5";
const char wac166[] PROGMEM="r3r1k1/5pp1/p1p4p/2Pp4/8/q1NQP1BP/5PP1/4K2R b K - bm d4; id ""WAC.166""; d5+2";
const char wac167[] PROGMEM="7Q/ppp2q2/3p2k1/P2Ppr1N/1PP5/7R/5rP1/6K1 b - - bm Rxg2+; id ""WAC.167""; d5+m5";
const char wac168[] PROGMEM="r3k2r/pb1q1p2/8/2p1pP2/4p1p1/B1P1Q1P1/P1P3K1/R4R2 b kq - bm Qd2+; id ""WAC.168""; d5+17 d9+m11 d11+m8";
const char wac169[] PROGMEM="5rk1/1pp3bp/3p2p1/2PPp3/1P2P3/2Q1B3/4q1PP/R5K1 b - - bm Bh6; id ""WAC.169""; d7+4";
const char wac170[] PROGMEM="5r1k/6Rp/1p2p3/p2pBp2/1qnP4/4P3/Q4PPP/6K1 w - - bm Qxc4; id ""WAC.170""; d5+4";
const char wac171[] PROGMEM="2rq4/1b2b1kp/p3p1p1/1p1nNp2/7P/1B2B1Q1/PP3PP1/3R2K1 w - - bm Bh6+; id ""WAC.171""; d5+1.8";
const char wac172[] PROGMEM="5r1k/p5pp/8/1P1pq3/P1p2nR1/Q7/5BPP/6K1 b - - bm Qe1+; id ""WAC.172""; d5+m3";
const char wac173[] PROGMEM="2r1b3/1pp1qrk1/p1n1P1p1/7R/2B1p3/4Q1P1/PP3PP1/3R2K1 w - - bm Qh6+; id ""WAC.173""; d5+m3";
const char wac174[] PROGMEM="2r2rk1/6p1/p3pq1p/1p1b1p2/3P1n2/PP3N2/3N1PPP/1Q2RR1K b - - bm Nxg2; id ""WAC.174""; d5+2";
const char wac175[] PROGMEM="r5k1/pppb3p/2np1n2/8/3PqNpP/3Q2P1/PPP5/R4RK1 w - - bm Nh5; id ""WAC.175""; d5+1.7";
const char wac176[] PROGMEM="r1bq3r/ppp2pk1/3p1pp1/8/2BbPQ2/2NP2P1/PPP4P/R4R1K b - - bm Rxh2+; id ""WAC.176""; d5+2";
const char wac177[] PROGMEM="r1b3r1/4qk2/1nn1p1p1/3pPp1P/p4P2/1p3BQN/PKPBN3/3R3R b - - bm Qa3+; id ""WAC.177""; d5+m3";
const char wac178[] PROGMEM="3r2k1/p1rn1p1p/1p2pp2/6q1/3PQNP1/5P2/P1P4R/R5K1 w - - bm Nxe6; id ""WAC.178""; d6+1";
const char wac179[] PROGMEM="r1b2r1k/pp4pp/3p4/3B4/8/1QN3Pn/PP3q1P/R3R2K b - - bm Qg1+; id ""WAC.179""; d5+m3";
const char wac180[] PROGMEM="r1q2rk1/p3bppb/3p1n1p/2nPp3/1p2P1P1/6NP/PP2QPB1/R1BNK2R b KQ - bm Nxd5; id ""WAC.180""; d5+1";
const char wac181[] PROGMEM="r3k2r/2p2p2/p2p1n2/1p2p3/4P2p/1PPPPp1q/1P5P/R1N2QRK b kq - bm Ng4; id ""WAC.181""; d5+5.5";
const char wac182[] PROGMEM="r1b2rk1/ppqn1p1p/2n1p1p1/2b3N1/2N5/PP1BP3/1B3PPP/R2QK2R w KQ - bm Qh5; id ""WAC.182""; d5+m7 d11+m6";
const char wac183[] PROGMEM="1r2k1r1/5p2/b3p3/1p2b1B1/3p3P/3B4/PP2KP2/2R3R1 w - - bm Bf6; id ""WAC.183""; d5+1.7";
const char wac184[] PROGMEM="4kn2/r4p1r/p3bQ2/q1nNP1Np/1p5P/8/PPP3P1/2KR3R w - - bm Qe7+; id ""WAC.184""; d5+m2";
const char wac185[] PROGMEM="1r1rb1k1/2p3pp/p2q1p2/3PpP1Q/Pp1bP2N/1B5R/1P4PP/2B4K w - - bm Qxh7+; id ""WAC.185""; d6+4";
const char wac186[] PROGMEM="r5r1/p1q2p1k/1p1R2pB/3pP3/6bQ/2p5/P1P1NPPP/6K1 w - - bm Bf8+; id ""WAC.186""; d5+m3";
const char wac187[] PROGMEM="6k1/5p2/p3p3/1p3qp1/2p1Qn2/2P1R3/PP1r1PPP/4R1K1 b - - bm Nh3+; id ""WAC.187""; d5+6";
const char wac188[] PROGMEM="3RNbk1/pp3p2/4rQpp/8/1qr5/7P/P4P2/3R2K1 w - - bm Qg7+; id ""WAC.188""; d5+m2";
const char wac189[] PROGMEM="3r1k2/1ppPR1n1/p2p1rP1/3P3p/4Rp1N/5K2/P1P2P2/8 w - - bm Re8+; id ""WAC.189""; d6+7";
const char wac190[] PROGMEM="8/p2b2kp/1q1p2p1/1P1Pp3/4P3/3B2P1/P2Q3P/2Nn3K b - - bm Bh3; id ""WAC.190""; d5+6";
const char wac191[] PROGMEM="2r1Rn1k/1p1q2pp/p7/5p2/3P4/1B4P1/P1P1QP1P/6K1 w - - bm Qc4; id ""WAC.191""; d5+m3";
const char wac192[] PROGMEM="r3k3/ppp2Npp/4Bn2/2b5/1n1pp3/N4P2/PPP3qP/R2QKR2 b Qq - bm Nd3+; id ""WAC.192""; d5+6";
const char wac193[] PROGMEM="5bk1/p4ppp/Qp6/4B3/1P6/Pq2P1P1/2rr1P1P/R4RK1 b - - bm Qxe3; id ""WAC.193""; d6+8 d11+m8";
const char wac194[] PROGMEM="5rk1/ppq2ppp/2p5/4bN2/4P3/6Q1/PPP2PPP/3R2K1 w - - bm Nh6+; id ""WAC.194""; d6+5";
const char wac195[] PROGMEM="3r1rk1/1p3p2/p3pnnp/2p3p1/2P2q2/1P5P/PB2QPPN/3RR1K1 w - - bm g3; id ""WAC.195""; d5+2";
const char wac196[] PROGMEM="rr4k1/p1pq2pp/Q1n1pn2/2bpp3/4P3/2PP1NN1/PP3PPP/R1B1K2R b KQ - bm Nb4; id ""WAC.196""; d8+1";
const char wac197[] PROGMEM="7k/1p4p1/7p/3P1n2/4Q3/2P2P2/PP3qRP/7K b - - bm Qf1+; id ""WAC.197""; d5+m3";
const char wac198[] PROGMEM="2br2k1/ppp2p1p/4p1p1/4P2q/2P1Bn2/2Q5/PP3P1P/4R1RK b - - bm Rd3; id ""WAC.198""; d5+3.5";
const char wac199[] PROGMEM="r1br2k1/pp2nppp/2n5/1B1q4/Q7/4BN2/PP3PPP/2R2RK1 w - - bm Bxc6 Rcd1 Rfd1; id ""WAC.199""; Rfd1 d5+3";
const char wac200[] PROGMEM="2rqrn1k/pb4pp/1p2pp2/n2P4/2P3N1/P2B2Q1/1B3PPP/2R1R1K1 w - - bm Bxf6; id ""WAC.200""; d5+2.5";
const char wac201[] PROGMEM="2b2r1k/4q2p/3p2pQ/2pBp3/8/6P1/1PP2P1P/R5K1 w - - bm Ra7; id ""WAC.201""; d5+m6";
const char wac202[] PROGMEM="QR2rq1k/2p3p1/3p1pPp/8/4P3/8/P1r3PP/1R4K1 b - - bm Rxa2; id ""WAC.202""; d5+0.3";
const char wac203[] PROGMEM="r4rk1/5ppp/p3q1n1/2p2NQ1/4n3/P3P3/1B3PPP/1R3RK1 w - - bm Qh6; id ""WAC.203""; d5+m3";
const char wac204[] PROGMEM="r1b1qrk1/1p3ppp/p1p5/3Nb3/5N2/P7/1P4PQ/K1R1R3 w - - bm Rxe5; id ""WAC.204""; d5+0.4";
const char wac205[] PROGMEM="r3rnk1/1pq2bb1/p4p2/3p1Pp1/3B2P1/1NP4R/P1PQB3/2K4R w - - bm Qxg5; id ""WAC.205""; d6+3";
const char wac206[] PROGMEM="1Qq5/2P1p1kp/3r1pp1/8/8/7P/p4PP1/2R3K1 b - - bm Rc6; id ""WAC.206""; d5+1.5";
const char wac207[] PROGMEM="r1bq2kr/p1pp1ppp/1pn1p3/4P3/2Pb2Q1/BR6/P4PPP/3K1BNR w - - bm Qxg7+; id ""WAC.207""; d5+2";
const char wac208[] PROGMEM="3r1bk1/ppq3pp/2p5/2P2Q1B/8/1P4P1/P6P/5RK1 w - - bm Bf7+; id ""WAC.208""; d5+10";
const char wac209[] PROGMEM="4kb1r/2q2p2/r2p4/pppBn1B1/P6P/6Q1/1PP5/2KRR3 w k - bm Rxe5+; id ""WAC.209""; d6+8";
const char wac210[] PROGMEM="3r1rk1/pp1q1ppp/3pn3/2pN4/5PP1/P5PQ/1PP1B3/1K1R4 w - - bm Rh1; id ""WAC.210""; d7+3";
const char wac211[] PROGMEM="r1bqrk2/pp1n1n1p/3p1p2/P1pP1P1Q/2PpP1NP/6R1/2PB4/4RBK1 w - - bm Qxf7+; id ""WAC.211""; d5+m5";
const char wac212[] PROGMEM="rn1qr2Q/pbppk1p1/1p2pb2/4N3/3P4/2N5/PPP3PP/R4RK1 w - - bm Qxg7+; id ""WAC.212""; d5+m5";
const char wac213[] PROGMEM="3r1r1k/1b4pp/ppn1p3/4Pp1R/Pn5P/3P4/4QP2/1qB1NKR1 w - - bm Rxh7+ Rxg7+; id ""WAC.213""; d7+0";
const char wac214[] PROGMEM="r2r2k1/1p2qpp1/1np1p1p1/p3N3/2PPN3/bP5R/4QPPP/4R1K1 w - - bm Ng5; id ""WAC.214""; d5+3";
const char wac215[] PROGMEM="3r2k1/pb1q1pp1/1p2pb1p/8/3N4/P2QB3/1P3PPP/1Br1R1K1 w - - bm Qh7+; id ""WAC.215""; d5+m4";
const char wac216[] PROGMEM="r2qr1k1/1b1nbppp/p3pn2/1p1pN3/3P1B2/2PB1N2/PP2QPPP/R4RK1 w - - bm Nxf7 a4; id ""WAC.216""; d5+1.5";
const char wac217[] PROGMEM="r3kb1r/1pp3p1/p3bp1p/5q2/3QN3/1P6/PBP3P1/3RR1K1 w kq - bm Qd7+; id ""WAC.217""; d7+m5";
const char wac218[] PROGMEM="6k1/pp5p/2p3q1/6BP/2nPr1Q1/8/PP3R1K/8 w - - bm Bh6; id ""WAC.218""; d7+m6";
const char wac219[] PROGMEM="7k/p4q1p/1pb5/2p5/4B2Q/2P1B3/P6P/7K b - - bm Qf1+; id ""WAC.219""; d5+m3";
const char wac220[] PROGMEM="3rr1k1/ppp2ppp/8/5Q2/4n3/1B5R/PPP1qPP1/5RK1 b - - bm Qxf1+; id ""WAC.220""; d6+6";
const char wac221[] PROGMEM="r3k3/P5bp/2N1bp2/4p3/2p5/6NP/1PP2PP1/3R2K1 w q - bm Rd8+; id ""WAC.221""; d5+5";
const char wac222[] PROGMEM="2r1r2k/1q3ppp/p2Rp3/2p1P3/6QB/p3P3/bP3PPP/3R2K1 w - - bm Bf6; id ""WAC.222""; d9+m6";
const char wac223[] PROGMEM="r1bqk2r/pp3ppp/5n2/8/1b1npB2/2N5/PP1Q2PP/1K2RBNR w kq - bm Nxe4; id ""WAC.223""; d7+0.7";
const char wac224[] PROGMEM="5rk1/p1q3pp/1p1r4/2p1pp1Q/1PPn1P2/3B3P/P2R2P1/3R2K1 b - - bm Rh6 e4; id ""WAC.224""; Rh6 d6+3 e4 d9+4";
const char wac225[] PROGMEM="4R3/4q1kp/6p1/1Q3b2/1P1b1P2/6KP/8/8 b - - bm Qh4+; id ""WAC.225""; d5+m3";
const char wac226[] PROGMEM="2b2rk1/p1p4p/2p1p1p1/br2N1Q1/1p2q3/8/PB3PPP/3R1RK1 w - - bm Nf7; id ""WAC.226""; d7+3.5 ";
const char wac227[] PROGMEM="2k1rb1r/ppp3pp/2np1q2/5b2/2B2P2/2P1BQ2/PP1N1P1P/2KR3R b - - bm d5; id ""WAC.227""; d5+2.5";
const char wac228[] PROGMEM="r4rk1/1bq1bp1p/4p1p1/p2p4/3BnP2/1N1B3R/PPP3PP/R2Q2K1 w - - bm Bxe4; id ""WAC.228""; d6+1.5";
const char wac229[] PROGMEM="8/8/8/1p5r/p1p1k1pN/P2pBpP1/1P1K1P2/8 b - - bm Rxh4 b4; id ""WAC.229""; b4 d14+4.5";
const char wac230[] PROGMEM="2b5/1r6/2kBp1p1/p2pP1P1/2pP4/1pP3K1/1R3P2/8 b - - bm Rb4; id ""WAC.230""; ??? Rh7d5+2.5";
const char wac231[] PROGMEM="r4rk1/1b1nqp1p/p5p1/1p2PQ2/2p5/5N2/PP3PPP/R1BR2K1 w - - bm Bg5; id ""WAC.231""; d5+0.5";
const char wac232[] PROGMEM="1R2rq1k/2p3p1/Q2p1pPp/8/4P3/8/P1r3PP/1R4K1 w - - bm Qb5 Rxe8; id ""WAC.232""; Rxe8 d8+3 Qb5 d14+7";
const char wac233[] PROGMEM="5rk1/p1p2r1p/2pp2p1/4p3/PPPnP3/3Pq1P1/1Q1R1R1P/4NK2 b - - bm Nb3; id ""WAC.233""; d7+6";
const char wac234[] PROGMEM="2kr1r2/p6p/5Pp1/2p5/1qp2Q1P/7R/PP6/1KR5 w - - bm Rb3; id ""WAC.234""; d5+5";
const 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";
const char wac236[] PROGMEM="1R6/p5pk/4p2p/4P3/8/2r3qP/P3R1b1/4Q1K1 b - - bm Rc1; id ""WAC.236""; d5+0.8";
const char wac237[] PROGMEM="r5k1/pQp2qpp/8/4pbN1/3P4/6P1/PPr4P/1K1R3R b - - bm Rc1+; id ""WAC.237""; d12+15";
const char wac238[] PROGMEM="1k1r4/pp1r1pp1/4n1p1/2R5/2Pp1qP1/3P2QP/P4PB1/1R4K1 w - - bm Bxb7; id ""WAC.238""; d5+4";
const char wac239[] PROGMEM="8/6k1/5pp1/Q6p/5P2/6PK/P4q1P/8 b - - bm Qf1+; id ""WAC.239""; d10+13";
const char wac240[] PROGMEM="2b4k/p1b2p2/2p2q2/3p1PNp/3P2R1/3B4/P1Q2PKP/4r3 w - - bm Qxc6; id ""WAC.240""; d6+5";
const char wac241[] PROGMEM="2rq1rk1/pp3ppp/2n2b2/4NR2/3P4/PB5Q/1P4PP/3R2K1 w - - bm Qxh7+; id ""WAC.241""; d11+m6";
const char wac242[] PROGMEM="r1b1r1k1/pp1nqp2/2p1p1pp/8/4N3/P1Q1P3/1P3PPP/1BRR2K1 w - - bm Rxd7; id ""WAC.242""; d5+3.5";
const char wac243[] PROGMEM="1r3r1k/3p4/1p1Nn1R1/4Pp1q/pP3P1p/P7/5Q1P/6RK w - - bm Qe2; id ""WAC.243""; d7+1.5";
const char wac244[] PROGMEM="r6r/pp3ppp/3k1b2/2pb4/B4Pq1/2P1Q3/P5PP/1RBR2K1 w - - bm Qxc5+; id ""WAC.244""; d5+m4";
const char wac245[] PROGMEM="4rrn1/ppq3bk/3pPnpp/2p5/2PB4/2NQ1RPB/PP5P/5R1K w - - bm Qxg6+; id ""WAC.245""; d7+4";
const char wac246[] PROGMEM="6R1/4qp1p/ppr1n1pk/8/1P2P1QP/6N1/P4PP1/6K1 w - - bm Qh5+; id ""WAC.246""; d5+m2";
const char wac247[] PROGMEM="2k1r3/1p2Bq2/p2Qp3/Pb1p1p1P/2pP1P2/2P5/2P2KP1/1R6 w - - bm Rxb5; id ""WAC.247""; d8+7";
const char wac248[] PROGMEM="5r1k/1p4pp/3q4/3Pp1R1/8/8/PP4PP/4Q1K1 b - - bm Qc5+; id ""WAC.248""; d6+0.5";
const 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"; 
const char wac250[] PROGMEM="1b5k/7P/p1p2np1/2P2p2/PP3P2/4RQ1R/q2r3P/6K1 w - - bm Re8+; id ""WAC.250""; d5+m8";
const char wac251[] PROGMEM="k7/p4p2/P1q1b1p1/3p3p/3Q4/7P/5PP1/1R4K1 w - - bm Qe5 Qf4; id ""WAC.251""; d8+m6";
const 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";
const char wac253[] PROGMEM="k5r1/p4b2/2P5/5p2/3P1P2/4QBrq/P5P1/4R1K1 w - - bm Qe8+; id ""WAC.253""; d5+m4";
const char wac254[] PROGMEM="r6k/pp3p1p/2p1bp1q/b3p3/4Pnr1/2PP2NP/PP1Q1PPN/R2B2RK b - - bm Nxh3; id ""WAC.254""; d5+2.5";
const char wac255[] PROGMEM="3r3r/p4pk1/5Rp1/3q4/1p1P2RQ/5N2/P1P4P/2b4K w - - bm Rfxg6+; id ""WAC.255""; d5+4";
const char wac256[] PROGMEM="3r1rk1/1pb1qp1p/2p3p1/p7/P2Np2R/1P5P/1BP2PP1/3Q1BK1 w - - bm Nf5; id ""WAC.256""; d9+3";
const char wac257[] PROGMEM="4r1k1/pq3p1p/2p1r1p1/2Q1p3/3nN1P1/1P6/P1P2P1P/3RR1K1 w - - bm Rxd4; id ""WAC.257""; d5+3";
const char wac258[] PROGMEM="r3brkn/1p5p/2p2Ppq/2Pp3B/3Pp2Q/4P1R1/6PP/5R1K w - - bm Bxg6; id ""WAC.258""; d5+0.2";
const char wac259[] PROGMEM="r1bq1rk1/ppp2ppp/2np4/2bN1PN1/2B1P3/3p4/PPP2nPP/R1BQ1K1R w - - bm Qh5; id ""WAC.259""; d5-1.5";
const char wac260[] PROGMEM="2r2b1r/p1Nk2pp/3p1p2/N2Qn3/4P3/q6P/P4PP1/1R3K1R w - - bm Qe6+; id ""WAC.260""; d5+m5";
const char wac261[] PROGMEM="r5k1/1bp3pp/p2p4/1p6/5p2/1PBP1nqP/1PP3Q1/R4R1K b - - bm Nd4; id ""WAC.261""; d6+9";
const char wac262[] PROGMEM="6k1/p1B1b2p/2b3r1/2p5/4p3/1PP1N1Pq/P2R1P2/3Q2K1 b - - bm Rh6; id ""WAC.262""; d5+1.2";
const char wac263[] PROGMEM="rnbqr2k/pppp1Qpp/8/b2NN3/2B1n3/8/PPPP1PPP/R1B1K2R w KQ - bm Qg8+; id ""WAC.263""; d6+m4";
const char wac264[] PROGMEM="r2r2k1/1R2qp2/p5pp/2P5/b1PN1b2/P7/1Q3PPP/1B1R2K1 b - - bm Qe5 Rab8; id ""WAC.264""; Rab8 d5+2";
const char wac265[] PROGMEM="2r1k2r/2pn1pp1/1p3n1p/p3PP2/4q2B/P1P5/2Q1N1PP/R4RK1 w k - bm exf6; id ""WAC.265""; d10+2";
const char wac266[] PROGMEM="r3q2r/2p1k1p1/p5p1/1p2Nb2/1P2nB2/P7/2PNQbPP/R2R3K b - - bm Rxh2+; id ""WAC.266""; d5+m6";
const char wac267[] PROGMEM="2r1kb1r/pp3ppp/2n1b3/1q1N2B1/1P2Q3/8/P4PPP/3RK1NR w Kk - bm Nc7+; id ""WAC.267""; d5+m5";
const char wac268[] PROGMEM="2r3kr/ppp2n1p/7B/5q1N/1bp5/2Pp4/PP2RPPP/R2Q2K1 w - - bm Re8+; id ""WAC.268""; d5+11";
const char wac269[] PROGMEM="2kr2nr/pp1n1ppp/2p1p3/q7/1b1P1B2/P1N2Q1P/1PP1BPP1/R3K2R w KQ - bm axb4; id ""WAC.269""; d8+3";
const char wac270[] PROGMEM="2r1r1k1/pp1q1ppp/3p1b2/3P4/3Q4/5N2/PP2RPPP/4R1K1 w - - bm Qg4; id ""WAC.270""; d8+0.7";
const char wac271[] PROGMEM="2kr4/ppp3Pp/4RP1B/2r5/5P2/1P6/P2p4/3K4 w - - bm Rd6; id ""WAC.271""; d6+0";
const char wac272[] PROGMEM="nrq4r/2k1p3/1p1pPnp1/pRpP1p2/P1P2P2/2P1BB2/1R2Q1P1/6K1 w - - bm Bxc5; id ""WAC.272""; d5+2";
const char wac273[] PROGMEM="2k4B/bpp1qp2/p1b5/7p/1PN1n1p1/2Pr4/P5PP/R3QR1K b - - bm Ng3+ g3; id ""WAC.273""; Ng3+ d6+6";
const char wac274[] PROGMEM="8/1p6/p5R1/k7/Prpp4/K7/1NP5/8 w - - am Rd6; bm Rb6 Rg5+; id ""WAC.274""; Rb6 d6+2.5";
const char wac275[] PROGMEM="r1b2rk1/1p1n1ppp/p1p2q2/4p3/P1B1Pn2/1QN2N2/1P3PPP/3R1RK1 b - - bm Nc5 Nxg2 b5; id ""WAC.275""; b5 d5+1.3";
const char wac276[] PROGMEM="r5k1/pp1RR1pp/1b6/6r1/2p5/B6P/P4qPK/3Q4 w - - bm Qd5+; id ""WAC.276""; d5+9";
const char wac277[] PROGMEM="1r4r1/p2kb2p/bq2p3/3p1p2/5P2/2BB3Q/PP4PP/3RKR2 b - - bm Rg3 Rxg2; id ""WAC.277""; Rg3 d5+1.3";
const char wac278[] PROGMEM="r2qkb1r/pppb2pp/2np1n2/5pN1/2BQP3/2N5/PPP2PPP/R1B1K2R w KQkq - bm Bf7+; id ""WAC.278""; d5+m5";
const char wac279[] PROGMEM="r7/4b3/2p1r1k1/1p1pPp1q/1P1P1P1p/PR2NRpP/2Q3K1/8 w - - bm Nxf5 Rc3; id ""WAC.279""; d5+1.6";
const char wac280[] PROGMEM="r1r2bk1/5p1p/pn4p1/N2b4/3Pp3/B3P3/2q1BPPP/RQ3RK1 b - - bm Bxa3; id ""WAC.280""; d6+2";
const char wac281[] PROGMEM="2R5/2R4p/5p1k/6n1/8/1P2QPPq/r7/6K1 w - - bm Rxh7+; id ""WAC.281""; d5+6";
const char wac282[] PROGMEM="6k1/2p3p1/1p1p1nN1/1B1P4/4PK2/8/2r3b1/7R w - - bm Rh8+; id ""WAC.282""; d5+m4";
const char wac283[] PROGMEM="3q1rk1/4bp1p/1n2P2Q/3p1p2/6r1/Pp2R2N/1B4PP/7K w - - bm Ng5; id ""WAC.283""; d5+m4";
const char wac284[] PROGMEM="3r3k/pp4pp/8/1P6/3N4/Pn2P1qb/1B1Q2B1/2R3K1 w - - bm Nf5; id ""WAC.284""; d6+3.5";
const char wac285[] PROGMEM="2rr3k/1b2bppP/p2p1n2/R7/3P4/1qB2P2/1P4Q1/1K5R w - - bm Qxg7+; id ""WAC.285""; d5+m5";
const char wac286[] PROGMEM="3r1k2/1p6/p4P2/2pP2Qb/8/1P1KB3/P6r/8 b - - bm Rxd5+; id ""WAC.286""; d5+3";
const char wac287[] PROGMEM="rn3k1r/pp2bBpp/2p2n2/q5N1/3P4/1P6/P1P3PP/R1BQ1RK1 w - - bm Qg4 Qh5; id ""WAC.287""; Qh5 d5+4";
const char wac288[] PROGMEM="r1b2rk1/p4ppp/1p1Qp3/4P2N/1P6/8/P3qPPP/3R1RK1 w - - bm Nf6+; id ""WAC.288""; d5+3.5";
const char wac289[] PROGMEM="2r3k1/5p1p/p3q1p1/2n3P1/1p1QP2P/1P4N1/PK6/2R5 b - - bm Qe5; id ""WAC.289""; d5+3.5";
const char wac290[] PROGMEM="2k2r2/2p5/1pq5/p1p1n3/P1P2n1B/1R4Pp/2QR4/6K1 b - - bm Ne2+; id ""WAC.290""; d5+m4";
const char wac291[] PROGMEM="5r1k/3b2p1/p6p/1pRpR3/1P1P2q1/P4pP1/5QnP/1B4K1 w - - bm h3; id ""WAC.291""; d7+3";
const char wac292[] PROGMEM="4r3/1Q1qk2p/p4pp1/3Pb3/P7/6PP/5P2/4R1K1 w - - bm d6+; id ""WAC.292""; d5+2.5";
const char wac293[] PROGMEM="1nbq1r1k/3rbp1p/p1p1pp1Q/1p6/P1pPN3/5NP1/1P2PPBP/R4RK1 w - - bm Nfg5; id ""WAC.293""; d9+m4";
const 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";
const char wac295[] PROGMEM="4r3/p4r1p/R1p2pp1/1p1bk3/4pNPP/2P1K3/2P2P2/3R4 w - - bm Rxd5+; id ""WAC.295""; d5+m3";
const char wac296[] PROGMEM="3r4/1p2k2p/p1b1p1p1/4Q1Pn/2B3KP/4pP2/PP2R1N1/6q1 b - - bm Rd4+ Rf8; id ""WAC.296""; Rf8 d5+5 Rd4+ d9+9";
const char wac297[] PROGMEM="3r1rk1/p3qp1p/2bb2p1/2p5/3P4/1P6/PBQN1PPP/2R2RK1 b - - bm Bxg2 Bxh2+; id ""WAC.297""; Bxg2 d8+1.6";
const char wac298[] PROGMEM="3Q4/p3b1k1/2p2rPp/2q5/4B3/P2P4/7P/6RK w - - bm Qh8+; id ""WAC.298""; d6+m4";
const char wac299[] PROGMEM="1n2rr2/1pk3pp/pNn2p2/2N1p3/8/6P1/PP2PPKP/2RR4 w - - bm Nca4; id ""WAC.299""; d5+5";
const char wac300[] PROGMEM="b2b1r1k/3R1ppp/4qP2/4p1PQ/4P3/5B2/4N1K1/8 w - - bm g6; id ""WAC.300""; d5+2";

const char * const wacs[] PROGMEM = {   
  wac1,wac2,wac3,wac4,wac5,wac6,wac7,wac8,wac9,wac10,
  wac11,wac12,wac13,wac14,wac15,wac16,wac17,wac18,wac19,wac20,
  wac21,wac22,wac23,wac24,wac25,wac26,wac27,wac28,wac29,wac30,  
  wac31,wac32,wac33,wac34,wac35,wac36,wac37,wac38,wac39,wac40,
  wac41,wac42,wac43,wac44,wac45,wac46,wac47,wac48,wac49,wac50,
  wac51,wac52,wac53,wac54,wac55,wac56,wac57,wac58,wac59,wac60,
  wac61,wac62,wac63,wac64,wac65,wac66,wac67,wac68,wac69,wac70,
  wac71,wac72,wac73,wac74,wac75,wac76,wac77,wac78,wac79,wac80,
  wac81,wac82,wac83,wac84,wac85,wac86,wac87,wac88,wac89,wac90,
  wac91,wac92,wac93,wac94,wac95,wac96,wac97,wac98,wac99,wac100,
  wac101,wac102,wac103,wac104,wac105,wac106,wac107,wac108,wac109,wac110,
  wac111,wac112,wac113,wac114,wac115,wac116,wac117,wac118,wac119,wac120,
  wac121,wac122,wac123,wac124,wac125,wac126,wac127,wac128,wac129,wac130,  
  wac131,wac132,wac133,wac134,wac135,wac136,wac137,wac138,wac139,wac140,
  wac141,wac142,wac143,wac144,wac145,wac146,wac147,wac148,wac149,wac150,
  wac151,wac152,wac153,wac154,wac155,wac156,wac157,wac158,wac159,wac160,
  wac161,wac162,wac163,wac164,wac165,wac166,wac167,wac168,wac169,wac170,
  wac171,wac172,wac173,wac174,wac175,wac176,wac177,wac178,wac179,wac180,
  wac181,wac182,wac183,wac184,wac185,wac186,wac187,wac188,wac189,wac190,
  wac191,wac192,wac193,wac194,wac195,wac196,wac197,wac198,wac199,wac200,
  wac201,wac202,wac203,wac204,wac205,wac206,wac207,wac208,wac209,wac210,
  wac211,wac212,wac213,wac214,wac215,wac216,wac217,wac218,wac219,wac220,
  wac221,wac222,wac223,wac224,wac225,wac226,wac227,wac228,wac229,wac230,  
  wac231,wac232,wac233,wac234,wac235,wac236,wac237,wac238,wac239,wac240,
  wac241,wac242,wac243,wac244,wac245,wac246,wac247,wac248,wac249,wac250,
  wac251,wac252,wac253,wac254,wac255,wac256,wac257,wac258,wac259,wac260,
  wac261,wac262,wac263,wac264,wac265,wac266,wac267,wac268,wac269,wac270,
  wac271,wac272,wac273,wac274,wac275,wac276,wac277,wac278,wac279,wac280,
  wac281,wac282,wac283,wac284,wac285,wac286,wac287,wac288,wac289,wac290,
  wac291,wac292,wac293,wac294,wac295,wac296,wac297,wac298,wac299,wac300
 };

(I see vBulletin adds scrollbars to the code blocks, so I guess it's not so bad)
 
Try running Teensy 4.1 at 24 MHz, in case the problem is as "simple" as Teensy running too fast.

Just use Tools > CPU Speed and upload again for the slow speed to take effect.
 
Try running Teensy 4.1 at 24 MHz, in case the problem is as "simple" as Teensy running too fast.

Just use Tools > CPU Speed and upload again for the slow speed to take effect.

Well, today I learned how to set the Teensy speed. :) Thanks.

I was really hoping it wasn't a speed issue as one reason I went with Teensy 4.0 was the performance boost over the Mega, but sure enough, setting the speed for 24MHz didn't result in any change.
 
Data on the display from the eBay page:

Code:
Supports development boards such as Arduino Mega2560 for plug-in use without wiring
480X320 resolution, clear display, support for touch function
Support 16-bit RGB 65K color display, display rich colors
8-bit parallel bus, faster than serial SPI refresh
On-board 5V/3.3V level shifting IC, compatible with 5V/3.3V operating voltage
Easy to expand the experiment with SD card slot
Provides an Arduino library with a rich sample program
Military-grade process standards, long-term stable work
Provide underlying driver technical support
 
Product Parameters
Name Parameter
Display Color RGB 65K color
SKU MAR3501(have touch screen)/MAR3502(have no touch screen)
Screen Size 3.5(inch)
Type TFT
Driver IC ILI9486
Resolution 480*320 (Pixel)
Module Interface 8-bit parallel interface
Active Area 73.44*48.96(mm)
Module PCB Size 85.49*55.63(mm)
Operating Temperature -20℃~70℃
Storage Temperature -40℃~70℃
Operating Voltage 5V/3.3V
Power Consumption TBD
Product Weight(Package containing) 44g(have touch screen),55g(have no touch screen)
 
Interface Definition
Number Pin Label Pin Description
1 LCD_RST LCD bus reset signal, low level reset
2 LCD_CS LCD bus chip select signal, low level enable
3 LCD_RS LCD bus command / data selection signal,
low level: command, high level: data
4 LCD_WR LCD bus write signal
5 LCD_RD LCD bus read signal
6 GND Power ground
7 5V 5V power input
8 3V3 3.3V power input, this pin can be disconnected
9 LCD_D0 LCD 8-bit data Bit0
10 LCD_D1 LCD 8-bit data Bit1
11 LCD_D2 LCD 8-bit data Bit2
12 LCD_D3 LCD 8-bit data Bit3
13 LCD_D4 LCD 8-bit data Bit4
14 LCD_D5 LCD 8-bit data Bit5
15 LCD_D6 LCD 8-bit data Bit6
16 LCD_D7 LCD 8-bit data Bit7
17 SD_SS SD card SPI bus chip select signal, low level enable
18 SD_DI SD card SPI bus MOSI signal
19 SD_DO SD card SPI bus MISO signal
20 SD_SCK SD card SPI bus clock signal
 
It might be worth first just trying to write to the display.
There does not seem to much information about writing to the display with 8bit parallel interface.
Have a look at this.
 
Back
Top