boardMask.cc Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
boardMask.cc
Go to the documentation of this file.
1 /* boardMask.cc
2 */
3 #include "osl/container/boardMask.h"
4 #include "osl/centering5x3.h"
5 #include <iostream>
6
7 #ifndef MINIMAL
8 std::ostream& osl::container::operator<<(std::ostream& os, const BoardMask& mask)
9 {
10 for(int y=1; y<=9; ++y) {
11 for(int x=9; x>=1; --x) {
12 const Square p(x,y);
13 os << mask.test(p);
14 }
15 os << std::endl;
16 }
17 return os;
18 }
19 #endif
20
21 osl::container::
22 BoardMaskTable5x5::BoardMaskTable5x5()
23 {
24 for (int cx=1; cx<=9; ++cx) {
25 for (int cy=1; cy<=9; ++cy) {
26 const int min_x = std::max(1, cx - 2);
27 const int max_x = std::min(9, cx + 2);
28 const int min_y = std::max(1, cy - 2);
29 const int max_y = std::min(9, cy + 2);
30 BoardMask mask;
31 mask.clear();
32 for (int x=min_x; x<=max_x; ++x) {
33 for (int y=min_y; y<=max_y; ++y) {
34 mask.set(Square(x,y));
35 }
36 }
37 data[Square(cx,cy).index()] = mask;
38 }
39 }
40 }
41
42 osl::container::
43 BoardMaskTable3x3::BoardMaskTable3x3()
44 {
45 for (int cx=1; cx<=9; ++cx) {
46 for (int cy=1; cy<=9; ++cy) {
47 const int min_x = std::max(1, cx - 1);
48 const int max_x = std::min(9, cx + 1);
49 const int min_y = std::max(1, cy - 1);
50 const int max_y = std::min(9, cy + 1);
51 BoardMask mask;
52 mask.clear();
53 for (int x=min_x; x<=max_x; ++x) {
54 for (int y=min_y; y<=max_y; ++y) {
55 mask.set(Square(x,y));
56 }
57 }
58 data[Square(cx,cy).index()] = mask;
59 }
60 }
61 }
62
63 osl::container::
64 BoardMaskTable5x3Center::BoardMaskTable5x3Center()
65 {
66 for (int cx=1; cx<=9; ++cx) {
67 for (int cy=1; cy<=9; ++cy) {
68 const Square center = Centering5x3::adjustCenter(Square(cx, cy));
69 const int min_x = std::max(1, center.x() - 2);
70 const int max_x = std::min(9, center.x() + 2);
71 const int min_y = std::max(1, center.y() - 1);
72 const int max_y = std::min(9, center.y() + 1);
73 BoardMask mask;
74 mask.clear();
75 for (int x=min_x; x<=max_x; ++x) {
76 for (int y=min_y; y<=max_y; ++y) {
77 mask.set(Square(x,y));
78 }
79 }
80 data[Square(cx,cy).index()] = mask;
81 }
82 }
83 }
84
85 // ;;; Local Variables:
86 // ;;; mode:c++
87 // ;;; c-basic-offset:2
88 // ;;; End: