2 Stockfish, a UCI chess playing engine derived from Glaurung 2.1
3 Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
4 Copyright (C) 2008 Marco Costalba
6 Stockfish is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Stockfish is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
36 /// Translating files, ranks and squares to/from characters and strings:
38 File file_from_char(char c) {
39 return File(c - 'a') + FILE_A;
43 char file_to_char(File f) {
44 return char(f - FILE_A) + 'a';
48 Rank rank_from_char(char c) {
49 return Rank(c - '1') + RANK_1;
53 char rank_to_char(Rank r) {
54 return char(r - RANK_1) + '1';
58 Square square_from_string(const std::string &str) {
59 return make_square(file_from_char(str[0]), rank_from_char(str[1]));
63 const std::string square_to_string(Square s) {
65 str += file_to_char(square_file(s));
66 str += rank_to_char(square_rank(s));
71 /// file_is_ok(), rank_is_ok() and square_is_ok(), for debugging:
73 bool file_is_ok(File f) {
74 return f >= FILE_A && f <= FILE_H;
78 bool rank_is_ok(Rank r) {
79 return r >= RANK_1 && r <= RANK_8;
83 bool square_is_ok(Square s) {
84 return file_is_ok(square_file(s)) && rank_is_ok(square_rank(s));