diff options
author | tomsmeding <tom.smeding@gmail.com> | 2018-03-12 00:20:50 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2018-03-12 00:20:50 +0100 |
commit | b26b8840e2cebec9ea8294d24ceb6663942005d4 (patch) | |
tree | 295d74c04bc9b6496e5a06a76234d87e876b3fe9 /board.h |
Initial
Diffstat (limited to 'board.h')
-rw-r--r-- | board.h | 67 |
1 files changed, 67 insertions, 0 deletions
@@ -0,0 +1,67 @@ +#pragma once + +#include <iostream> +#include <vector> +#include "move.h" + +using namespace std; + + +const int WHITE = 0; +const int BLACK = 1; + +const int EMPTY = 0, PAWN = 1, ROOK = 2, KNIGHT = 3, BISHOP = 4, KING = 5, QUEEN = 6; + +// WHITE WHITE WHITE y = 0 +// ... +// ... +// BLACK BLACK BLACK y = 7 + + +#define IDX(x_, y_) (8 * (y_) + (x_)) + + +class Board { + int bd[64]; // 0 = empty, >0 = white, <0 = black + +public: + int pieceScore[2]; // captured points by player + int lastTarget; // destination of last move + int onTurn; // colour of player to move + bool kingMoved[2], rookLmoved[2], rookRmoved[2]; + + Board(); + + template <typename F> // void(Board&) + inline Board newWith(const F &func) const { + Board B(*this); + func(B); + return B; + } + + inline int& at(int x, int y) {return at(IDX(x, y));} + inline int& at(int idx) {return bd[idx];} + inline int at(int x, int y) const {return at(IDX(x, y));} + inline int at(int idx) const {return bd[idx];} + + int locate(int stone) const; + + static inline int colour(int stone) {return stone > 0 ? WHITE : BLACK;} + + static inline int worth(int stone) { + static const int w[7] = {0, 1, 5, 3, 3, 100000000, 9}; + if (stone < -6 || stone > 6) __asm("int3\n\t"); + return w[abs(stone)]; + } + + vector<Board> subsequents() const; + + void apply(const Move &mv); // does not perform checking + + bool isValid(const Move &mv); + + friend bool operator==(const Board &B1, const Board &B2); +}; + +ostream& operator<<(ostream &os, const Board &B); +bool operator==(const Board &B1, const Board &B2); |