Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SgEvaluatedMoves.h

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file SgEvaluatedMoves.h
00003     Data structure for keeping move values.
00004 */
00005 //----------------------------------------------------------------------------
00006 
00007 #ifndef SG_EVALUATEDMOVES_H
00008 #define SG_EVALUATEDMOVES_H
00009 
00010 #include "SgPointSet.h"
00011 #include "SgVector.h"
00012 
00013 //----------------------------------------------------------------------------
00014 
00015 /** Simple data structure keeps a best move value and a list of all moves
00016     with that value.
00017     @todo  Originally worked with any SgMove, but introduction of SgPointSet
00018     relevant now requires SgMove=SgPoint. Should be made independent of that
00019     again, otherwise, why not merge with SgEvaluatedMovesArray?
00020 */
00021 class SgEvaluatedMoves
00022 {
00023 public:
00024     explicit SgEvaluatedMoves(const SgPointSet& relevant)
00025         : m_bestValue(s_minValue),
00026           m_relevant(relevant)
00027     { }
00028 
00029     SgEvaluatedMoves(const SgEvaluatedMoves& original)
00030         : m_bestValue(original.m_bestValue),
00031           m_moveList(original.m_moveList),
00032           m_relevant(original.m_relevant)
00033     { }
00034     
00035     virtual ~SgEvaluatedMoves()
00036     { }
00037 
00038     virtual void AddMove(SgPoint move, int value);
00039 
00040     virtual void AddMoves(const SgPointSet& moves, int value);
00041 
00042     virtual void AddMoves(const SgVector<SgPoint>& moves, int value);
00043 
00044     virtual void Clear()
00045     {
00046         m_bestValue = s_minValue;
00047         m_moveList.Clear();
00048     }
00049 
00050     SgPoint BestMove();
00051 
00052     int BestValue()
00053     {
00054         return m_bestValue;
00055     }
00056 
00057     const SgPointSet& Relevant() const
00058     {
00059         return m_relevant;
00060     }
00061 
00062     bool IsRelevant(SgPoint p) const
00063     {
00064         return m_relevant[p];
00065     }
00066 
00067     void Disable(SgPoint p)
00068     {
00069         m_relevant.Exclude(p);
00070     }
00071 
00072     void Enable(SgPoint p)
00073     {
00074         m_relevant.Include(p);
00075     }
00076 
00077     virtual SgEvaluatedMoves* Duplicate() const
00078     {
00079         return new SgEvaluatedMoves(*this);
00080     }
00081 
00082     virtual int GetEvaluation(SgPoint p) const
00083     {
00084         if (m_moveList.Contains(p))
00085             return m_bestValue;
00086         else
00087             return 0;
00088     }
00089 
00090     /** Compute list of the n best moves. */
00091     virtual void BestMoves(SgVector<SgPoint>& best, int nuMoves) const;
00092 
00093 protected:
00094     int m_bestValue;
00095 
00096     SgVector<SgPoint> m_moveList;
00097 
00098     SgPointSet m_relevant;
00099 
00100     // DS: INT_MIN is sometimes used to mark illegal moves
00101     static const int s_minValue = INT_MIN + 1;
00102 };
00103 
00104 //----------------------------------------------------------------------------
00105 
00106 /** Simple data structure keeps an integer value for each point on a board.
00107     @todo better name: SgEvaluatedPoints?
00108 */
00109 class SgEvaluatedMovesArray
00110     : public SgEvaluatedMoves
00111 {
00112 public:
00113     explicit SgEvaluatedMovesArray(const SgPointSet& relevant,
00114                                    int boardSize = SG_MAX_SIZE);
00115 
00116     virtual ~SgEvaluatedMovesArray()
00117     { }
00118 
00119     SgEvaluatedMovesArray(const SgEvaluatedMovesArray& original)
00120         : SgEvaluatedMoves(original),
00121           m_boardSize(original.m_boardSize)
00122     {
00123         for (int i = 0; i < SG_MAXPOINT; ++i)
00124             m_value[i] = original.m_value[i];
00125     }
00126 
00127     virtual void AddMove(SgPoint move, int value);
00128 
00129     virtual void ReduceMove(SgPoint move, int value);
00130 
00131     virtual void Clear();
00132 
00133     void Write() const;
00134 
00135     virtual SgEvaluatedMoves* Duplicate() const
00136     {
00137         return new SgEvaluatedMovesArray(*this);
00138     }
00139 
00140     virtual int GetEvaluation(SgPoint p) const
00141     {
00142         return m_value[p];
00143     }
00144 
00145     virtual void BestMoves(SgVector<SgPoint>& best, int nuMoves) const;
00146 
00147 private:
00148     int m_value[SG_MAXPOINT];
00149 
00150     int m_boardSize;
00151 
00152     SgPoint SelectNextBest(SgVector<SgPoint>& bestSoFar) const;
00153 };
00154 
00155 //----------------------------------------------------------------------------
00156 
00157 #endif // SG_EVALUATEDMOVES_H


17 Jun 2010 Doxygen 1.4.7