Reorder README
[purplehaze.git] / src / move.cpp
blob6c9ec2b2cd6dba1646a08d73f407281477b8c487
1 /* Copyright (C) 2007-2012 Vincent Ollivier
3 * Purple Haze is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * Purple Haze is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include <cassert>
18 #include <iostream>
20 #include "move.h"
21 #include "piece.h"
23 PieceType Move::promotion_type() const
25 switch (type()) {
26 case KNIGHT_PROMOTION:
27 case KNIGHT_PROMOTION_CAPTURE:
28 return KNIGHT;
29 case BISHOP_PROMOTION:
30 case BISHOP_PROMOTION_CAPTURE:
31 return BISHOP;
32 case ROOK_PROMOTION:
33 case ROOK_PROMOTION_CAPTURE:
34 return ROOK;
35 case QUEEN_PROMOTION:
36 case QUEEN_PROMOTION_CAPTURE:
37 return QUEEN;
38 default:
39 return EMPTY;
43 PieceType Move::castle_side() const
45 switch (type()) {
46 case KING_CASTLE:
47 return KING;
48 case QUEEN_CASTLE:
49 return QUEEN;
50 default:
51 return EMPTY;
55 std::ostream& operator<<(std::ostream& out, const Move move)
57 return (out << move.to_string());
60 std::string Move::to_string() const
62 if (is_null()) {
63 return "#";
65 std::string res = "";
66 res += static_cast<char>('a' + orig_file());
67 res += static_cast<char>('1' + orig_rank());
68 res += static_cast<char>('a' + dest_file());
69 res += static_cast<char>('1' + dest_rank());
70 if (is_promotion()) {
71 res += Piece(BLACK, promotion_type()).to_string(); // Lower case
73 return res;