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