Belofte version 2.1.9
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/**
14 * position on board, defined as 255 if invalid
15 * used primarily to compose a move or a source or destination field
16 * does not contain the piece that occupies it
17 */
18class bCase {
19public:
20 explicit bCase()
21 {}
22 explicit bCase(bCase&& cf);
23 explicit bCase(case_t cf);
24 explicit bCase(std::string const& s);
25 explicit bCase(column_t const c, rank_t const r);
27 {}
28
29 bCase(bCase const&) = delete;
30 bCase& operator=(bCase const&) = delete;
31 bCase& operator=(bCase&&) = delete;
32
33 bCase& operator=(std::string const& s);
34
35 bool operator==(bCase const rhs) const;
36
37 constexpr column_t column0() const
38 { return bCase::column0(m_case); }
39 constexpr rank_t rank0() const
40 { return bCase::rank0(m_case); }
41 constexpr column_t column() const
42 { return bCase::column(m_case); }
43 constexpr rank_t rank() const
44 { return bCase::rank(m_case); }
45 constexpr case_t getCaseT() const
46 { return m_case; }
47
48 operator std::string() const;
49
50public:
51 static constexpr case_t coordToCase(column_t const c, rank_t const r) {
52 return static_cast<case_t>((r << 3) | c);
53 }
54 static constexpr column_t column0(case_t const cf) {
55 return (cf == 0xFF) ? -1 : (cf & 0x07);
56 }
57 static constexpr rank_t rank0(case_t const cf) {
58 return (cf == 0xFF) ? -1 : ((cf >> 3) & 0x07);
59 }
60 static constexpr column_t column(case_t const cf) {
61 return cf & 0x07;
62 }
63 static constexpr rank_t rank(case_t const cf) {
64 return cf >> 3;
65 }
66 static constexpr boardbitmap_t caseToBit(case_t const cf) {
67 return 1ULL << cf;
68 }
69
70private:
71 friend std::ostream& operator<<(std::ostream& os, bCase const& cf);
72
73private:
74 case_t m_case = 0xFF;
75};
76
77typedef std::vector<case_t> caselist_t;
78
79#endif // defined CASE_H
80
81// eof
std::bitset< 64 > boardbitmap_t
Definition belofte.h:102
int8_t rank_t
Definition belofte.h:94
int8_t column_t
Definition belofte.h:95
uint8_t case_t
Definition belofte.h:96
std::vector< case_t > caselist_t
Definition case.h:77
position on board, defined as 255 if invalid used primarily to compose a move or a source or destinat...
Definition case.h:18
bCase & operator=(bCase const &)=delete
constexpr rank_t rank() const
Definition case.h:43
bCase(bCase &&cf)
bool operator==(bCase const rhs) const
Definition case.cpp:41
constexpr column_t column0() const
Definition case.h:37
static constexpr rank_t rank0(case_t const cf)
Definition case.h:57
static constexpr boardbitmap_t caseToBit(case_t const cf)
Definition case.h:66
bCase(bCase const &)=delete
bCase()
Definition case.h:20
constexpr column_t column() const
Definition case.h:41
static constexpr column_t column(case_t const cf)
Definition case.h:60
static constexpr column_t column0(case_t const cf)
Definition case.h:54
constexpr case_t getCaseT() const
Definition case.h:45
static constexpr case_t coordToCase(column_t const c, rank_t const r)
Definition case.h:51
static constexpr rank_t rank(case_t const cf)
Definition case.h:63
friend std::ostream & operator<<(std::ostream &os, bCase const &cf)
Definition case.cpp:51
constexpr rank_t rank0() const
Definition case.h:39
~bCase()
Definition case.h:26
bCase & operator=(bCase &&)=delete