Go to the documentation of this file.00001
00002
00003 #ifndef OSL_MOVE_PROBABILITY_STATEINFO_H
00004 #define OSL_MOVE_PROBABILITY_STATEINFO_H
00005
00006 #include "osl/move_probability/pinnedGeneral.h"
00007 #include "osl/state/numEffectState.h"
00008 #include "osl/checkmate/king8Info.h"
00009 #include "osl/progress/progress16.h"
00010 #include "osl/stl/vector.h"
00011 #include "osl/misc/fixedCapacityVector.h"
00012 #include "osl/container/square8.h"
00013 #include "osl/container/moveStack.h"
00014 #include "osl/container/pieceVector.h"
00015 #include <algorithm>
00016
00017 namespace osl
00018 {
00019 namespace move_probability
00020 {
00021 struct StateInfo
00022 {
00023 const NumEffectState *state;
00024 const MoveStack *history;
00025 Progress16 progress16;
00026 PieceVector pin_by_opposing_sliders, king8_long_pieces;
00027 CArray<Piece,2> threatened;
00028 typedef FixedCapacityVector<int,8> long_attack_t;
00029 CArray2d<long_attack_t,40,8> long_attack_cache;
00030 typedef CArray<int,16> pattern_square_t;
00031 CArray<pattern_square_t,Square::SIZE> pattern_cache;
00032 CArray2d<bool,40,2> attack_shadow;
00033 PieceMask last_add_effect;
00034 Ptype last_move_ptype5;
00035 CArray<PieceMask,2> pin;
00036 Move threatmate_move;
00037 Square8 sendoffs;
00038 typedef FixedCapacityVector<PinnedGeneral,64> pinned_gs_t;
00039 CArray<pinned_gs_t,2> exchange_pins;
00040 CArray<bool,2> move_candidate_exists;
00041 mutable NumEffectState copy;
00042 BoardMask changed_effects;
00043 CArray<std::pair<Piece,Square>,2> checkmate_defender;
00044 unsigned int possible_threatmate_ptype;
00045 CArray<Move,2> bookmove;
00046 bool dirty;
00047
00048 StateInfo() : state(0), history(0), progress16(0), dirty(true)
00049 {
00050 }
00051 StateInfo(const NumEffectState& s, Progress16 p, const MoveStack& h,
00052 Move t=Move())
00053 : state(&s), history(&h), progress16(p), dirty(true)
00054 {
00055 clearOldCache();
00056 threatmate_move = t;
00057 finishUpdate();
00058 }
00059 void reset0(const NumEffectState& s, Progress16 p)
00060 {
00061 dirty = true;
00062 state = &s;
00063 progress16 = p;
00064 pin_by_opposing_sliders.clear();
00065 king8_long_pieces.clear();
00066 long_attack_cache.fill(long_attack_t());
00067 clearOldCache();
00068 }
00069 void reset1(const MoveStack& h)
00070 {
00071 history = &h;
00072 }
00073 void finishUpdate();
00074 void reset(const NumEffectState& s, Progress16 p,
00075 const MoveStack& h, Move threatmate_move=Move())
00076 {
00077 reset0(s, p);
00078 reset1(h);
00079 setThreatmate(threatmate_move);
00080 finishUpdate();
00081 }
00082 void setThreatmate(Move move) { threatmate_move = move; }
00083
00084 bool pinByOpposingSliders(Piece p) const
00085 {
00086 return std::find(pin_by_opposing_sliders.begin(), pin_by_opposing_sliders.end(),
00087 p) != pin_by_opposing_sliders.end();
00088 }
00089 King8Info king8Info(Player pl) const
00090 {
00091 return King8Info(state->Iking8Info(pl));
00092 }
00093 int progress8() const { return progress16.value()/2; }
00094 static std::pair<Piece,Square> findCheckmateDefender(const NumEffectState& state, Player king);
00095 static Move findShortThreatmate(const NumEffectState&, Move last_move);
00096 private:
00097 void clearOldCache();
00098 void updateDelayed();
00099 void makePinOfLongPieces();
00100 void makeLongAttacks();
00101 void updatePinnedGenerals(Player owner);
00102 };
00103 bool operator==(const StateInfo& l, const StateInfo& r);
00104 }
00105 }
00106
00107 #endif
00108
00109
00110
00111