Implement a lot of stuff

This commit is contained in:
Quinten Kock 2020-06-15 22:49:14 +02:00
parent fa18fa6a98
commit ce74c6c4f9
4 changed files with 68 additions and 17 deletions

View File

@ -6,7 +6,15 @@ Board b = Board();
void setup() {
// put your setup code here, to run once:
Serial.begin(19200);
Serial.begin(9600);
char value;
while(Serial.available() == 0) {
delay(100);
}
value = Serial.read();
b.field[0x32] = char_to_piece(value);
}
void loop() {
@ -15,4 +23,5 @@ void loop() {
delay(1000);
Serial.println(b.get_zobrist());
b.print();
Serial.println(sizeof(b));
}

View File

@ -15,8 +15,8 @@ class Board {
Board();
void print() {
for(int i = 7; i >= 0; i--) {
for(int j = 0; j < 16; j++) {
for(char i = 7; i >= 0; i--) {
for(byte j = 0; j < 16; j++) {
Serial.print(field[i*16 + j], HEX);
Serial.print(" ");
}
@ -29,7 +29,6 @@ class Board {
return *addr;
}
private:
byte field[128] = {
W_ROOK, W_KNGT, W_BSHP, W_QUEN, W_KING, W_BSHP, W_KNGT, W_ROOK, 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,
@ -40,6 +39,7 @@ class Board {
B_PAWN, B_PAWN, B_PAWN, B_PAWN, B_PAWN, B_PAWN, B_PAWN, B_PAWN, 0, 0, 0, 0, 0, 0, 0, 0,
B_ROOK, B_KNGT, B_BSHP, B_QUEN, B_KING, B_BSHP, B_KNGT, B_ROOK, 0, 0, 0, 0, 0, 0, 0, 0,
};
private:
const byte PTR_SIDE_AND_CASTLERIGHT = 0x08; //byte (1=side, 2,4=white castle, 8,16=black)
const byte PTR_PTR_UNMAKE = 0x09; //byte (points to index)
@ -90,7 +90,7 @@ class Board {
Unmake read_unmake() {
Unmake u;
byte* ptr = (byte*) &u;
for(size_t i = sizeof(u) - 1; i >= 0; i++) {
for(int i = sizeof(u) - 1; i >= 0; i++) {
ptr[i] = field[prev_unmake()];
}
return u;

3
Move.h
View File

@ -9,4 +9,7 @@ struct Move {
Piece pc_prom;
};
//Move move_from_str(char* s) {
//}
#endif

63
Types.h
View File

@ -2,19 +2,58 @@
#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,
P_EMPTY = 0b0000,
P_ANY = 0b1000,
B_PAWN = 0b1000,
B_KNGT = 0b1001,
B_BSHP = 0b1010,
B_ROOK = 0b1100,
B_QUEN = 0b1110,
B_KING = 0b1111,
W_PAWN = 0b0001,
W_KNGT = 0b0010,
W_KING = 0b0011,
W_BSHP = 0b0101,
W_ROOK = 0b0110,
W_QUEN = 0b0111,
B_PAWN = 0b1001,
B_KNGT = 0b1010,
B_KING = 0b1011,
B_BSHP = 0b1101,
B_ROOK = 0b1110,
B_QUEN = 0b1111,
};
#ifdef _ACF_FAST_PIECE
Piece char_to_piece(char c) {
switch(c) {
case 'p': return W_PAWN;
case 'n': return W_KNGT;
case 'k': return W_KING;
case 'b': return W_BSHP;
case 'r': return W_ROOK;
case 'q': return W_QUEN;
case 'P': return B_PAWN;
case 'N': return B_KNGT;
case 'K': return B_KING;
case 'B': return B_BSHP;
case 'R': return B_ROOK;
case 'Q': return B_QUEN;
default: return P_EMPTY;
}
}
#else // _ACF_FAST_PIECE
const char CHAR_STRS[] PROGMEM = " pnkbrq PNKBRQ";
Piece char_to_piece(char c) {
for(byte i = 0; i < 0b1111; i++) {
if(pgm_read_byte_near(CHAR_STRS + i) == c)
return (Piece)i;
}
return P_EMPTY;
}
char piece_to_char(Piece p) {
return CHAR_STRS[p];
}
#endif // _ACF_FAST_PIECE
#endif