alphaBeta3.h
Go to the documentation of this file.
00001 /* alphaBeta3.h
00002  */
00003 #ifndef OSL_ALPHABETA3_H
00004 #define OSL_ALPHABETA3_H
00005 #include "osl/state/numEffectState.h"
00006 #include "osl/search/searchTimer.h"
00007 #include "osl/search/fixedEval.h"
00008 // temporal
00009 #include "osl/search/searchState2.h"
00010 #include "osl/eval/ml/openMidEndingEval.h"
00011 #include "osl/eval/progressEval.h"
00012 #include "osl/container/moveVector.h"
00013 
00014 namespace osl
00015 {
00016   namespace search
00017   {
00018     class CountRecorder;
00019     class SimpleHashTable;
00020     struct MoveWithComment;
00021     class AlphaBeta3 : public SearchTimer, FixedEval
00022     {
00023     public:
00024       // interface required for game_playing::SearchPlayer
00025       typedef SearchState2::checkmate_t checkmate_t;
00026       typedef eval::ml::OpenMidEndingEval eval_t;
00027       // typedef eval::PieceEval eval_t;
00028       // typedef eval::ProgressEval eval_t;
00029       AlphaBeta3(const NumEffectState& s, checkmate_t& checker,
00030                  SimpleHashTable *t, CountRecorder&);
00031       ~AlphaBeta3();
00032       Move computeBestMoveIteratively(int limit, int step, 
00033                                       int initial_limit=600,
00034                                       size_t node_limit=1600000,
00035                                       const TimeAssigned& assign=TimeAssigned(MilliSeconds::Interval(60*1000)),
00036                                       MoveWithComment *additional_info=0);
00037       bool isReasonableMove(Move move, int pawn_sacrifice=1);
00038       void setRootIgnoreMoves(const MoveVector *rim, bool);
00039       void setHistory(const MoveStack& h);
00040       void enableMultiPV(unsigned int) {}
00041 
00042       static void showNodeDepth(std::ostream&);
00043       static void clearNodeDepth();
00044 
00045       // original staff
00046       enum MoveCategory { Initial, KingEscape, Pass, TakeBack, Capture, Killer, CaptureAll, All };
00047       enum { MaxDepth = 64 };
00048       enum NodeType { PvNode = 0, CutNode = 1, AllNode = -1 };
00049       struct SearchInfo;
00050       struct PVInfo
00051       {
00052         Move move;
00053         int height;
00054         bool in_check;
00055       };
00056       struct PVVector : public FixedCapacityVector<PVInfo,MaxDepth> 
00057       {
00058         void setPV(Move m, const SearchInfo&, const PVVector&);
00059       };
00060       struct SearchInfo
00061       {
00062         SearchInfo();
00063         // input
00064         // (modified: alpha, node_type, eval)
00065         Move moved;
00066         HashKey hash_key;
00067         PathEncoding path;
00068         int height, extended;
00069         int alpha, beta;
00070         NodeType node_type;
00071         eval_t eval;            // before moved
00072         // output
00073         int search_value;
00074         int moves_tried;
00075         bool in_check;
00076         PVVector pv;
00077         // work area
00078         MoveVector moves;
00079         MoveCategory move_type;
00080         unsigned int move_index;
00081       };
00082     private:
00083       template <Player P> struct CallSearch;
00084       template <Player P> struct CallQuiesce;
00085       friend struct CallSearch<BLACK>;
00086       friend struct CallSearch<WHITE>;
00087       friend struct CallQuiesce<BLACK>;
00088       friend struct CallQuiesce<WHITE>;
00089       Move searchRoot(int limit);
00090       template <Player P> int makeMoveAndSearch(Move, int consume);
00091       template <Player P> void presearch();
00092       template <Player P> void search();
00093       template <Player P> Move nextMove();
00094       template <Player P> void quiesceRoot();
00095       template <Player P> int makeMoveAndQuiesce(Move);
00096       template <Player P> void quiesce();
00097     private:
00098       volatile int stop_by_alarm;
00099       NumEffectState state;
00100       int depth;
00101       CountRecorder& recorder;
00102       SimpleHashTable *table_common;
00103     public: // public for test
00104       template <Player P>
00105       static void generateAllMoves(const NumEffectState& state, const SearchInfo&, SearchInfo&);
00106       template <Player P>
00107       static void generateCapture(const NumEffectState& state, SearchInfo&);
00108       template <Player P>
00109       static void generateCaptureAll(const NumEffectState& state, SearchInfo&);
00110       template <Player P>      
00111       static bool seePlusLight(const NumEffectState& state, Move m);
00112     private:
00113       bool reductionOk() const;
00114       int evalValue() const;
00115     };
00116     
00117   }
00118   using search::AlphaBeta3;
00119 }
00120 
00121 #endif /* OSL_ALPHABETA3_H */
00122 // ;;; Local Variables:
00123 // ;;; mode:c++
00124 // ;;; c-basic-offset:2
00125 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines