Belofte version 2.1.8
A promising chess program using the UCI or Winboard interface
case.cpp
Go to the documentation of this file.
1/*---------------------------------------------------------------------+
2 * File: case.cpp
3 * Project: part of belofte - A Promising Chess Program
4 * Author: yves
5 * SPDX-License-Identifier: GPL-2.0-only
6+----------------------------------------------------------------------*/
7
8#include "belofte.h"
9
10//-----------------------------------------------------------------------
11// bCase class
12
14{
15}
16
18{
19 m_case = c;
20}
21
22bCase::bCase(column_t const c, rank_t const r)
23{
24 if (c != -1)
25 m_case = static_cast<case_t>(bCase::coordToCase(c, r));
26 else
27 m_case = 0xFF;
28}
29
30bCase::bCase(std::string const& bc)
31{
32 if (bc.size() > 1) {
33 m_case = bCase::coordToCase(bc[0] - 'a', bc[1] - '1');
34 }
35}
36
38{
39}
40
41bCase& bCase::operator=(std::string const& bc)
42{
43 if (bc.size() > 1) {
44 m_case = bCase::coordToCase(bc[0] - 'a', bc[1] - '1');
45 }
46 return *this;
47}
48
49bool bCase::operator==(bCase const rhs) const {
50 return m_case == rhs.m_case;
51}
52
54{
55 return m_case;
56}
57
58bCase::operator std::string() const
59{
60 if (m_case == 0xFF) return "-";
61 return std::string(1, column0() + 'a') + std::string(1, rank0() + '1');
62}
63
64std::ostream& operator<<(std::ostream& os, bCase const& bc)
65{
66 os << std::string(bc);
67 return os;
68}
69
70// eof
This is the main include file, needs to be included before any other include.
int8_t rank_t
Definition belofte.h:104
int8_t column_t
Definition belofte.h:105
uint8_t case_t
Definition belofte.h:106
std::ostream & operator<<(std::ostream &os, bCase const &bc)
Definition case.cpp:64
position on board, defined as 255 if invalid used primarily to compose a move or a source or destinat...
Definition case.h:17
bCase & operator=(bCase const &)=delete
bool operator==(bCase const rhs) const
Definition case.cpp:49
case_t getCaseT() const
Definition case.cpp:53
bCase()
Definition case.cpp:13
static constexpr case_t coordToCase(column_t const c, rank_t const r)
Definition case.h:42
~bCase()
Definition case.cpp:37