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