piecePair.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
piecePair.h
Go to the documentation of this file.
1 /* piecePair.h
2 */
3 #ifndef OSL_EVAL_PIECEPAIR_H
4 #define OSL_EVAL_PIECEPAIR_H
5
6 #include "osl/eval/ml/weights.h"
7 #include "osl/eval/evalTraits.h"
8 #include "osl/state/numEffectState.h"
9 #include "osl/misc/carray3d.h"
10 #include <iostream>
11
12 namespace osl
13 {
14 namespace eval
15 {
16 namespace ml
17 {
18 class PiecePair
19 {
20 public:
21 enum {
22 plain_table_size = 1338,
23 x_table_size = 4901,
24 y_table_size = 7057,
25 DIM = plain_table_size + x_table_size + y_table_size, // 14 * 12 * PTYPEO_SIZE * PTYPEO_SIZE
26 };
27
28 static int eval(const NumEffectState&, const Weights&);
29 template<int Direction, int Offset>
30 static int sum12One(const Piece *basePtr,const int *xbase, const int *ybase);
31 static int sum12(NumEffectState const& state,Square base,PtypeO ptypeO);
32 template<int Direction, int Offset>
33 static int adjust12One(const Piece *basePtr,const int *xbase1, const int *ybase1,const int *xbase2, const int *ybase2);
34 static int adjust12(NumEffectState const& state,Square base,PtypeO pos,PtypeO neg);
35
36 static int evalWithUpdate(const NumEffectState& state, Move moved, int last_value, const Weights& values);
37 static int evalWithUpdateCompiled(const NumEffectState& state, Move moved, int last_value);
38
39 static int pieceValue(const NumEffectState& state, Piece p, const Weights& values);
40 static int pieceValueDouble(const NumEffectState& state, Piece p, const Weights&);
41 static int weight(Player attack, int index, const Weights& values)
42 {
43 return osl::eval::delta(attack) * values.value(index);
44 }
45 typedef CArray<int,3> index_t;
46 static index_t index(int offset_id, Piece p, Piece q);
47 static index_t index(int offset_id, Square p0, PtypeO o0, Square p1, PtypeO o1);
48
49 static int value(int offset_id, Piece p, Piece q, const Weights& values)
50 {
51 assert(p.isOnBoard() && q.isOnBoard());
52 return value(offset_id, p.square(), p.ptypeO(), q.square(), q.ptypeO(), values);
53 }
54 static int value(int offset_id, Piece p, Square p1, PtypeO o1, const Weights& values)
55 {
56 return value(offset_id, p.square(), p.ptypeO(), p1, o1, values);
57 }
58 static int value(int offset_id, Square p0, PtypeO o0, Square p1, PtypeO o1, const Weights& values)
59 {
60 assert(p0 != p1);
61 index_t idx = index(offset_id, p0, o0, p1, o1);
62 assert(idx[0] != 0); // do not forget to call init()
63 int ret = 0;
64 for (int i=0; i<3; ++i)
65 ret += (idx[i] > 0) ? values.value(idx[i]) : -values.value(-idx[i]);
66 return ret;
67 }
68
69 static void init();
70 static void sanitize(Weights& values);
72 static void compile(const Weights& values);
73 static int valueCompiled(int offset_id, Piece p, Square p1, PtypeO o1)
74 {
75 return valueCompiled(offset_id, p.square(), p.ptypeO(), p1, o1);
76 }
77 static int valueCompiled(int offset_id, Square p0, PtypeO o0, Square p1, PtypeO o1);
78
79 // 内部用
80 struct IndexTable : public CArray3d<signed short, 12, PTYPEO_SIZE, PTYPEO_SIZE>
81 {
82 IndexTable();
83 void fillBW(int index, int dir, Ptype p0, Ptype p1);
85 void fillSame(int index, int dir, Ptype p0, Ptype p1);
87 void fillDiffer(int index, int dir, Ptype p0, Ptype p1);
88 static int pindex(Player player, Ptype ptype)
89 {
90 return ptypeOIndex(newPtypeO(player, ptype));
91 }
92 void amplify(int base);
93 };
94 static IndexTable plain_table;
95 static CArray<IndexTable, 10> x_table, y_table;
96 static const CArray<const Offset, 12> offsets; // offset_id -> Offset
97 };
98 }
99 }
100 }
101
102
103 #endif /* OSL_EVAL_ATTACKKING_H */
104 // ;;; Local Variables:
105 // ;;; mode:c++
106 // ;;; c-basic-offset:2
107 // ;;; End: