pinGroup.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
pinGroup.h
Go to the documentation of this file.
1 /* pinGroup.h
2 */
3 #ifndef _PINGROUP_H
4 #define _PINGROUP_H
5
6 #include "osl/rating/group.h"
7 #include "osl/rating/feature/pinAttack.h"
8
9 namespace osl
10 {
11 namespace rating
12 {
13 struct PinGroup : public Group
14 {
15 PinGroup() : Group("PinAttack")
16 {
17 for (int s = PTYPE_PIECE_MIN; s<= PTYPE_MAX; ++s) {
18 for (int t = PTYPE_PIECE_MIN; t<= PTYPE_MAX; ++t) {
19 const Ptype self = static_cast<Ptype>(s);
20 const Ptype target = static_cast<Ptype>(t);
21 for (int p=0; p<8; ++p) // progress8
22 push_back(new PinAttack(true, self, target));
23 for (int p=0; p<8; ++p) // progress8
24 push_back(new PinAttack(false, self, target));
25 }
26 }
27 }
28 void show(std::ostream& os, int name_width, const range_t& range,
29 const vector<double>& weights) const
30 {
31 showTopN(os, name_width, range, weights, 3);
32 }
33 int findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
34 {
35 const int progress8 = env.progress.value()/2;
36 const int attack_index = PinAttack::index(state, move, env, true);
37 if (attack_index >= 0)
38 return attack_index*8 + progress8;
39 const int defense_index = PinAttack::index(state, move, env, false);
40 if (defense_index >= 0)
41 return defense_index*8 + progress8;
42 return -1;
43 }
44 };
45
46 struct EscapePinGroup : public Group
47 {
48 EscapePinGroup() : Group("EscapePin")
49 {
50 for (int s = PTYPE_BASIC_MIN+1; s<= PTYPE_MAX; ++s) {
51 const Ptype self = static_cast<Ptype>(s);
52 for (int p=0; p<8; ++p) // progress8
53 push_back(new EscapePin(self));
54 }
55 }
56 void show(std::ostream& os, int name_width, const range_t& range,
57 const vector<double>& weights) const
58 {
59 showTopN(os, name_width, range, weights, 3);
60 }
61 int findMatch(const NumEffectState&, Move move, const RatingEnv& env) const
62 {
63 if (move.ptype() != KING || ! env.my_pin.any())
64 return -1;
65 int s;
66 for (s = PTYPE_BASIC_MIN+1; s<= PTYPE_MAX; ++s) {
67 const Ptype pinned = static_cast<Ptype>(s);
68 if ((env.my_pin.getMask(Ptype_Table.getIndex(pinned))
69 & Ptype_Table.getMaskLow(pinned)).any())
70 break;
71 }
72 s -= PTYPE_BASIC_MIN+1;
73 assert(s >= 0);
74 const int progress8 = env.progress.value()/2;
75 return s*8 + progress8;
76 }
77 };
78 }
79 }
80
81
82 #endif /* _PINGROUP_H */
83 // ;;; Local Variables:
84 // ;;; mode:c++
85 // ;;; c-basic-offset:2
86 // ;;; End: