Fix perft, extend benchmark

This commit is contained in:
Quinten Kock 2020-06-19 03:05:11 +02:00
parent cc5562c533
commit c54e2b9e1a
3 changed files with 67 additions and 17 deletions

View File

@ -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();
}

View File

@ -7,3 +7,5 @@
//#define _ACF_PANIC_BLINK
#define _ACF_DEBUG_PRINT
#define _ACF_ACTIVITY_BLINK

16
Panic.h
View File

@ -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);