1 /* square.h
2 
3    GNU Chess protocol adapter
4 
5    Copyright (C) 2001-2011 Free Software Foundation, Inc.
6 
7    This program is free software: you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation, either version 3 of the License, or
10    (at your option) any later version.
11 
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 
22 // square.h
23 
24 #ifndef SQUARE_H
25 #define SQUARE_H
26 
27 // includes
28 
29 #include "util.h"
30 
31 namespace adapter {
32 
33 // constants
34 
35 const int SquareNb = 16 * 12;
36 
37 const int FileA = 0;
38 const int FileB = 1;
39 const int FileC = 2;
40 const int FileD = 3;
41 const int FileE = 4;
42 const int FileF = 5;
43 const int FileG = 6;
44 const int FileH = 7;
45 
46 const int Rank1 = 0;
47 const int Rank2 = 1;
48 const int Rank3 = 2;
49 const int Rank4 = 3;
50 const int Rank5 = 4;
51 const int Rank6 = 5;
52 const int Rank7 = 6;
53 const int Rank8 = 7;
54 
55 const int SquareNone = 0;
56 
57 const int A1=0x24, B1=0x25, C1=0x26, D1=0x27, E1=0x28, F1=0x29, G1=0x2A, H1=0x2B;
58 const int A2=0x34, B2=0x35, C2=0x36, D2=0x37, E2=0x38, F2=0x39, G2=0x3A, H2=0x3B;
59 const int A3=0x44, B3=0x45, C3=0x46, D3=0x47, E3=0x48, F3=0x49, G3=0x4A, H3=0x4B;
60 const int A4=0x54, B4=0x55, C4=0x56, D4=0x57, E4=0x58, F4=0x59, G4=0x5A, H4=0x5B;
61 const int A5=0x64, B5=0x65, C5=0x66, D5=0x67, E5=0x68, F5=0x69, G5=0x6A, H5=0x6B;
62 const int A6=0x74, B6=0x75, C6=0x76, D6=0x77, E6=0x78, F6=0x79, G6=0x7A, H6=0x7B;
63 const int A7=0x84, B7=0x85, C7=0x86, D7=0x87, E7=0x88, F7=0x89, G7=0x8A, H7=0x8B;
64 const int A8=0x94, B8=0x95, C8=0x96, D8=0x97, E8=0x98, F8=0x99, G8=0x9A, H8=0x9B;
65 
66 const int Dark  = 0;
67 const int Light = 1;
68 
69 // functions
70 
71 extern void square_init        ();
72 
73 extern bool square_is_ok       (int square);
74 
75 extern int  square_make        (int file, int rank);
76 
77 extern int  square_file        (int square);
78 extern int  square_rank        (int square);
79 extern int  square_side_rank   (int square, int colour);
80 
81 extern int  square_from_64     (int square);
82 extern int  square_to_64       (int square);
83 
84 extern bool square_is_promote  (int square);
85 extern int  square_ep_dual     (int square);
86 
87 extern int  square_colour      (int square);
88 
89 extern bool char_is_file       (int c);
90 extern bool char_is_rank       (int c);
91 
92 extern int  file_from_char     (int c);
93 extern int  rank_from_char     (int c);
94 
95 extern int  file_to_char       (int file);
96 extern int  rank_to_char       (int rank);
97 
98 extern bool square_to_string   (int square, char string[], int size);
99 extern int  square_from_string (const char string[]);
100 
101 }  // namespace adapter
102 
103 #endif // !defined SQUARE_H
104 
105 // end of square.h
106 
107