00001
00002
00003 #ifndef _LIBERTY8TABLE_H
00004 #define _LIBERTY8TABLE_H
00005 #include "osl/ptype.h"
00006 #include "osl/ptypeTable.h"
00007 #include "osl/container/nearMask.h"
00008 #include "osl/misc/carray.h"
00009 #include "osl/misc/carray2d.h"
00010 #include <iosfwd>
00011 namespace osl
00012 {
00013 namespace effect
00014 {
00020 struct LongEffect8
00021 {
00022 friend std::ostream& operator<<(std::ostream& os,LongEffect8 const& longEffect);
00026 char smallOffset;
00027 CArray<unsigned char,3> mask;
00028 public:
00029 LongEffect8():smallOffset(0){
00030 mask[0]=mask[1]=mask[2]=0;
00031 }
00032 Offset getOffset() const{
00033 return Offset::makeDirect(smallOffset);
00034 }
00035 void setOffset(Offset o){
00036 smallOffset=static_cast<char>(o.intValue());
00037 }
00038 unsigned int getMask(int index) const{
00039 return static_cast<unsigned int>(mask[index]);
00040 }
00041 void setMask(int index,unsigned int val) {
00042 mask[index]=static_cast<unsigned char>(val);
00043 }
00044 };
00051 class Liberty8Table{
00052 CArray<CArray<unsigned char,Offset32::SIZE>,PTYPE_SIZE> shortMask;
00053 CArray2d<LongEffect8,PTYPE_SIZE,Offset32::SIZE> longEffect;
00054 CArray<LongEffect8,Offset32::SIZE> longEffect2;
00055 LongEffect8 longEffectOf(Ptype ptype,int dx,int dy);
00056 public:
00057 Liberty8Table();
00065 template<Player P>
00066 NearMask getShortMask(Ptype ptype,Position from, Position to) const{
00067 assert(isValid(ptype) && from.isOnBoard() && to.isOnBoard());
00068 Offset32 offset32=Offset32(to,from).blackOffset32<P>();
00069 return NearMask::makeDirect(shortMask[ptype][offset32.index()]);
00070 }
00076 template<Player P>
00077 LongEffect8 getLongEffect(Ptype ptype,Position from, Position to) const{
00078 assert(isValid(ptype) && from.isOnBoard() && to.isOnBoard());
00079 assert(Ptype_Table.hasLongMove(ptype));
00080 Offset32 offset32=Offset32(to,from).blackOffset32<P>();
00081 return longEffect[ptype][offset32.index()];
00082 }
00087 template<Player P>
00088 LongEffect8 getLongEffect2(Position from, Position to) const{
00089 assert(from.isOnBoard() && to.isOnBoard());
00090 Offset32 offset32=Offset32(to,from).blackOffset32<P>();
00091 return longEffect2[offset32.index()];
00092 }
00093 };
00094
00095 extern const Liberty8Table Liberty8_Table;
00096 }
00097 }
00098 #endif
00099
00100
00101
00102
00103