00001
00002
00003 #ifndef OSL_EVAL_PIECEPAIR_H
00004 #define OSL_EVAL_PIECEPAIR_H
00005
00006 #include "osl/eval/weights.h"
00007 #include "osl/eval/evalTraits.h"
00008 #include "osl/numEffectState.h"
00009 #include <iostream>
00010
00011 namespace osl
00012 {
00013 namespace eval
00014 {
00015 namespace ml
00016 {
00017 class PiecePair
00018 {
00019 public:
00020 enum {
00021 plain_table_size = 1338,
00022 x_table_size = 4901,
00023 y_table_size = 7057,
00024 DIM = plain_table_size + x_table_size + y_table_size,
00025 };
00026
00027 static int eval(const NumEffectState&, const Weights&);
00028 template<int Direction, int Offset>
00029 static int sum12One(const Piece *basePtr,const int *xbase, const int *ybase);
00030 static int sum12(NumEffectState const& state,Square base,PtypeO ptypeO);
00031 template<int Direction, int Offset>
00032 static int adjust12One(const Piece *basePtr,const int *xbase1, const int *ybase1,const int *xbase2, const int *ybase2);
00033 static int adjust12(NumEffectState const& state,Square base,PtypeO pos,PtypeO neg);
00034
00035 static int evalWithUpdate(const NumEffectState& state, Move moved, int last_value, const Weights& values);
00036 static int evalWithUpdateCompiled(const NumEffectState& state, Move moved, int last_value);
00037
00038 static int pieceValue(const NumEffectState& state, Piece p, const Weights& values);
00039 static int pieceValueDouble(const NumEffectState& state, Piece p, const Weights&);
00040 static int weight(Player attack, int index, const Weights& values)
00041 {
00042 return osl::eval::delta(attack) * values.value(index);
00043 }
00044 typedef CArray<int,3> index_t;
00045 static index_t index(int offset_id, Piece p, Piece q);
00046 static index_t index(int offset_id, Square p0, PtypeO o0, Square p1, PtypeO o1);
00047
00048 static int value(int offset_id, Piece p, Piece q, const Weights& values)
00049 {
00050 assert(p.isOnBoard() && q.isOnBoard());
00051 return value(offset_id, p.square(), p.ptypeO(), q.square(), q.ptypeO(), values);
00052 }
00053 static int value(int offset_id, Piece p, Square p1, PtypeO o1, const Weights& values)
00054 {
00055 return value(offset_id, p.square(), p.ptypeO(), p1, o1, values);
00056 }
00057 static int value(int offset_id, Square p0, PtypeO o0, Square p1, PtypeO o1, const Weights& values)
00058 {
00059 assert(p0 != p1);
00060 index_t idx = index(offset_id, p0, o0, p1, o1);
00061 assert(idx[0] != 0);
00062 int ret = 0;
00063 for (int i=0; i<3; ++i)
00064 ret += (idx[i] > 0) ? values.value(idx[i]) : -values.value(-idx[i]);
00065 return ret;
00066 }
00067
00068 static void init();
00069 static void sanitize(Weights& values);
00071 static void compile(const Weights& values);
00072 static int valueCompiled(int offset_id, Piece p, Square p1, PtypeO o1)
00073 {
00074 return valueCompiled(offset_id, p.square(), p.ptypeO(), p1, o1);
00075 }
00076 static int valueCompiled(int offset_id, Square p0, PtypeO o0, Square p1, PtypeO o1);
00077
00078
00079 struct IndexTable : public CArray3d<signed short, 12, PTYPEO_SIZE, PTYPEO_SIZE>
00080 {
00081 IndexTable();
00082 void fillBW(int index, int dir, Ptype p0, Ptype p1);
00084 void fillSame(int index, int dir, Ptype p0, Ptype p1);
00086 void fillDiffer(int index, int dir, Ptype p0, Ptype p1);
00087 static int pindex(Player player, Ptype ptype)
00088 {
00089 return ptypeOIndex(newPtypeO(player, ptype));
00090 }
00091 void amplify(int base);
00092 };
00093 static IndexTable plain_table;
00094 static CArray<IndexTable, 10> x_table, y_table;
00095 static const CArray<Offset, 12> offsets;
00096 };
00097 }
00098 }
00099 }
00100
00101
00102 #endif
00103
00104
00105
00106