#pragma GCC optimize ("-O3") #include #include "Config.h" #include "Board.h" #include "Move.h" #include "Movegen.h" #include "Types.h" unsigned long pseudo_perft(byte depth) { // only checks pseudolegality // but, it should work overall if(depth == 0) return 1; if(depth == 3) blink(); unsigned long move_count = 0; Movegen gen; Move m; while (true) { m = gen.next_move(); 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 < 5; i++) { Serial.print(F("Perft ")); Serial.print(i); Serial.print(F(": ")); Serial.println(pseudo_perft(i)); } } void debug_movegen() { make({0x14, 0x34, P_EMPTY}); Movegen gen = Movegen(); Move m; do { DEBUG("start movegen"); m = gen.next_move(); Serial.print(F("FROM ")); Serial.print(m.sq_from, HEX); Serial.print(F(" TO ")); Serial.print(m.sq_to, HEX); Serial.print(F(" PROMOTE ")); Serial.println(m.pc_prom); if(m.sq_from != 255) { DEBUG("make"); make(m); print(); DEBUG("unmake"); unmake(); DEBUG("unmake done"); } } while (m.sq_from != 255); } void debug_castle() { print(); make({0x06, 0x25, P_EMPTY}); print(); make({0x76, 0x55, P_EMPTY}); print(); make({0x16, 0x26, P_EMPTY}); print(); make({0x63, 0x43, P_EMPTY}); print(); make({0x05, 0x16, P_EMPTY}); print(); make({0x62, 0x42, P_EMPTY}); print(); make({0x04, 0x06, P_EMPTY}); print(); unmake(); print(); unmake(); print(); unmake(); print(); unmake(); print(); unmake(); print(); unmake(); print(); unmake(); print(); } void debug_ep() { print(); make({0x14, 0x34, P_EMPTY}); print(); make({0x64, 0x54, P_EMPTY}); print(); make({0x34, 0x44, P_EMPTY}); print(); make({0x63, 0x43, P_EMPTY}); print(); make({0x44, 0x53, P_EMPTY}); print(); unmake(); print(); unmake(); print(); unmake(); print(); unmake(); print(); unmake(); print(); } void bench() { unsigned long startTime = micros(); make({0x14, 0x34, P_EMPTY}); make({0x64, 0x54, P_EMPTY}); make({0x34, 0x44, P_EMPTY}); make({0x63, 0x43, P_EMPTY}); make({0x44, 0x53, P_EMPTY}); unmake(); unmake(); unmake(); unmake(); unmake(); make({0x06, 0x25, P_EMPTY}); make({0x76, 0x55, P_EMPTY}); make({0x16, 0x26, P_EMPTY}); make({0x63, 0x43, P_EMPTY}); make({0x05, 0x16, P_EMPTY}); make({0x62, 0x42, P_EMPTY}); make({0x04, 0x06, P_EMPTY}); unmake(); unmake(); unmake(); unmake(); unmake(); unmake(); unmake(); unsigned long elapsed = micros() - startTime; Serial.print(elapsed); 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)")); } void setup() { // put your setup code here, to run once: board_init(); Serial.begin(115200); pinMode(LED_BUILTIN, OUTPUT); perft_test(); bench(); } void loop() { // put your main code here, to run repeatedly: }