MoveIterator.cc
Go to the documentation of this file.
1 // cwchessboard -- A C++ chessboard tool set
2 //
3 //! @file MoveIterator.cc This file contains the implementation of class MoveIterator.
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 #endif
27 
28 #include "MoveIterator.h"
29 
30 namespace cwchess {
31 
32 bool MoveIterator::next_promotion(void)
33 {
34  Type type = rook;
35  Type promotion_type = M_current_move.promotion_type();
36  // The piece is a queen when we get here first.
37  // Order: queen -> rook -> knight -> bishop -> return true.
38  if (promotion_type == bishop)
39  return true; // We tried all types.
40  else if (promotion_type == rook)
41  type = knight;
42  else if (promotion_type == knight)
43  type = bishop;
45  return false;
46 }
47 
48 bool MoveIterator::prev_promotion(void)
49 {
50  Type type = queen;
51  Type promotion_type = M_current_move.promotion_type();
52  // Order: bishop -> knight -> rook --> queen --> return true.
53  if (promotion_type == queen)
54  return true; // We tried all types.
55  else if (promotion_type == bishop)
56  type = knight;
57  else if (promotion_type == knight)
58  type = rook;
60  return false;
61 }
62 
63 } // namespace cwchess
A namespace for all chess related objects that are not related to the GUI.
Definition: Array.h:39
TypeData const bishop
A constant representing a bishop.
Definition: Type.h:71
TypeData const queen
A constant representing a queen.
Definition: Type.h:75
TypeData const rook
A constant representing a rook.
Definition: Type.h:73
TypeData const knight
A constant representing a knight.
Definition: Type.h:67
Move M_current_move
The actual move that is returned when dereferenced.
Definition: MoveIterator.h:62
void set_promotion(Type promotion)
Set a different promotion type.
Definition: Move.h:115
This file contains the declaration of class MoveIterator.
Type promotion_type(void) const
Return the promotion type. Returns empty if this isn&#39;t a promotion.
Definition: Move.h:107

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