pattern.cc
Go to the documentation of this file.
/* pattern.cc
*/
#include "osl/rating/feature/pattern.h"
#include <sstream>
const std::string osl::rating::Pattern::name(Direction d, Direction d2, Ptype self, Ptype target, bool same)
{
std::ostringstream os;
os << d;
if (d2 != Pattern::INVALID)
os << d2;
os << "-" << Ptype_Table.getCsaName(self) << "-"
<< Ptype_Table.getCsaName(target) << (same ? "=" : "!");
return os.str();
}
const std::string osl::rating::LongTarget::name() const
{
std::ostringstream os;
os << Ptype_Table.getCsaName(target)
<< (same ? "=" : "!") << (promotable ? "p" : "-");
return os.str() + CountEffect2::name(attack, defense);
}
const std::string osl::rating::LongTarget2::name() const
{
std::ostringstream os;
os << Ptype_Table.getCsaName(target)
<< (same ? "=" : "!");
return os.str();
}
osl::rating::
PatternLong::PatternLong(Direction d, Ptype s, LongTarget t)
: Feature(name(d, s)+"-"+t.name()), direction(d), self(s), target(t)
{
assert(unpromote(s) == LANCE || unpromote(s) == BISHOP || unpromote(s) == ROOK);
}
const osl::rating::PieceSquare osl::rating::
PatternLong::nextPieceOrEnd(const SimpleState& state, Square start, Offset diff)
{
Square cur = start;
assert(cur.isOnBoard());
assert(! diff.zero());
cur += diff;
while (state.pieceAt(cur) == Piece::EMPTY())
cur += diff;
const Piece p = state.pieceAt(cur);
if (! p.isEdge())
return std::make_pair(p, cur);
cur -= diff;
assert(cur.isOnBoard());
if (cur == start)
return std::make_pair(p, cur); // EDGE
return std::make_pair(state.pieceOnBoard(cur), cur); // EMPTY
}
const osl::rating::PieceSquare osl::rating::
PatternLong::nextPieceOrEnd(const SimpleState& state, Square start, Player player, Direction direction)
{
const Offset diff = Board_Table.getOffset(player, direction);
return nextPieceOrEnd(state, start, diff);
}
const osl::rating::PieceSquare osl::rating::
PatternLong::find(const NumEffectState& state, Move move, Direction direction)
{
PieceSquare p = nextPieceOrEnd(state, move.to(), move.player(), direction);
if (p.second == move.from())
p = nextPieceOrEnd(state, p.second, move.player(), direction);
return p;
}
const std::string osl::rating::PatternLong::name(Direction d, Ptype self)
{
std::ostringstream os;
os << d << "-" << Ptype_Table.getCsaName(self);
return os.str();
}
osl::rating::
PatternLong2::PatternLong2(Direction d, Ptype s, LongTarget2 t2)
: Feature(name(d, s)+"--"+t2.name()), direction(d), self(s), target2(t2)
{
assert(unpromote(s) == LANCE || unpromote(s) == BISHOP || unpromote(s) == ROOK);
}
const std::string osl::rating::
PatternLong2::name(Direction d, Ptype self)
{
std::ostringstream os;
os << d << "-" << Ptype_Table.getCsaName(self);
return os.str();
}
osl::rating::
PatternBlock::PatternBlock(Ptype s, Ptype a, LongTarget t)
: Feature(std::string(Ptype_Table.getCsaName(s))/*+"-"+Ptype_Table.getCsaName(a)+">"*/+t.name()),
self(s), attack(a), target(t)
{
}
const osl::rating::PieceSquare osl::rating::
PatternBlock::find(const NumEffectState& state, Move move, Ptype ap)
{
Piece attack;
if (ap == LANCE) {
attack = state.findAttackAt<LANCE>(alt(state.turn()), move.to());
if (attack.ptype() == LANCE)
return PatternLong::nextPieceOrEnd
(state, move.to(),
Board_Table.getShortOffset(Offset32(move.to(), attack.square())));
} else if (ap == BISHOP) {
attack = state.findAttackAt<BISHOP>(alt(state.turn()), move.to());
if (attack.isPiece())
return PatternLong::nextPieceOrEnd
(state, move.to(),
Board_Table.getShortOffset(Offset32(move.to(), attack.square())));
} else if (ap == ROOK) {
attack = state.findAttackAt<ROOK>(alt(state.turn()), move.to());
if (attack.isPiece())
return PatternLong::nextPieceOrEnd
(state, move.to(),
Board_Table.getShortOffset(Offset32(move.to(), attack.square())));
}
return std::make_pair(Piece::EDGE(), Square::STAND());
}
/* ------------------------------------------------------------------------- */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::Move
圧縮していない moveの表現 .
Definition basic_type.h:1052
osl::Move::player
Player player() const
Definition basic_type.h:1195
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::NumEffectState::findAttackAt
const Piece findAttackAt(Player attack, Square target) const
return a piece s.t.
Definition numEffectState.h:503
osl::Offset
座標の差分
Definition basic_type.h:430
osl::Offset::zero
bool zero() const
Definition basic_type.h:502
osl::Piece
駒.
Definition basic_type.h:788
osl::Piece::isEdge
bool isEdge() const
Definition basic_type.h:919
osl::Piece::EMPTY
static const Piece EMPTY()
Definition basic_type.h:797
osl::Piece::EDGE
static const Piece EDGE()
Definition basic_type.h:798
osl::SimpleState
Definition simpleState.h:35
osl::SimpleState::pieceOnBoard
const Piece pieceOnBoard(Square sq) const
Definition simpleState.h:170
osl::SimpleState::turn
Player turn() const
Definition simpleState.h:220
osl::SimpleState::pieceAt
const Piece pieceAt(Square sq) const
Definition simpleState.h:167
osl::Square
Definition basic_type.h:532
osl::Square::STAND
static const Square STAND()
Definition basic_type.h:548
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::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::name
static const std::string name(Direction d, Ptype self)
Definition pattern.cc:90
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::name
static const std::string name(Direction d, Ptype self)
Definition pattern.cc:74
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::find
static const PieceSquare find(const NumEffectState &state, Move move, Direction direction)
Definition pattern.cc:66
osl::rating::Pattern::same
bool same
Definition pattern.h:20
osl::rating::Pattern::INVALID
static const Direction INVALID
Definition pattern.h:16
osl::rating::Pattern::target
Ptype target
Definition pattern.h:19
osl::rating::Pattern::self
Ptype self
Definition pattern.h:19
osl::rating::PieceSquare
std::pair< Piece, Square > PieceSquare
Definition pattern.h:60
osl::Ptype
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
osl::ROOK
@ ROOK
Definition basic_type.h:100
osl::BISHOP
@ BISHOP
Definition basic_type.h:99
osl::LANCE
@ LANCE
Definition basic_type.h:96
osl::Ptype_Table
const PtypeTable Ptype_Table
Definition tables.cc:97
osl::unpromote
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に，promote前の型を返す． promoteしていない型の時はそのまま返す
Definition basic_type.h:157
osl::Board_Table
const BoardTable Board_Table
Definition tables.cc:95
osl::Direction
Direction
Definition basic_type.h:310
osl::Offset32
Offset32Base< 8, 9 > Offset32
Definition offset32.h:63
osl::Player
Player
Definition basic_type.h:8
osl::alt
constexpr Player alt(Player player)
Definition basic_type.h:13
std
Definition basic_type.h:1353
pattern.h
osl::rating::CountEffect2::attack
int attack
Definition countEffect2.h:17
osl::rating::CountEffect2::name
static std::string name(int attack, int defense)
Definition countEffect2.cc:9
osl::rating::CountEffect2::defense
int defense
Definition countEffect2.h:17
osl::rating::LongTarget2
Definition pattern.h:104
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::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::promotable
bool promotable
Definition pattern.h:64
osl::rating::LongTarget::name
const std::string name() const
Definition pattern.cc:17
osl::rating::LongTarget::target
Ptype target
Definition pattern.h:63