Go to the documentation of this file.00001
00002
00003 #ifndef EFFECT_UTIL_NEIGHBORING8EFFECT_H
00004 #define EFFECT_UTIL_NEIGHBORING8EFFECT_H
00005
00006 #include "osl/state/numEffectState.h"
00007 #include "osl/direction.h"
00008
00009 namespace osl
00010 {
00011 namespace effect_util
00012 {
00017 class Neighboring8Effect
00018 {
00019 class Table
00020 {
00021 struct Entry
00022 {
00023 bool has_unblockable_effect;
00024 Offset nearest;
00025 Entry() : has_unblockable_effect(false), nearest(Offset::ZERO())
00026 {
00027 }
00028 };
00029 CArray2d<Entry,PTYPEO_SIZE,Offset32::SIZE> table;
00030 void init(Player);
00031
00032 template <int maxCount>
00033 bool hasAtMaxPieceBetween(const NumEffectState& state,
00034 Square from, Square target) const
00035 {
00036 assert(from.isOnBoard());
00037 Offset offset=Board_Table.getShortOffset(Offset32(target, from));
00038 assert(! offset.zero());
00039 int count = 0;
00040 for (Square pos=from+offset; pos != target; pos+=offset)
00041 {
00042 if (!state.pieceAt(pos).isEmpty())
00043 {
00044 count++;
00045 if (count > maxCount) return false;
00046 }
00047 }
00048 return true;
00049 }
00050
00051 public:
00052 Table();
00053
00054 bool hasEffect(const NumEffectState& state,
00055 PtypeO ptypeo, Square from,
00056 Square target) const
00057 {
00058 const Offset32 offset32 = Offset32(target, from);
00059 const Entry& e = table[ptypeOIndex(ptypeo)][offset32.index()];
00060 if (e.has_unblockable_effect)
00061 return true;
00062 if (e.nearest.zero())
00063 return false;
00064 assert(Ptype_Table.hasLongMove(getPtype(ptypeo)));
00065 const Square nearest = from+e.nearest;
00066 if (! nearest.isOnBoard())
00067 {
00068 return false;
00069 }
00070 return hasAtMaxPieceBetween<1>(state, from, nearest);
00071 }
00072 };
00073 static const Table table;
00074 public:
00078 static bool hasEffect(const NumEffectState& state,
00079 PtypeO ptypeo, Square from,
00080 Square target)
00081 {
00082 return table.hasEffect(state, ptypeo, from, target);
00083 }
00084 private:
00085 static bool hasEffectFromTo(const NumEffectState& state,
00086 PtypeO ptypeo, Square from,
00087 Square target, Direction d);
00088 public:
00089 static bool hasEffectNaive(const NumEffectState& state,
00090 PtypeO ptypeo, Square from,
00091 Square target);
00092 };
00093
00094 }
00095 using effect_util::Neighboring8Effect;
00096 }
00097
00098 #endif
00099
00100
00101
00102