candidates_table.cc
Go to the documentation of this file.
1 // cwchessboard -- A C++ chessboard tool set for gtkmm
2 //
3 //! @file candidates_table.cc Program used to generate cwchess::candidates_table[].
4 //
5 // Copyright (C) 2008, by
6 //
7 // Carlo Wood, Run on IRC <carlo@alinoe.com>
8 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt
9 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61
10 //
11 // This program is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 2 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 
24 #include "sys.h"
25 #include <iostream>
26 #include <iomanip>
27 
28 using std::cout;
29 using std::endl;
30 
31 struct Direction {
32  int x;
33  int y;
34 };
35 
36 struct Piece {
37  char const* name;
38  int depth;
39  int nrdirs;
40  Direction direction[4];
41 };
42 
43 Piece piece[] = {
44  { "Knight", 1, 4, { { 1, 2 }, { 2, 1 }, { 2, -1, }, { 1, -2 } } },
45  { "King", 1, 4, { { 0, 1 }, { 1, 0 }, { 1, 1 }, { 1, -1 } } },
46  { "Bishop", 8, 2, { { 1, 1 }, { 1, -1 } } },
47  { "Rook", 8, 2, { { 0, 1 }, { 1, 0 } } },
48  { "Queen", 8, 4, { { 0, 1 }, { 1, 0 }, { 1, 1 }, { 1, -1 } } }
49 };
50 
51 uint64_t colrow2mask(int col, int row)
52 {
53  return CW_MASK_T_CONST(1) << ((col << 3) + row);
54 }
55 
56 int main()
57 {
58  for (int p = 0; p < 5; ++p)
59  {
60  cout << "// " << piece[p].name << '\n';
61  for (int col = 0; col < 8; ++col)
62  {
63  for (int row = 0; row < 8; ++row)
64  {
65  uint64_t mask = 0;
66  for (int dir = 0; dir < piece[p].nrdirs; ++dir)
67  {
68  for (int depth = -piece[p].depth; depth <= piece[p].depth; ++depth)
69  {
70  if (depth == 0)
71  continue;
72  int tcol = col + depth * piece[p].direction[dir].x;
73  if (tcol < 0 || tcol > 7)
74  continue;
75  int trow = row + depth * piece[p].direction[dir].y;
76  if (trow < 0 || trow > 7)
77  continue;
78  mask |= colrow2mask(tcol, trow);
79  }
80  }
81  std::cout << std::hex << "{ CW_MASK_T_CONST(0x" << std::setfill('0') << std::setw(16) << mask << ") }, ";
82  if (row == 3)
83  std::cout << '\n';
84  }
85  std::cout << '\n';
86  }
87  }
88 }

Copyright © 2006 - 2010 Carlo Wood.  All rights reserved.