offset.cc Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
offset.cc
Go to the documentation of this file.
1 /* offset.cc
2 */
3 #include "osl/offset.h"
4 #include "osl/boardTable.h"
5 #include <iostream>
6
7 #define OFFSET_INDEX(dx,dy) ((dx*BOARD_HEIGHT + dy) - OFFSET_MIN)
8
9 osl::Offset::Offset(Player player, Direction direction)
10 {
11 *this = Board_Table.getOffset(player, direction);
12 }
13
18 int osl::Offset::dx() const
19 {
20 switch (index())
21 {
22 case OFFSET_INDEX(-1,-2): return -1;
23 case OFFSET_INDEX(1,-2): return 1;
24 case OFFSET_INDEX(-1,-1): return -1;
25 case OFFSET_INDEX(0,-1): return 0;
26 case OFFSET_INDEX(1,-1): return 1;
27 case OFFSET_INDEX(-1,0): return -1;
28 case OFFSET_INDEX(1,0): return 1;
29 case OFFSET_INDEX(-1,1): return -1;
30 case OFFSET_INDEX(0,1): return 0;
31 case OFFSET_INDEX(1,1): return 1;
32 case OFFSET_INDEX(-1,2): return -1;
33 case OFFSET_INDEX(1,2): return 1;
34 default:
35 std::cerr << index() << " " << ZERO().index() << "\n";
36 assert(0);
37 }
38 return 0;
39 }
40
45 int osl::Offset::dy() const
46 {
47 switch (index())
48 {
49 case OFFSET_INDEX(-1,-2): return -2;
50 case OFFSET_INDEX(1,-2): return -2;
51 case OFFSET_INDEX(-1,-1): return -1;
52 case OFFSET_INDEX(0,-1): return -1;
53 case OFFSET_INDEX(1,-1): return -1;
54 case OFFSET_INDEX(-1,0): return 0;
55 case OFFSET_INDEX(1,0): return 0;
56 case OFFSET_INDEX(-1,1): return 1;
57 case OFFSET_INDEX(0,1): return 1;
58 case OFFSET_INDEX(1,1): return 1;
59 case OFFSET_INDEX(-1,2): return 2;
60 case OFFSET_INDEX(1,2): return 2;
61 default: assert(0);
62 }
63 return 0;
64 }
65
66 #ifndef MINIMAL
67 std::ostream& osl::operator<<(std::ostream& os, Offset offset)
68 {
69 return os << "offset(" << offset.intValue() << ')';
70 }
71 #endif
72 /* ------------------------------------------------------------------------- */
73 // ;;; Local Variables:
74 // ;;; mode:c++
75 // ;;; c-basic-offset:2
76 // ;;; End: