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