Initial commit

This commit is contained in:
Quinten Kock 2020-06-15 05:37:19 +02:00
commit 72424baa47
4 changed files with 128 additions and 0 deletions

17
Arduchess.ino Normal file
View File

@ -0,0 +1,17 @@
#include "Board.h"
#include "Move.h"
#include "Types.h"
Board b = Board();
void setup() {
// put your setup code here, to run once:
Serial.begin(19200);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(F("hello"));
delay(1000);
Serial.println(b.get_zobrist());
}

79
Board.h Normal file
View File

@ -0,0 +1,79 @@
#ifndef __BOARD_H_INC
#define __BOARD_H_INC
#include "Types.h"
class Board {
public:
Board();
unsigned long get_zobrist() {
long* addr = (long*) &field[PTR_ZOBRIST];
return *addr;
}
private:
byte field[128] = {
B_ROOK, B_KNGT, B_BSHP, B_QUEN, B_KING, B_BSHP, B_KNGT, B_ROOK, 0, 0, 0, 0, 0, 0, 0, 0,
B_PAWN, B_PAWN, B_PAWN, B_PAWN, B_PAWN, B_PAWN, B_PAWN, B_PAWN, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0,
W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN, W_PAWN, 0, 0, 0, 0, 0, 0, 0, 0,
W_ROOK, W_KNGT, W_BSHP, W_QUEN, W_KING, W_BSHP, W_KNGT, W_ROOK, 0, 0, 0, 0, 0, 0, 0, 0,
};
const byte PTR_SIDE_AND_CASTLERIGHT = 0x08; //byte (1=side, 2,4=white castle, 8,16=black)
const byte PTR_PTR_REVMOV = 0x09; //byte (points to index)
const byte PTR_W_KING = 0x0A; // byte (points to index or maybe 64-arr index)
// const byte PTR_B_KING = 0x0B; (PTR_W_KING | COLOR or PTR_W_KING + COLOR)
const byte PTR_ZOBRIST = 0x0C; // 4 bytes
// 0x0D
// 0x0E
// 0x0F
const byte PTR_ENPASSANT = 0x18;
const byte UNMAKE_START = 0x1A;
inline byte get_unmake() __attribute__((always_inline)) {
return field[PTR_PTR_REVMOV];
}
byte next_unmake() {
field[PTR_PTR_REVMOV]++;
if(get_unmake() >= 0x80) {
field[PTR_PTR_REVMOV] = UNMAKE_START;
return UNMAKE_START;
}
while(get_unmake() & 0x88) {
field[PTR_PTR_REVMOV]++;
}
return get_unmake();
}
byte prev_unmake() {
field[PTR_PTR_REVMOV]--;
if(get_unmake() < UNMAKE_START) {
field[PTR_PTR_REVMOV] = 0x7F;
return 0x7F;
}
while(get_unmake() & 0x88) {
field[PTR_PTR_REVMOV]--;
}
return get_unmake();
}
};
Board::Board() {
// Then, other data we need to store is assigned 0-fields.
field[PTR_ZOBRIST+1] = 1;
}
struct unmake {
byte sq_from;
byte sq_to;
byte enpassant;
#endif

12
Move.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef __MOVE_H_INC
#define __MOVE_H_INC
#include "Types.h"
struct Move {
byte sq_from;
byte sq_to;
Piece pc_prom;
};
#endif

20
Types.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef __TYPES_H_INC
#define __TYPES_H_INC
enum Piece: byte {
W_PAWN = 0b0000,
W_KNGT = 0b0001,
W_BSHP = 0b0010,
W_ROOK = 0b0100,
W_QUEN = 0b0110,
W_KING = 0b0111,
B_PAWN = 0b1000,
B_KNGT = 0b1001,
B_BSHP = 0b1010,
B_ROOK = 0b1100,
B_QUEN = 0b1110,
B_KING = 0b1111,
};
#endif