00001 // cwchessboard -- A C++ chessboard tool set 00002 // 00003 //! @file MoveIterator.cc This file contains the implementation of class MoveIterator. 00004 // 00005 // Copyright (C) 2008, by 00006 // 00007 // Carlo Wood, Run on IRC <carlo@alinoe.com> 00008 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt 00009 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61 00010 // 00011 // This program is free software: you can redistribute it and/or modify 00012 // it under the terms of the GNU General Public License as published by 00013 // the Free Software Foundation, either version 2 of the License, or 00014 // (at your option) any later version. 00015 // 00016 // This program is distributed in the hope that it will be useful, 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 // GNU General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU General Public License 00022 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00023 00024 #ifndef USE_PCH 00025 #include "sys.h" 00026 #endif 00027 00028 #include "MoveIterator.h" 00029 00030 namespace cwchess { 00031 00032 bool MoveIterator::next_promotion(void) 00033 { 00034 Type type = rook; 00035 Type promotion_type = M_current_move.promotion_type(); 00036 // The piece is a queen when we get here first. 00037 // Order: queen -> rook -> knight -> bishop -> return true. 00038 if (promotion_type == bishop) 00039 return true; // We tried all types. 00040 else if (promotion_type == rook) 00041 type = knight; 00042 else if (promotion_type == knight) 00043 type = bishop; 00044 M_current_move.set_promotion(type); 00045 return false; 00046 } 00047 00048 bool MoveIterator::prev_promotion(void) 00049 { 00050 Type type = queen; 00051 Type promotion_type = M_current_move.promotion_type(); 00052 // Order: bishop -> knight -> rook --> queen --> return true. 00053 if (promotion_type == queen) 00054 return true; // We tried all types. 00055 else if (promotion_type == bishop) 00056 type = knight; 00057 else if (promotion_type == knight) 00058 type = rook; 00059 M_current_move.set_promotion(type); 00060 return false; 00061 } 00062 00063 } // namespace cwchess