libscid 0.1.0
Chess applications made easy.
Loading...
Searching...
No Matches
square_collections.h
Go to the documentation of this file.
1
5#pragma once
6
7#include "scid/core/board.h"
8
9#include <cassert>
10
11namespace scid::core {
12
13constexpr uint MAX_SQUARELIST = 65; // 64 squares plus null square
14
16 uint ListSize;
17 squareT Squares[MAX_SQUARELIST];
18
19public:
20 SquareList() { ListSize = 0; }
21
22 void Init() { ListSize = 0; }
23 void Clear() { ListSize = 0; }
24 void Add(squareT sq) {
25 Squares[ListSize] = sq;
26 ListSize++;
27 }
28 uint Size() { return ListSize; }
29
30 squareT Get(uint index) {
31 assert(index < ListSize);
32 return Squares[index];
33 }
34
35 bool Contains(squareT sq) {
36 for (uint i = 0; i < ListSize; i++) {
37 if (Squares[i] == sq) {
38 return true;
39 }
40 }
41 return false;
42 }
43
44 void Remove(uint index) {
45 assert(index < ListSize);
46 ListSize--;
47 if (index != ListSize) {
48 Squares[index] = Squares[ListSize];
49 }
50 }
51};
52
53class SquareSet {
54 unsigned long long bits_ = 0;
55
56public:
57 void Add(squareT sq) {
58 assert(sq < 64);
59 bits_ |= 1ull << sq;
60 }
61
62 bool Contains(squareT sq) {
63 assert(sq < 64);
64 return (bits_ & (1ull << sq)) != 0;
65 }
66};
67
68} // namespace scid::core
Chess board constants, piece helpers, square geometry, and directions.
Definition square_collections.h:15
Definition square_collections.h:53