-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
board.cpp
53 lines (40 loc) · 1.07 KB
/
board.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* board.cpp
*
* the MicroChess project: https://github.com/ripred/MicroChess
*
* implementation file for the board class
*
*/
#include <Arduino.h>
#include <stdint.h>
#include "MicroChess.h"
#include "board.h"
board_t::board_t() {
init();
} // board_t::board_t()
void board_t::clear() {
for (index_t i = 0; i < index_t(BOARD_SIZE); i++) {
board.set(i, Empty);
}
} // board_t::clear()
void board_t::init() {
clear();
uint8_t pieces[8] = { Rook, Knight, Bishop, Queen, King, Bishop, Knight, Rook };
for (index_t piece = 0; piece < 8; piece++) {
board.set(piece, pieces[piece]);
board.set(8 + piece, Pawn);
board.set(48 + piece, Pawn);
board.set(48 + piece, setSide(board.get(48 + piece), White));
board.set(56 + piece, pieces[piece]);
board.set(56 + piece, setSide(board.get(56 + piece), White));
}
} // board_t::init()
Piece board_t::get(unsigned char index) const
{
return board.get(index);
}
void board_t::set(unsigned char index, Piece const piece)
{
board.set(index, piece);
}