説明を見る。00001
00002
00003 #include "osl/effect_util/sendOffSquare.h"
00004 #include "osl/bits/ptypeTable.h"
00005 #include "osl/oslConfig.h"
00006
00007 osl::effect_util::SendOffSquare::Table osl::effect_util::SendOffSquare::table;
00008
00009 static osl::SetUpRegister _initializer([](){
00010 osl::effect_util::SendOffSquare::init();
00011 });
00012
00013 void osl::effect_util::SendOffSquare::
00014 Table::init()
00015 {
00016 normal[0] = Offset( 1, 1);
00017 normal[1] = Offset( 1, 0);
00018 normal[2] = Offset( 1,-1);
00019 normal[3] = Offset( 0, 1);
00020 normal[4] = Offset( 0,-1);
00021 normal[5] = Offset(-1, 1);
00022 normal[6] = Offset(-1, 0);
00023 normal[7] = Offset(-1,-1);
00024
00025 const Square center(5,5);
00026 const PtypeO king = newPtypeO(BLACK, KING);
00027 for (int i=0; i<8; ++i)
00028 {
00029 const Offset king_square = normal[i];
00030 for (int j=0; j<8; ++j)
00031 {
00032 const Offset target = normal[j];
00033 if (i==j)
00034 continue;
00035 const int dx = king_square.dx() - target.dx();
00036 const int dy = king_square.dy() - target.dy();
00037 const EffectContent effect
00038 = Ptype_Table.getEffect(king, Offset32(dx, dy));
00039 if (! effect.hasEffect())
00040 {
00041 reverse[i].push_back(j);
00042 }
00043 }
00044 }
00045
00046 for (int i=0; i<256; ++i)
00047 {
00048 unsigned int val = i;
00049 while (val)
00050 {
00051 const int j = misc::BitOp::takeOneBit(val);
00052
00053 for (int p: reverse[j])
00054 {
00055 if (! reverse_all[i].isMember(p))
00056 reverse_all[i].push_back(p);
00057 }
00058 }
00059 }
00060 }
00061
00062 template <osl::Player Attack>
00063 osl::effect_util::SendOffSquare::SendOff8
00064 #if (defined __GNUC__) && (! defined GPSONE) && (! defined GPSUSIONE)
00065 __attribute__ ((used))
00066 #endif
00067 osl::effect_util::
00068 SendOffSquare::find(const NumEffectState& state, Square king_square,
00069 Square8& out)
00070 {
00071 assert(out.empty());
00072 int flags=0;
00073 for (int i=0; i<8; ++i)
00074 {
00075 testSquare<Attack>(state, king_square+table.normal[i], i, flags);
00076 }
00077 SendOff8 data = 0;
00078 for (int i: table.reverse_all[flags])
00079 {
00080 const Square candidate = king_square + table.normal[i];
00081 if (! state.pieceAt(candidate).isEdge()
00082 && state.countEffect(alt(Attack), candidate) == 1) {
00083 out.push_back(candidate);
00084 data |= (1<<i);
00085 }
00086 }
00087 return data;
00088 }
00089
00090 void osl::effect_util::
00091 SendOffSquare::unpack(SendOff8 flags8, Square king_square,
00092 Square8& out)
00093 {
00094 assert(out.empty());
00095 unsigned int flags = flags8;
00096 while (flags) {
00097 const int i = misc::BitOp::takeOneBit(flags);
00098 const Square candidate = king_square + table.normal[i];
00099 out.push_back(candidate);
00100 }
00101 }
00102
00103 osl::effect_util::SendOffSquare::SendOff8 osl::effect_util::
00104 SendOffSquare::find(Player attack, const NumEffectState& state,
00105 Square king_square,
00106 Square8& out)
00107 {
00108 if (attack == BLACK)
00109 return find<BLACK>(state, king_square, out);
00110 else
00111 return find<WHITE>(state, king_square, out);
00112 }
00113
00114
00115
00116
00117
00118