Fix perft, extend benchmark
This commit is contained in:
parent
cc5562c533
commit
c54e2b9e1a
|
|
@ -9,28 +9,30 @@
|
||||||
#include "Movegen.h"
|
#include "Movegen.h"
|
||||||
#include "Types.h"
|
#include "Types.h"
|
||||||
|
|
||||||
unsigned int pseudo_perft(byte depth) {
|
unsigned long pseudo_perft(byte depth) {
|
||||||
// only checks pseudolegality
|
// only checks pseudolegality
|
||||||
// but, it should work overall
|
// but, it should work overall
|
||||||
if(depth == 0) return 1;
|
if(depth == 0) return 1;
|
||||||
Serial.print(F("Start a PERFT "));
|
if(depth == 3) blink();
|
||||||
Serial.print(depth);
|
unsigned long move_count = 0;
|
||||||
Serial.println('-');
|
|
||||||
print();
|
|
||||||
unsigned int move_count = 0;
|
|
||||||
Movegen gen;
|
Movegen gen;
|
||||||
Move m;
|
Move m;
|
||||||
do {
|
|
||||||
|
while (true) {
|
||||||
m = gen.next_move();
|
m = gen.next_move();
|
||||||
//make(m);
|
if(m.sq_to != 255) {
|
||||||
move_count += pseudo_perft(depth-1);
|
make(m);
|
||||||
//unmake();
|
move_count += pseudo_perft(depth-1);
|
||||||
} while (m.sq_from != 255);
|
unmake();
|
||||||
return move_count - 1;
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return move_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void perft_test() {
|
void perft_test() {
|
||||||
for(byte i = 0; i < 2; i++) {
|
for(byte i = 0; i < 5; i++) {
|
||||||
Serial.print(F("Perft "));
|
Serial.print(F("Perft "));
|
||||||
Serial.print(i);
|
Serial.print(i);
|
||||||
Serial.print(F(": "));
|
Serial.print(F(": "));
|
||||||
|
|
@ -39,6 +41,7 @@ void perft_test() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void debug_movegen() {
|
void debug_movegen() {
|
||||||
|
make({0x14, 0x34, P_EMPTY});
|
||||||
Movegen gen = Movegen();
|
Movegen gen = Movegen();
|
||||||
Move m;
|
Move m;
|
||||||
do {
|
do {
|
||||||
|
|
@ -104,7 +107,7 @@ void debug_ep() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void bench() {
|
void bench() {
|
||||||
int startTime = micros();
|
unsigned long startTime = micros();
|
||||||
|
|
||||||
make({0x14, 0x34, P_EMPTY});
|
make({0x14, 0x34, P_EMPTY});
|
||||||
make({0x64, 0x54, P_EMPTY});
|
make({0x64, 0x54, P_EMPTY});
|
||||||
|
|
@ -133,9 +136,38 @@ void bench() {
|
||||||
unmake();
|
unmake();
|
||||||
|
|
||||||
|
|
||||||
int elapsed = micros() - startTime;
|
unsigned long elapsed = micros() - startTime;
|
||||||
Serial.print(elapsed);
|
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:
|
// put your setup code here, to run once:
|
||||||
board_init();
|
board_init();
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
|
perft_test();
|
||||||
bench();
|
bench();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
2
Config.h
2
Config.h
|
|
@ -7,3 +7,5 @@
|
||||||
//#define _ACF_PANIC_BLINK
|
//#define _ACF_PANIC_BLINK
|
||||||
|
|
||||||
#define _ACF_DEBUG_PRINT
|
#define _ACF_DEBUG_PRINT
|
||||||
|
|
||||||
|
#define _ACF_ACTIVITY_BLINK
|
||||||
16
Panic.h
16
Panic.h
|
|
@ -4,9 +4,23 @@
|
||||||
#pragma GCC push_options
|
#pragma GCC push_options
|
||||||
#pragma GCC optimize("-Os")
|
#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
|
#ifdef _ACF_PANIC_BLINK
|
||||||
void sos() {
|
void sos() {
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
|
||||||
while(true) {
|
while(true) {
|
||||||
digitalWrite(LED_BUILTIN, HIGH);
|
digitalWrite(LED_BUILTIN, HIGH);
|
||||||
delay(500);
|
delay(500);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue