king8Group.cc Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
king8Group.cc
Go to the documentation of this file.
1 /* king8Group.cc
2 */
3 #include "osl/rating/group/king8Group.h"
4 #include <sstream>
5
6 osl::rating::AttackKing8Group::AttackKing8Group()
7 : Group("AttackKing8")
8 {
9 for (int attack=0; attack<3; ++attack) {
10 for (int defense=0; defense<3; ++defense) {
11 for (int s=PTYPE_PIECE_MIN; s<= PTYPE_MAX; ++s) {
12 for (int t=PTYPE_PIECE_MIN; t<= PTYPE_MAX; ++t) {
13 for (int p=0; p<8; ++p) // progress8
14 push_back(new AttackKing8(static_cast<Ptype>(s), static_cast<Ptype>(t), true, attack, defense));
15 for (int p=0; p<8; ++p) // progress8
16 push_back(new AttackKing8(static_cast<Ptype>(s), static_cast<Ptype>(t), false, attack, defense));
17 }
18 for (int p=0; p<8; ++p) // progress8
19 push_back(new AttackKing8(static_cast<Ptype>(s), PTYPE_EMPTY, true, attack, defense));
20 }
21 }
22 }
23 }
24
25 int osl::rating::AttackKing8Group::findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
26 {
27 const Ptype self = move.ptype();
28 const Square position
29 = Neighboring8Direct::findNearest(state, move.ptypeO(), move.to(),
30 state.kingSquare(alt(state.turn())));
31 if (position.isPieceStand() || position == move.from())
32 return -1;
33 if (! move.isDrop() && state.hasEffectByPiece(state.pieceOnBoard(move.from()), position))
34 return -1;
35 const Piece p = state.pieceAt(position);
36 const Ptype target = p.ptype();
37 const int base = CountEffect2::index(state, position, env)
38 * (PTYPE_MAX+1 - PTYPE_PIECE_MIN) * ((PTYPE_MAX+1 - PTYPE_PIECE_MIN)*2 +1);
39
40 const int self_index = self - PTYPE_PIECE_MIN;
41
42 int index = base + self_index*((PTYPE_MAX+1 - PTYPE_PIECE_MIN)*2 +1);
43 if (!isPiece(target)) {
44 index += (PTYPE_MAX+1 - PTYPE_PIECE_MIN)*2;
45 }
46 else {
47 index += (target - PTYPE_PIECE_MIN)*2 + (p.owner() != move.player());
48 }
49
50 const int progress8 = env.progress.value()/2;
51 return index*8 + progress8;
52 }
53
54 osl::rating::DefenseKing8Group::DefenseKing8Group()
55 : Group("DefenseKing8")
56 {
57 for (int danger=0; danger<=4; ++danger) {
58 for (int s=PTYPE_PIECE_MIN; s<= PTYPE_MAX; ++s) {
59 for (int p=0; p<8; ++p) // progress8
60 push_back(new DefenseKing8(static_cast<Ptype>(s), true, danger));
61 for (int p=0; p<8; ++p) // progress8
62 push_back(new DefenseKing8(static_cast<Ptype>(s), false, danger));
63 }
64 }
65 }
66
67 int osl::rating::DefenseKing8Group::findMatch(const NumEffectState& state, Move move, const RatingEnv& env) const
68 {
69 assert(env.attack_count_for_turn == DefenseKing8::count(state));
70 const int self_index = (move.ptype() - PTYPE_PIECE_MIN)*2;
71 int index;
72 if (DefenseKing8::matchDrop(state, move))
73 index = env.attack_count_for_turn*(PTYPE_MAX+1-PTYPE_PIECE_MIN)*2 + self_index;
74 else if (DefenseKing8::matchMove(state, move))
75 index = env.attack_count_for_turn*(PTYPE_MAX+1-PTYPE_PIECE_MIN)*2 + self_index + 1;
76 else
77 return -1;
78 const int progress8 = env.progress.value()/2;
79 return index*8 + progress8;
80 }
81
82 /* ------------------------------------------------------------------------- */
83 // ;;; Local Variables:
84 // ;;; mode:c++
85 // ;;; c-basic-offset:2
86 // ;;; End: