00001
00002
00003 #include "osl/rating/feature/pattern.h"
00004 #include <sstream>
00005
00006 const std::string osl::rating::Pattern::name(Direction d, Direction d2, Ptype self, Ptype target, bool same)
00007 {
00008 std::ostringstream os;
00009 os << d;
00010 if (d2 != Pattern::INVALID)
00011 os << d2;
00012 os << "-" << Ptype_Table.getCsaName(self) << "-"
00013 << Ptype_Table.getCsaName(target) << (same ? "=" : "!");
00014 return os.str();
00015 }
00016
00017 const std::string osl::rating::LongTarget::name() const
00018 {
00019 std::ostringstream os;
00020 os << Ptype_Table.getCsaName(target)
00021 << (same ? "=" : "!") << (promotable ? "p" : "-");
00022 return os.str() + CountEffect2::name(attack, defense);
00023 }
00024 const std::string osl::rating::LongTarget2::name() const
00025 {
00026 std::ostringstream os;
00027 os << Ptype_Table.getCsaName(target)
00028 << (same ? "=" : "!");
00029 return os.str();
00030 }
00031
00032 osl::rating::
00033 PatternLong::PatternLong(Direction d, Ptype s, LongTarget t)
00034 : Feature(name(d, s)+"-"+t.name()), direction(d), self(s), target(t)
00035 {
00036 assert(unpromote(s) == LANCE || unpromote(s) == BISHOP || unpromote(s) == ROOK);
00037 }
00038
00039 const osl::rating::PiecePosition osl::rating::
00040 PatternLong::nextPieceOrEnd(const SimpleState& state, Position start, Player player, Offset diff)
00041 {
00042 Position cur = start;
00043 assert(cur.isOnBoard());
00044 assert(! diff.zero());
00045 cur += diff;
00046 while (state.getPieceAt(cur) == Piece::EMPTY())
00047 cur += diff;
00048 const Piece p = state.getPieceAt(cur);
00049 if (! p.isEdge())
00050 return std::make_pair(p, cur);
00051 cur -= diff;
00052 assert(cur.isOnBoard());
00053 if (cur == start)
00054 return std::make_pair(p, cur);
00055 return std::make_pair(state.getPieceOnBoard(cur), cur);
00056 }
00057
00058 const osl::rating::PiecePosition osl::rating::
00059 PatternLong::nextPieceOrEnd(const SimpleState& state, Position start, Player player, Direction direction)
00060 {
00061 const Offset diff = Board_Table.getOffset(player, direction);
00062 return nextPieceOrEnd(state, start, player, diff);
00063 }
00064
00065 const osl::rating::PiecePosition osl::rating::
00066 PatternLong::find(const NumEffectState& state, Move move, Direction direction)
00067 {
00068 PiecePosition p = nextPieceOrEnd(state, move.to(), move.player(), direction);
00069 if (p.second == move.from())
00070 p = nextPieceOrEnd(state, p.second, move.player(), direction);
00071 return p;
00072 }
00073
00074 const std::string osl::rating::PatternLong::name(Direction d, Ptype self)
00075 {
00076 std::ostringstream os;
00077 os << d << "-" << Ptype_Table.getCsaName(self);
00078 return os.str();
00079 }
00080
00081
00082 osl::rating::
00083 PatternLong2::PatternLong2(Direction d, Ptype s, LongTarget2 t2)
00084 : Feature(name(d, s)+"--"+t2.name()), direction(d), self(s), target2(t2)
00085 {
00086 assert(unpromote(s) == LANCE || unpromote(s) == BISHOP || unpromote(s) == ROOK);
00087 }
00088
00089 const std::string osl::rating::
00090 PatternLong2::name(Direction d, Ptype self)
00091 {
00092 std::ostringstream os;
00093 os << d << "-" << Ptype_Table.getCsaName(self);
00094 return os.str();
00095 }
00096
00097 osl::rating::
00098 PatternBlock::PatternBlock(Ptype s, Ptype a, LongTarget t)
00099 : Feature(std::string(Ptype_Table.getCsaName(s))+t.name()),
00100 self(s), attack(a), target(t)
00101 {
00102 }
00103
00104 const osl::rating::PiecePosition osl::rating::
00105 PatternBlock::find(const NumEffectState& state, Move move, Ptype ap)
00106 {
00107 Piece attack;
00108 if (ap == LANCE) {
00109 attack = state.effectPtype<LANCE>(alt(state.getTurn()), move.to());
00110 if (attack.ptype() == LANCE)
00111 return PatternLong::nextPieceOrEnd
00112 (state, move.to(), move.player(),
00113 Board_Table.getShortOffset(Offset32(move.to(), attack.position())));
00114 } else if (ap == BISHOP) {
00115 attack = state.effectPtype<BISHOP>(alt(state.getTurn()), move.to());
00116 if (attack.isPiece())
00117 return PatternLong::nextPieceOrEnd
00118 (state, move.to(), move.player(),
00119 Board_Table.getShortOffset(Offset32(move.to(), attack.position())));
00120 } else if (ap == ROOK) {
00121 attack = state.effectPtype<ROOK>(alt(state.getTurn()), move.to());
00122 if (attack.isPiece())
00123 return PatternLong::nextPieceOrEnd
00124 (state, move.to(), move.player(),
00125 Board_Table.getShortOffset(Offset32(move.to(), attack.position())));
00126 }
00127 return std::make_pair(Piece::EDGE(), Position::STAND());
00128 }
00129
00130
00131
00132
00133
00134