Go to the documentation of this file.00001
00002
00003 #ifndef ENDGAME_KINGPIECETABLE_H
00004 #define ENDGAME_KINGPIECETABLE_H
00005
00006 #include "osl/piece.h"
00007 #include "osl/misc/carray2d.h"
00008
00009 namespace osl
00010 {
00011 namespace state
00012 {
00013 class SimpleState;
00014 }
00015 namespace container
00016 {
00017 class PieceValues;
00018 }
00019 namespace eval
00020 {
00021 namespace endgame
00022 {
00023 class KingPieceTable;
00024 bool operator==(const KingPieceTable& l, KingPieceTable& r);
00028 class KingPieceTable
00029 {
00030 public:
00031 enum { EffectiveDimension = 81*2*82*PTYPE_SIZE };
00032 protected:
00033 CArray2d<int,Square::SIZE*2,Square::SIZE*PTYPE_SIZE> data;
00034 KingPieceTable() { data.fill(0); }
00035 public:
00036 static int otherIndex(Square other, Ptype ptype)
00037 {
00038 return other.index()*PTYPE_SIZE + ptype;
00039 }
00040 static int kingIndex(Square king, Player defense)
00041 {
00042 return king.index()*2+playerToIndex(defense);
00043 }
00044 int& valueOf(Square king, Player defense, Square other, Ptype ptype)
00045 {
00046 return data[kingIndex(king,defense)][otherIndex(other,ptype)];
00047 }
00048 int valueOf(Square king, Player defense, Square other, Ptype ptype) const
00049 {
00050 return data[kingIndex(king,defense)][otherIndex(other, ptype)];
00051 }
00052 static int effectiveIndexOf(Square king, Player defense, Square other, Ptype ptype)
00053 {
00054 int base = (((king.x()-1)*9+king.y()-1)*2+playerToIndex(defense));
00055 int s = other.isPieceStand() ? 0 : ((other.x()-1)*9+other.y());
00056 return base*82*PTYPE_SIZE + s*PTYPE_SIZE + ptype;
00057 }
00058 void saveText(const char *filename) const;
00059 void loadText(const char *filename);
00060 void resetWeights(const int *w);
00061 void randomize();
00062 void clear();
00063 static int dimension() { return EffectiveDimension; }
00064 friend bool operator==(const KingPieceTable& l, KingPieceTable& r);
00065 };
00066 }
00067 }
00068 }
00069
00070
00071 #endif
00072
00073
00074
00075
00076