CastleFlags.cc
Go to the documentation of this file.
1 // cwchessboard -- A C++ chessboard tool set
2 //
3 //! @file CastleFlags.cc This file contains the implementation of class CastleFlags.
4 //
5 // Copyright (C) 2008, by
6 //
7 // Carlo Wood, Run on IRC <carlo@alinoe.com>
8 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt
9 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61
10 //
11 // This program is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 2 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 
24 #ifndef USE_PCH
25 #include "sys.h"
26 #include "debug.h"
27 #endif
28 
29 #include "CastleFlags.h"
30 
31 namespace cwchess {
32 
33 void CastleFlags::piece_moved_from(Piece const& piece, Index const& from)
34 {
35  switch (piece.code()())
36  {
37  case (black_bits|rook_bits):
38  if (from == ia8)
39  M_bits |= black_rook_queen_side_moved;
40  else if (from == ih8)
41  M_bits |= black_rook_king_side_moved;
42  break;
43  case (black_bits|king_bits):
44  M_bits |= black_king_moved;
45  break;
46  case (white_bits|rook_bits):
47  if (from == ia1)
48  M_bits |= white_rook_queen_side_moved;
49  else if (from == ih1)
50  M_bits |= white_rook_king_side_moved;
51  break;
52  case (white_bits|king_bits):
53  M_bits |= white_king_moved;
54  break;
55  default:
56  return;
57  }
58 }
59 
60 bool CastleFlags::has_moved(Code const& code, Index const& index)
61 {
62  if (index == ia1 && code == white_rook)
63  return M_bits & white_rook_queen_side_moved;
64  else if (index == ie1 && code == white_king)
65  return M_bits & white_king_moved;
66  else if (index == ih1 && code == white_rook)
67  return M_bits & white_rook_king_side_moved;
68  else if (index == ia8 && code == black_rook)
69  return M_bits & black_rook_queen_side_moved;
70  else if (index == ie8 && code == black_king)
71  return M_bits & black_king_moved;
72  else if (index == ih8 && code == black_rook)
73  return M_bits & black_rook_king_side_moved;
74  // We should normally never get here. Return some random value.
75  return false;
76 }
77 
78 } // namespace cwchess
A namespace for all chess related objects that are not related to the GUI.
Definition: Array.h:39
IndexData const ia1
A constant representing the index to square a1.
Definition: Index.h:53
IndexData const ih1
A constant representing the index to square h1.
Definition: Index.h:67
This file contains the declaration of class CastleFlags.
bool has_moved(Code const& code, Index const& index)
Return TRUE if code at index is marked as having moved.
Definition: CastleFlags.cc:60
IndexData const ih8
A constant representing the index to square h8.
Definition: Index.h:179
IndexData const ia8
A constant representing the index to square a8.
Definition: Index.h:165
CodeData const black_rook
A constant representing a black rook;.
Definition: Code.h:68
The index of a chess square.
Definition: Index.h:211
CodeData const white_rook
A constant representing a white rook.
Definition: Code.h:56
uint8_t const white_bits
The underlaying integral value of color& #39;white&#39;.
Definition: Color.h:49
uint8_t const king_bits
The underlaying integral value of type& #39;king&#39;.
Definition: Type.h:56
A chess piece type including color.
Definition: Code.h:92
uint8_t const black_bits
The underlaying integral value of color& #39;black&#39;.
Definition: Color.h:48
CodeData const black_king
A constant representing a black king;.
Definition: Code.h:76
CodeData const white_king
A constant representing a white king.
Definition: Code.h:64
IndexData const ie8
A constant representing the index to square e8.
Definition: Index.h:173
IndexData const ie1
A constant representing the index to square e1.
Definition: Index.h:61
uint8_t const rook_bits
The underlaying integral value of type& #39;rook&#39;.
Definition: Type.h:58

Copyright © 2006 - 2010 Carlo Wood.  All rights reserved.