Belofte version 2.1.9
A promising chess program using the UCI or Winboard interface
basicmove.cpp
Go to the documentation of this file.
1/*---------------------------------------------------------------------+
2 * File: basicmove.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
12bBasicMove::operator std::string() const
13{
14 return bCase(m_from).operator std::string()
15 + bCase(m_to).operator std::string()
16 + getPromotionDecorationStr();
17}
18
20{
22 return tPiece::W_QUEEN;
23 } else if (m_promotion == tPPiece::N_P_KNIGHT) {
24 return tPiece::W_KNIGHT;
25 } else if (m_promotion == tPPiece::N_P_ROOK) {
26 return tPiece::W_ROOK;
27 } else if (m_promotion == tPPiece::N_P_BISHOP) {
28 return tPiece::W_BISHOP;
29 }
30 throw std::logic_error("getWhitePromotionPiece called with tPiece::FIELD_EMPTY");
31}
32
34{
36 return tPiece::B_QUEEN;
37 } else if (m_promotion == tPPiece::N_P_KNIGHT) {
38 return tPiece::B_KNIGHT;
39 } else if (m_promotion == tPPiece::N_P_ROOK) {
40 return tPiece::B_ROOK;
41 } else if (m_promotion == tPPiece::N_P_BISHOP) {
42 return tPiece::B_BISHOP;
43 }
44 throw std::logic_error("getBlackPromotionPiece called with tPiece::FIELD_EMPTY");
45}
46
47std::string const bBasicMove::getPromotionDecorationStr() const
48{
49 if (!m_promotion) {
50 return "";
51 } else if (m_promotion == tPPiece::N_P_QUEEN) {
52 return "q";
53 } else if (m_promotion == tPPiece::N_P_KNIGHT) {
54 return "n";
55 } else if (m_promotion == tPPiece::N_P_ROOK) {
56 return "r";
57 } else {
58 return "b";
59 }
60}
61
62std::ostream& operator<<(std::ostream& os, bBasicMove const& m)
63{
64 os << m.operator std::string();
65 return os;
66}
67
68// eof
std::ostream & operator<<(std::ostream &os, bBasicMove const &m)
Definition basicmove.cpp:62
This is the main include file, needs to be included before any other include.
ppiece_t m_promotion
Definition basicmove.h:162
piece_t getWhitePromotionPiece() const
Definition basicmove.cpp:19
piece_t getBlackPromotionPiece() const
Definition basicmove.cpp:33
case_t m_to
Definition basicmove.h:146
case_t m_from
Definition basicmove.h:145
position on board, defined as 255 if invalid used primarily to compose a move or a source or destinat...
Definition case.h:18
@ W_KNIGHT
Definition piece.h:39
@ B_BISHOP
Definition piece.h:40
@ W_ROOK
Definition piece.h:39
@ B_ROOK
Definition piece.h:40
@ W_QUEEN
Definition piece.h:39
@ B_KNIGHT
Definition piece.h:40
@ B_QUEEN
Definition piece.h:40
@ W_BISHOP
Definition piece.h:39
enum tPiece piece_t
Definition piece.h:44
@ N_P_KNIGHT
Definition piece.h:48
@ N_P_QUEEN
Definition piece.h:48
@ N_P_ROOK
Definition piece.h:48
@ N_P_BISHOP
Definition piece.h:48