All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
sendOffSquare.cc
Go to the documentation of this file.
1 /* sendOffSquare.cc
2  */
4 #include "osl/ptypeTable.h"
5 #include "osl/misc/bitOp.h"
6 #include <boost/foreach.hpp>
7 
10 {
11  normal[0] = Offset( 1, 1);
12  normal[1] = Offset( 1, 0);
13  normal[2] = Offset( 1,-1);
14  normal[3] = Offset( 0, 1);
15  normal[4] = Offset( 0,-1);
16  normal[5] = Offset(-1, 1);
17  normal[6] = Offset(-1, 0);
18  normal[7] = Offset(-1,-1);
19 
20  const Square center(5,5);
21  const PtypeO king = newPtypeO(BLACK, KING);
22  for (int i=0; i<8; ++i)
23  {
24  const Offset king_square = normal[i];
25  for (int j=0; j<8; ++j)
26  {
27  const Offset target = normal[j];
28  if (i==j)
29  continue;
30  const int dx = king_square.dx() - target.dx();
31  const int dy = king_square.dy() - target.dy();
32  const EffectContent effect
33  = Ptype_Table.getEffect(king, Offset32(dx, dy));
34  if (! effect.hasEffect())
35  {
36  reverse[i].push_back(j);
37  }
38  }
39  }
40 
41  for (int i=0; i<256; ++i)
42  {
43  unsigned int val = i;
44  while (val)
45  {
46  const int j = misc::BitOp::takeOneBit(val);
47 
48  BOOST_FOREACH(int p, reverse[j])
49  {
50  if (! reverse_all[i].isMember(p))
51  reverse_all[i].push_back(p);
52  }
53  }
54  }
55 }
56 
57 template <osl::Player Attack>
59 #if (defined __GNUC__) && (! defined GPSONE) && (! defined GPSUSIONE)
60 __attribute__ ((used))
61 #endif
63 SendOffSquare::find(const NumEffectState& state, Square king_square,
64  Square8& out)
65 {
66  assert(out.empty());
67  int flags=0;
68  for (int i=0; i<8; ++i)
69  {
70  testSquare<Attack>(state, king_square+table.normal[i], i, flags);
71  }
72  SendOff8 data = 0;
73  BOOST_FOREACH(int i, table.reverse_all[flags])
74  {
75  const Square candidate = king_square + table.normal[i];
76  if (! state.pieceAt(candidate).isEdge()
77  && state.countEffect(alt(Attack), candidate) == 1) {
78  out.push_back(candidate);
79  data |= (1<<i);
80  }
81  }
82  return data;
83 }
84 
87  Square8& out)
88 {
89  assert(out.empty());
90  unsigned int flags = flags8;
91  while (flags) {
92  const int i = misc::BitOp::takeOneBit(flags);
93  const Square candidate = king_square + table.normal[i];
94  out.push_back(candidate);
95  }
96 }
97 
99 SendOffSquare::find(Player attack, const NumEffectState& state,
100  Square king_square,
101  Square8& out)
102 {
103  if (attack == BLACK)
104  return find<BLACK>(state, king_square, out);
105  else
106  return find<WHITE>(state, king_square, out);
107 }
108 
109 /* ------------------------------------------------------------------------- */
110 // ;;; Local Variables:
111 // ;;; mode:c++
112 // ;;; c-basic-offset:2
113 // ;;; End: