Belofte version 2.1.9
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 : m_case{c}
15{
16}
17
18bCase::bCase(column_t const c, rank_t const r)
19{
20 if (c != -1)
21 m_case = static_cast<case_t>(bCase::coordToCase(c, r));
22 else
23 m_case = 0xFF;
24}
25
26bCase::bCase(std::string const& cf)
27{
28 if (cf.size() > 1) {
29 m_case = bCase::coordToCase(cf[0] - 'a', cf[1] - '1');
30 }
31}
32
33bCase& bCase::operator=(std::string const& cf)
34{
35 if (cf.size() > 1) {
36 m_case = bCase::coordToCase(cf[0] - 'a', cf[1] - '1');
37 }
38 return *this;
39}
40
41bool bCase::operator==(bCase const rhs) const {
42 return m_case == rhs.m_case;
43}
44
45bCase::operator std::string() const
46{
47 if (m_case == 0xFF) return "-";
48 return std::string(1, column0() + 'a') + std::string(1, rank0() + '1');
49}
50
51std::ostream& operator<<(std::ostream& os, bCase const& cf)
52{
53 os << std::string(cf);
54 return os;
55}
56
57// eof
This is the main include file, needs to be included before any other include.
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::ostream & operator<<(std::ostream &os, bCase const &cf)
Definition case.cpp:51
bCase & operator=(bCase const &)=delete
bool operator==(bCase const rhs) const
Definition case.cpp:41
constexpr column_t column0() const
Definition case.h:37
bCase()
Definition case.h:20
static constexpr case_t coordToCase(column_t const c, rank_t const r)
Definition case.h:51
constexpr rank_t rank0() const
Definition case.h:39