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