pattern.h
Go to the documentation of this file.
/* patternLong2.h
*/
#ifndef _PATTERNLONG2_H
#define _PATTERNLONG2_H
#include "osl/rating/feature.h"
#include "osl/rating/feature/countEffect2.h"
namespace osl
{
namespace rating
{
class Pattern : public Feature, CountEffect2
{
public:
static const Direction INVALID = LONG_UL;
private:
Direction direction, direction2;
Ptype self, target;
bool same;
static const std::string name(Direction d, Direction d2, Ptype self, Ptype target, bool same);
public:
Pattern(Direction d, Ptype s, Ptype t, bool ss, int attack, int defense)
: Feature(name(d, INVALID, s, t, ss)+CountEffect2::name(attack, defense)), CountEffect2(attack, defense),
direction(d), direction2(INVALID), self(s), target(t), same(ss)
{
}
Pattern(Direction d, Direction d2, Ptype s, Ptype t, bool ss, int attack, int defense)
: Feature(name(d, d2, s, t, ss)+CountEffect2::name(attack, defense)), CountEffect2(attack, defense),
direction(d), direction2(d2), self(s), target(t), same(ss)
{
}
static Square nextSquare(Player player, Square start, Direction direction, Direction direction2)
{
const Square p = Board_Table.nextSquare(player, start, direction);
if (direction2 == INVALID || ! p.isOnBoard())
return p;
return Board_Table.nextSquare(player, p, direction2);
}
static Square nextSquare(Move move, Direction direction, Direction direction2)
{
return nextSquare(move.player(), move.to(), direction, direction2);
}
bool match(const NumEffectState& state, Move move, const RatingEnv& env) const
{
if (move.ptype() != self)
return false;
const Square position = nextSquare(move, direction, direction2);
const Piece p = (position == move.from()) ? Piece::EMPTY() : state.pieceAt(position);
if (p.ptype() != target)
return false;
if (! CountEffect2::match(state, position, env))
return false;
if (!isPiece(target))
return true;
return same == (p.owner() == move.player());
}
};
typedef std::pair<Piece,Square> PieceSquare;
struct LongTarget : CountEffect2
{
Ptype target;
bool promotable, same;
LongTarget(Ptype t, bool p, bool s, int attack, int defense)
: CountEffect2(attack, defense), target(t), promotable(p), same(s)
{
}
static bool isPromotable(Move move, Square position)
{
assert(position.isOnBoard());
return position.canPromote(move.player()) || (! move.isDrop() && move.to().canPromote(move.player()));
}
bool match(const NumEffectState& state, Move move, PieceSquare p, const RatingEnv& env) const
{
if (p.first.ptype() != target)
return false;
if (target == PTYPE_EDGE)
return true;
if (isPromotable(move, p.second) != promotable)
return false;
if (! CountEffect2::match(state, p.second, env))
return false;
if (! p.first.isPiece())
return true;
return same == (p.first.owner() == move.player());
}
bool matchOtherThanPromotable(const NumEffectState& state, Move move, PieceSquare p, const RatingEnv& env) const
{
if (p.first.ptype() != target)
return false;
if (target == PTYPE_EDGE)
return true;
if (! CountEffect2::match(state, p.second, env))
return false;
if (! p.first.isPiece())
return true;
return same == (p.first.owner() == move.player());
}
const std::string name() const;
};
struct LongTarget2
{
Ptype target;
bool same;
LongTarget2(Ptype t, bool s) : target(t), same(s)
{
}
bool match(const NumEffectState&, Move move, Piece p) const
{
if (p.ptype() != target)
return false;
assert(! p.isEmpty());
if (! isPiece(target))
return true;
return same == (p.owner() == move.player());
}
const std::string name() const;
};
class PatternLong : public Feature
{
Direction direction;
Ptype self;
LongTarget target;
static const std::string name(Direction d, Ptype self);
public:
PatternLong(Direction d, Ptype s, LongTarget t);
static const PieceSquare nextPieceOrEnd(const SimpleState& state, Square start, Player player, Direction direction);
static const PieceSquare nextPieceOrEnd(const SimpleState& state, Square start, Offset);
static const PieceSquare find(const NumEffectState& state, Move move, Direction direction);
bool match(const NumEffectState& state, Move move, const RatingEnv& env) const
{
if (move.ptype() != self)
return false;
PieceSquare pp = find(state, move, direction);
return target.match(state, move, pp, env);
}
};
class PatternLong2 : public Feature
{
Direction direction;
Ptype self;
LongTarget2 target2;
static const std::string name(Direction d, Ptype self);
public:
PatternLong2(Direction d, Ptype s, LongTarget2 t2);
static const Piece find(const NumEffectState& state, Move move, Direction direction)
{
Piece p = state.nextPiece(move.to(), Board_Table.getOffset(move.player(), direction));
if (p.isPiece() && p.square() == move.from())
p = state.nextPiece(move.to(), Board_Table.getOffset(move.player(), direction));
return p;
}
bool match(const NumEffectState& state, Move move, const RatingEnv&) const
{
if (move.ptype() != self)
return false;
const Piece p = find(state, move, direction);
return target2.match(state, move, p);
}
};
class PatternBlock : public Feature
{
Ptype self, attack;
LongTarget target;
public:
PatternBlock(Ptype s, Ptype a, LongTarget t);
static const PieceSquare find(const NumEffectState& state, Move move, Ptype attacker_ptype);
bool match(const NumEffectState& state, Move move, const RatingEnv& env) const
{
if (move.ptype() != self)
return false;
PieceSquare pp = find(state, move, attack);
return ! pp.first.isEdge() && target.matchOtherThanPromotable(state, move, pp, env)
&& pp.second.canPromote(pp.first.isPiece() ? alt(pp.first.owner()) : alt(move.player()))
== target.promotable;
}
};
}
}
#endif /* _PATTERNLONG2_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::Move
圧縮していない moveの表現 .
Definition basic_type.h:1052
osl::Move::ptype
Ptype ptype() const
Definition basic_type.h:1155
osl::Move::player
Player player() const
Definition basic_type.h:1195
osl::Move::isDrop
bool isDrop() const
Definition basic_type.h:1150
osl::Move::to
const Square to() const
Definition basic_type.h:1132
osl::Move::from
const Square from() const
Definition basic_type.h:1125
osl::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
osl::Offset
座標の差分
Definition basic_type.h:430
osl::Piece
駒.
Definition basic_type.h:788
osl::Piece::ptype
Ptype ptype() const
Definition basic_type.h:821
osl::Piece::square
const Square square() const
Definition basic_type.h:832
osl::Piece::isEmpty
bool isEmpty() const
Definition basic_type.h:913
osl::Piece::owner
Player owner() const
Definition basic_type.h:963
osl::Piece::isPiece
bool isPiece() const
Definition basic_type.h:953
osl::Piece::EMPTY
static const Piece EMPTY()
Definition basic_type.h:797
osl::SimpleState
Definition simpleState.h:35
osl::SimpleState::nextPiece
Piece nextPiece(Square cur, Offset diff) const
diff方向にあるPiece を求める.
Definition simpleState.h:208
osl::SimpleState::pieceAt
const Piece pieceAt(Square sq) const
Definition simpleState.h:167
osl::Square
Definition basic_type.h:532
osl::Square::canPromote
bool canPromote() const
Definition basic_type.h:659
osl::Square::isOnBoard
bool isOnBoard() const
盤面上を表すかどうかの判定． 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する．
Definition basic_type.h:583
osl::rating::Feature::Feature
Feature(const std::string &name)
Definition rating/feature.h:18
osl::rating::Feature::name
const std::string & name() const
Definition rating/feature.h:24
osl::rating::PatternBlock::attack
Ptype attack
Definition pattern.h:175
osl::rating::PatternBlock::target
LongTarget target
Definition pattern.h:176
osl::rating::PatternBlock::PatternBlock
PatternBlock(Ptype s, Ptype a, LongTarget t)
Definition pattern.cc:98
osl::rating::PatternBlock::match
bool match(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition pattern.h:180
osl::rating::PatternBlock::find
static const PieceSquare find(const NumEffectState &state, Move move, Ptype attacker_ptype)
Definition pattern.cc:105
osl::rating::PatternBlock::self
Ptype self
Definition pattern.h:175
osl::rating::PatternLong2::PatternLong2
PatternLong2(Direction d, Ptype s, LongTarget2 t2)
Definition pattern.cc:83
osl::rating::PatternLong2::find
static const Piece find(const NumEffectState &state, Move move, Direction direction)
Definition pattern.h:157
osl::rating::PatternLong2::match
bool match(const NumEffectState &state, Move move, const RatingEnv &) const
Definition pattern.h:164
osl::rating::PatternLong2::self
Ptype self
Definition pattern.h:152
osl::rating::PatternLong2::target2
LongTarget2 target2
Definition pattern.h:153
osl::rating::PatternLong2::direction
Direction direction
Definition pattern.h:151
osl::rating::PatternLong::target
LongTarget target
Definition pattern.h:126
osl::rating::PatternLong::self
Ptype self
Definition pattern.h:125
osl::rating::PatternLong::PatternLong
PatternLong(Direction d, Ptype s, LongTarget t)
Definition pattern.cc:33
osl::rating::PatternLong::direction
Direction direction
Definition pattern.h:124
osl::rating::PatternLong::nextPieceOrEnd
static const PieceSquare nextPieceOrEnd(const SimpleState &state, Square start, Player player, Direction direction)
direction方向に空白を進み、駒を探す
Definition pattern.cc:59
osl::rating::PatternLong::match
bool match(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition pattern.h:140
osl::rating::PatternLong::find
static const PieceSquare find(const NumEffectState &state, Move move, Direction direction)
Definition pattern.cc:66
osl::rating::Pattern::nextSquare
static Square nextSquare(Player player, Square start, Direction direction, Direction direction2)
Definition pattern.h:33
osl::rating::Pattern::direction
Direction direction
Definition pattern.h:18
osl::rating::Pattern::Pattern
Pattern(Direction d, Ptype s, Ptype t, bool ss, int attack, int defense)
Definition pattern.h:23
osl::rating::Pattern::same
bool same
Definition pattern.h:20
osl::rating::Pattern::nextSquare
static Square nextSquare(Move move, Direction direction, Direction direction2)
Definition pattern.h:40
osl::rating::Pattern::INVALID
static const Direction INVALID
Definition pattern.h:16
osl::rating::Pattern::Pattern
Pattern(Direction d, Direction d2, Ptype s, Ptype t, bool ss, int attack, int defense)
Definition pattern.h:28
osl::rating::Pattern::match
bool match(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition pattern.h:44
osl::rating::Pattern::name
static const std::string name(Direction d, Direction d2, Ptype self, Ptype target, bool same)
Definition pattern.cc:6
osl::rating::Pattern::target
Ptype target
Definition pattern.h:19
osl::rating::Pattern::direction2
Direction direction2
Definition pattern.h:18
osl::rating::Pattern::self
Ptype self
Definition pattern.h:19
osl::rating::RatingEnv
Definition ratingEnv.h:16
countEffect2.h
osl::rating
Definition construct.h:18
osl::rating::PieceSquare
std::pair< Piece, Square > PieceSquare
Definition pattern.h:60
osl
Definition additionalEffect.h:6
osl::Ptype
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
osl::PTYPE_EDGE
@ PTYPE_EDGE
Definition basic_type.h:86
osl::Board_Table
const BoardTable Board_Table
Definition tables.cc:95
osl::Direction
Direction
Definition basic_type.h:310
osl::LONG_UL
@ LONG_UL
Definition basic_type.h:325
osl::Player
Player
Definition basic_type.h:8
osl::isPiece
constexpr bool isPiece(Ptype ptype)
ptypeが空白やEDGEでないかのチェック
Definition basic_type.h:120
osl::alt
constexpr Player alt(Player player)
Definition basic_type.h:13
feature.h
osl::rating::CountEffect2::CountEffect2
CountEffect2(int a, int d)
Definition countEffect2.h:18
osl::rating::CountEffect2::match
bool match(const NumEffectState &state, Square position, const RatingEnv &env) const
Definition countEffect2.h:37
osl::rating::CountEffect2::attack
int attack
Definition countEffect2.h:17
osl::rating::CountEffect2::defense
int defense
Definition countEffect2.h:17
osl::rating::LongTarget2
Definition pattern.h:104
osl::rating::LongTarget2::LongTarget2
LongTarget2(Ptype t, bool s)
Definition pattern.h:107
osl::rating::LongTarget2::name
const std::string name() const
Definition pattern.cc:24
osl::rating::LongTarget2::same
bool same
Definition pattern.h:106
osl::rating::LongTarget2::match
bool match(const NumEffectState &, Move move, Piece p) const
Definition pattern.h:110
osl::rating::LongTarget2::target
Ptype target
Definition pattern.h:105
osl::rating::LongTarget
Definition pattern.h:62
osl::rating::LongTarget::same
bool same
Definition pattern.h:64
osl::rating::LongTarget::matchOtherThanPromotable
bool matchOtherThanPromotable(const NumEffectState &state, Move move, PieceSquare p, const RatingEnv &env) const
Definition pattern.h:88
osl::rating::LongTarget::isPromotable
static bool isPromotable(Move move, Square position)
Definition pattern.h:69
osl::rating::LongTarget::match
bool match(const NumEffectState &state, Move move, PieceSquare p, const RatingEnv &env) const
Definition pattern.h:74
osl::rating::LongTarget::promotable
bool promotable
Definition pattern.h:64
osl::rating::LongTarget::LongTarget
LongTarget(Ptype t, bool p, bool s, int attack, int defense)
Definition pattern.h:65
osl::rating::LongTarget::name
const std::string name() const
Definition pattern.cc:17
osl::rating::LongTarget::target
Ptype target
Definition pattern.h:63