説明を見る。00001
00002
00003 #ifndef OSL_PTYPETABLE_H
00004 #define OSL_PTYPETABLE_H
00005
00006 #include "osl/basic_type.h"
00007 #include "osl/bits/ptypeTraits.h"
00008 #include "osl/bits/effectContent.h"
00009 #include "osl/container.h"
00010 #include "osl/bits/offset32.h"
00011 #include "osl/bits/mask.h"
00012
00013 namespace osl
00014 {
00015 class PtypeTable
00016 {
00017 private:
00018 CArray<mask_t, PTYPE_SIZE> numMaskLows;
00019 CArray<int, PTYPE_SIZE> numIndices;
00020 CArray<const char *, PTYPE_SIZE> names;
00021 CArray<const char *, PTYPE_SIZE> csaNames;
00022 CArray<bool, PTYPE_SIZE> betterToPromote;
00023 CArray<int, PTYPE_SIZE> moveMasks;
00024 CArray<int, PTYPE_SIZE> indexMins;
00025 CArray<int, PTYPE_SIZE> indexLimits;
00026
00027 CArray2d<int, 2, PTYPE_SIZE> canDropLimit;
00028
00029 CArray2d<EffectContent,PTYPEO_SIZE,Offset32::SIZE> effectTable;
00030 CArray2d<EffectContent,PTYPEO_SIZE,Offset32::SIZE> effectTableNotLongU;
00031 CArray2d<unsigned int, 2, SHORT_DIRECTION_SIZE> shortMoveMask;
00032
00033 template<Ptype T> void initPtypeSub(Int2Type<false> isBasic);
00034 template<Ptype T> void initPtypeSub(Int2Type<true> isBasic);
00035 template<Ptype T> void initPtype();
00036 public:
00037 PtypeTable();
00038 private:
00039 void init();
00040 public:
00041 unsigned int getShortMoveMask(Player p,PtypeO ptypeo,Direction dir) const
00042 {
00043 return shortMoveMask[playerToIndex(p)][static_cast<int>(dir)] &
00044 (1<<(ptypeo-PTYPEO_MIN));
00045 }
00046 mask_t getMaskLow(Ptype ptype) const
00047 {
00048 return numMaskLows[ptype];
00049 }
00050 int getIndex(Ptype) const { return 0; }
00054 bool hasLongMove(Ptype ptype) const
00055 {
00056 return getIndexMin(unpromote(ptype))>=32;
00057 }
00058 bool isBetterToPromote(Ptype ptype) const
00059 {
00060 return betterToPromote[ptype];
00061 }
00062 int getCanDropLimit(Player player,Ptype ptype) const
00063 {
00064 assert(isValid(ptype) && !isPromoted(ptype));
00065 return canDropLimit[playerToIndex(player)][ptype];
00066 }
00067
00068 bool canDropTo(Player pl, Ptype ptype, Square pos) const
00069 {
00070 if (pl == BLACK)
00071 return pos.y() >= getCanDropLimit(BLACK,ptype);
00072 else
00073 return pos.y() <= getCanDropLimit(WHITE,ptype);
00074 }
00075
00076 const char *getName(Ptype ptype) const
00077 {
00078 return names[ptype];
00079 }
00080 const char *getCsaName(Ptype ptype) const
00081 {
00082 return csaNames[ptype];
00083 }
00084 int getMoveMask(Ptype ptype) const
00085 {
00086 return moveMasks[ptype];
00087 }
00088 int getIndexMin(Ptype ptype) const
00089 {
00090 assert(isBasic(ptype));
00091 return indexMins[ptype];
00092 }
00093 int getIndexLimit(Ptype ptype) const
00094 {
00095 assert(isBasic(ptype));
00096 return indexLimits[ptype];
00097 }
00098 static int getKingIndex(Player p)
00099 {
00100 assert(isValid(p));
00101 if (p==BLACK)
00102 return KingTraits<BLACK>::index;
00103 else
00104 return KingTraits<WHITE>::index;
00105 }
00112 const EffectContent getEffect(PtypeO ptypeo,Square from, Square to) const
00113 {
00114 assert(from.isOnBoard() && to.isOnBoard());
00115 return getEffect(ptypeo,Offset32(to,from));
00116 }
00117 const EffectContent& getEffect(PtypeO ptypeo,Offset32 offset32) const
00118 {
00119 assert(isValidPtypeO(ptypeo));
00120 return effectTable[ptypeo-PTYPEO_MIN][offset32.index()];
00121 }
00122 private:
00123 EffectContent& effect(PtypeO ptypeo,Offset32 offset32)
00124 {
00125 assert(isValidPtypeO(ptypeo));
00126 const int i1 = ptypeo-PTYPEO_MIN;
00127 const int i2 = offset32.index();
00128 return effectTable[i1][i2];
00129 }
00130 public:
00132 const EffectContent
00133 getEffectNotLongU(PtypeO ptypeo, Square from, Square to) const
00134 {
00135 assert(isValidPtypeO(ptypeo));
00136 assert(from.isOnBoard() && to.isOnBoard());
00137 Offset32 offset32=Offset32(to,from);
00138 return effectTableNotLongU[ptypeo-PTYPEO_MIN][offset32.index()];
00139 }
00140 bool hasUnblockableEffect(PtypeO attacker, Square from, Square to) const
00141 {
00142 const EffectContent effect = getEffect(attacker, from, to);
00143 return effect.hasUnblockableEffect();
00144 }
00145 };
00146
00147 extern const PtypeTable Ptype_Table;
00148
00149 }
00150
00151
00152 #endif
00153
00154
00155
00156