direction_index_table.cc
Go to the documentation of this file.
1 // cwchessboard -- A C++ chessboard tool set for gtkmm
2 //
3 //! @file direction_index_table.cc Program used to generate cwchess::direction_index_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 <iostream>
25 #include <iomanip>
26 #include <cstdlib>
27 
28 void output(int val)
29 {
30  static int count = 0;
31  if (count == 0)
32  std::cout << ' ';
33  std::cout << " 0x" << std::setfill('0') << std::setw(2) << std::hex << val << std::dec << ',';
34  if (++count == 16)
35  {
36  std::cout << '\n';
37  count = 0;
38  }
39 }
40 
41 int main()
42 {
43  for (int i = 0; i < 256; ++i)
44  {
45  int col_diff = i & 0xf;
46  int row_diff = i >> 4;
47  if (col_diff == 8 || row_diff == 8)
48  {
49  output(8);
50  continue;
51  }
52  if (col_diff > 8)
53  col_diff -= 16;
54  if (row_diff > 8)
55  row_diff -= 16;
56  if (col_diff == 0 && row_diff == 0)
57  {
58  output(8);
59  continue;
60  }
61  if (col_diff != 0 && row_diff != 0 && std::abs(col_diff) != std::abs(row_diff))
62  {
63  output(8);
64  continue;
65  }
66  if (col_diff == 0 && row_diff < 0)
67  output(1); // south
68  else if (col_diff == 0 && row_diff > 0)
69  output(6); // north
70  else if (col_diff < 0 && row_diff == 0)
71  output(3); // west
72  else if (col_diff > 0 && row_diff == 0)
73  output(4); // east
74  else if (col_diff < 0 && row_diff < 0)
75  output(0); // south-west
76  else if (col_diff < 0 && row_diff > 0)
77  output(5); // north-west
78  else if (col_diff > 0 && row_diff < 0)
79  output(2); // south-east
80  else if (col_diff > 0 && row_diff > 0)
81  output(7); // north-east
82  }
83  std::cout << '\n';
84 }

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