From 72424baa474d71bcd124da3fc927e930ec08ebb0 Mon Sep 17 00:00:00 2001 From: Quinten Kock Date: Mon, 15 Jun 2020 05:37:19 +0200 Subject: [PATCH] Initial commit --- Arduchess.ino | 17 +++++++++++ Board.h | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ Move.h | 12 ++++++++ Types.h | 20 +++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 Arduchess.ino create mode 100644 Board.h create mode 100644 Move.h create mode 100644 Types.h diff --git a/Arduchess.ino b/Arduchess.ino new file mode 100644 index 0000000..91530d1 --- /dev/null +++ b/Arduchess.ino @@ -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()); +} diff --git a/Board.h b/Board.h new file mode 100644 index 0000000..05e9be1 --- /dev/null +++ b/Board.h @@ -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 diff --git a/Move.h b/Move.h new file mode 100644 index 0000000..b2cf99e --- /dev/null +++ b/Move.h @@ -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 diff --git a/Types.h b/Types.h new file mode 100644 index 0000000..cedd81f --- /dev/null +++ b/Types.h @@ -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