Belofte version 2.1.8
A promising chess program using the UCI or Winboard interface
case.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------+
2 * File: case.h
3 * Project: part of belofte - A Promising Chess Program
4 * Author: yves
5 * SPDX-License-Identifier: GPL-2.0-only
6+----------------------------------------------------------------------*/
7
8#if !defined(CASE_H)
9#define CASE_H
10
11//-----------------------------------------------------------------------
12
13/** position on board, defined as 255 if invalid
14 * used primarily to compose a move or a source or destination field
15 * does not contain the piece that occupies it
16 */
17class bCase final {
18public:
19 bCase();
20 explicit bCase(bCase&&) noexcept;
21 explicit bCase(case_t c);
22 explicit bCase(std::string const& s);
23 explicit bCase(column_t const c, rank_t const r);
24 ~bCase();
25
26 bCase(bCase const&) = delete;
27 bCase& operator=(bCase const&) = delete;
28 bCase& operator=(bCase&&) = delete;
29
30 bCase& operator=(std::string const& s);
31
32 operator std::string() const;
33 bool operator==(bCase const rhs) const;
34
35 column_t column0() const { return bCase::column0(m_case); }
36 rank_t rank0() const { return bCase::rank0(m_case); }
37 column_t column() const { return bCase::column(m_case); }
38 rank_t rank() const { return bCase::rank(m_case); }
39 case_t getCaseT() const;
40
41public:
42 static constexpr case_t coordToCase(column_t const c, rank_t const r) {
43 return static_cast<case_t>((r << 3) | c);
44 }
45 static constexpr column_t column0(case_t const c) {
46 return (c == 0xFF) ? -1 : (c & 0x07);
47 }
48 static constexpr rank_t rank0(case_t const c) {
49 return (c == 0xFF) ? -1 : ((c >> 3) & 0x07);
50 }
51 static constexpr column_t column(case_t const c) {
52 return c & 0x07;
53 }
54 static constexpr rank_t rank(case_t const c) {
55 return c >> 3;
56 }
57
58 static constexpr boardbitmap_t caseToBit(case_t const c) {
59 return 1ULL << c;
60 }
61
62private:
63 friend std::ostream& operator<<(std::ostream& os, bCase const& bc);
64
65private:
66 case_t m_case = 0xFF;
67};
68
69typedef std::vector<case_t> caselist_t;
70
71#endif // defined CASE_H
72
73// eof
int8_t rank_t
Definition belofte.h:104
int8_t column_t
Definition belofte.h:105
uint8_t case_t
Definition belofte.h:106
uint64_t boardbitmap_t
Definition belofte.h:111
std::vector< case_t > caselist_t
Definition case.h:69
position on board, defined as 255 if invalid used primarily to compose a move or a source or destinat...
Definition case.h:17
rank_t rank0() const
Definition case.h:36
static constexpr rank_t rank(case_t const c)
Definition case.h:54
case_t getCaseT() const
Definition case.cpp:53
static constexpr rank_t rank0(case_t const c)
Definition case.h:48
static constexpr column_t column0(case_t const c)
Definition case.h:45
bCase()
Definition case.cpp:13
bCase(bCase &&) noexcept
column_t column() const
Definition case.h:37
column_t column0() const
Definition case.h:35
friend std::ostream & operator<<(std::ostream &os, bCase const &bc)
Definition case.cpp:64
static constexpr case_t coordToCase(column_t const c, rank_t const r)
Definition case.h:42
static constexpr column_t column(case_t const c)
Definition case.h:51
static constexpr boardbitmap_t caseToBit(case_t const c)
Definition case.h:58
rank_t rank() const
Definition case.h:38