]> git.sesse.net Git - stockfish/blob - src/square.cpp
Tweak futility margins
[stockfish] / src / square.cpp
1 /*
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
5
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.
10   
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.
15   
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/>.
18 */
19
20
21 ////
22 //// Includes
23 ////
24
25 #include <cassert>
26 #include <string>
27
28 #include "square.h"
29
30
31 ////
32 //// Functions
33 ////
34
35
36 /// Translating files, ranks and squares to/from characters and strings:
37
38 File file_from_char(char c) {
39   return File(c - 'a') + FILE_A;
40 }
41
42
43 char file_to_char(File f) {
44   return char(f - FILE_A) + 'a';
45 }
46
47
48 Rank rank_from_char(char c) {
49   return Rank(c - '1') + RANK_1;
50 }
51
52
53 char rank_to_char(Rank r) {
54   return char(r - RANK_1) + '1';
55 }
56
57
58 Square square_from_string(const std::string &str) {
59   return make_square(file_from_char(str[0]), rank_from_char(str[1]));
60 }
61
62
63 const std::string square_to_string(Square s) {
64   std::string str;
65   str += file_to_char(square_file(s));
66   str += rank_to_char(square_rank(s));
67   return str;
68 }
69
70
71 /// file_is_ok(), rank_is_ok() and square_is_ok(), for debugging:
72
73 bool file_is_ok(File f) {
74   return f >= FILE_A && f <= FILE_H;
75 }
76
77
78 bool rank_is_ok(Rank r) {
79   return r >= RANK_1 && r <= RANK_8;
80 }
81
82
83 bool square_is_ok(Square s) {
84   return file_is_ok(square_file(s)) && rank_is_ok(square_rank(s));
85 }