diff --git a/ArduChess.ino b/ArduChess.ino index 766d39f..9841703 100644 --- a/ArduChess.ino +++ b/ArduChess.ino @@ -9,28 +9,30 @@ #include "Movegen.h" #include "Types.h" -unsigned int pseudo_perft(byte depth) { +unsigned long pseudo_perft(byte depth) { // only checks pseudolegality // but, it should work overall if(depth == 0) return 1; - Serial.print(F("Start a PERFT ")); - Serial.print(depth); - Serial.println('-'); - print(); - unsigned int move_count = 0; + if(depth == 3) blink(); + unsigned long move_count = 0; Movegen gen; Move m; - do { + + while (true) { m = gen.next_move(); - //make(m); - move_count += pseudo_perft(depth-1); - //unmake(); - } while (m.sq_from != 255); - return move_count - 1; + if(m.sq_to != 255) { + make(m); + move_count += pseudo_perft(depth-1); + unmake(); + } else { + break; + } + } + return move_count; } void perft_test() { - for(byte i = 0; i < 2; i++) { + for(byte i = 0; i < 5; i++) { Serial.print(F("Perft ")); Serial.print(i); Serial.print(F(": ")); @@ -39,6 +41,7 @@ void perft_test() { } void debug_movegen() { + make({0x14, 0x34, P_EMPTY}); Movegen gen = Movegen(); Move m; do { @@ -104,7 +107,7 @@ void debug_ep() { } void bench() { - int startTime = micros(); + unsigned long startTime = micros(); make({0x14, 0x34, P_EMPTY}); make({0x64, 0x54, P_EMPTY}); @@ -133,9 +136,38 @@ void bench() { unmake(); - int elapsed = micros() - startTime; + unsigned long elapsed = micros() - startTime; Serial.print(elapsed); - Serial.println(F(" microseconds")); + Serial.println(F(" microseconds for make/unmake")); + + for(int i = 1; i <= 4; i++) { + startTime = millis(); + pseudo_perft(i); + elapsed = millis() - startTime; + Serial.print(elapsed); + Serial.print(F(" milliseconds for pseudo_perft(")); + Serial.print(i); + Serial.println(')'); + } + + Movegen gen; + Move move[20]; + startTime = micros(); + for(int i = 0; i < 20; i++) { + move[i] = gen.next_move(); + } + elapsed = micros() - startTime; + Serial.print(elapsed); + Serial.println(F(" microseconds for movegen(init_pos)")); + + startTime = micros(); + for(int i = 0; i < 20; i++) { + make(move[i]); + unmake(); + } + elapsed = micros() - startTime; + Serial.print(elapsed); + Serial.println(F(" microseconds for make/unmake(init_pos)")); } @@ -143,6 +175,8 @@ void setup() { // put your setup code here, to run once: board_init(); Serial.begin(115200); + pinMode(LED_BUILTIN, OUTPUT); + perft_test(); bench(); } diff --git a/Config.h b/Config.h index 82a9435..e570758 100644 --- a/Config.h +++ b/Config.h @@ -7,3 +7,5 @@ //#define _ACF_PANIC_BLINK #define _ACF_DEBUG_PRINT + +#define _ACF_ACTIVITY_BLINK \ No newline at end of file diff --git a/Panic.h b/Panic.h index b3dd59c..931e490 100644 --- a/Panic.h +++ b/Panic.h @@ -4,9 +4,23 @@ #pragma GCC push_options #pragma GCC optimize("-Os") +#ifdef _ACF_ACTIVITY_BLINK +bool ledhi; +void blink() { + ledhi = !ledhi; + if(ledhi) { + digitalWrite(LED_BUILTIN, HIGH); + } else { + digitalWrite(LED_BUILTIN, LOW); + } +} +#else +void blink() {} +#endif + + #ifdef _ACF_PANIC_BLINK void sos() { - pinMode(LED_BUILTIN, OUTPUT); while(true) { digitalWrite(LED_BUILTIN, HIGH); delay(500);