Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

HexState.hpp

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file HexState.hpp
00003  */
00004 //----------------------------------------------------------------------------
00005 
00006 #ifndef HEXSTATE_H
00007 #define HEXSTATE_H
00008 
00009 #include "Hex.hpp"
00010 #include "StoneBoard.hpp"
00011 
00012 _BEGIN_BENZENE_NAMESPACE_
00013 
00014 //----------------------------------------------------------------------------
00015 
00016 /** Board position paired with a color to play. */
00017 class HexState
00018 {
00019 public:
00020     HexState();
00021 
00022     HexState(unsigned size);
00023 
00024     HexState(const StoneBoard& brd, HexColor toPlay);
00025 
00026     StoneBoard& Position();
00027 
00028     const StoneBoard& Position() const;
00029 
00030     void SetToPlay(HexColor color);
00031 
00032     HexColor ToPlay() const;
00033 
00034     hash_t Hash() const;
00035 
00036     void PlayMove(HexPoint move);
00037     
00038     void UndoMove(HexPoint move);
00039 
00040 private:
00041     StoneBoard m_brd;
00042 
00043     HexColor m_toPlay;
00044 
00045     void FlipColorToPlay();
00046 };
00047 
00048 inline HexState::HexState()
00049 {
00050 }
00051 
00052 inline HexState::HexState(unsigned size)
00053     : m_brd(size),
00054       m_toPlay(m_brd.WhoseTurn())
00055 {
00056 }
00057 
00058 inline HexState::HexState(const StoneBoard& brd, HexColor toPlay)
00059     : m_brd(brd),
00060       m_toPlay(toPlay)
00061 {
00062 }
00063 
00064 inline StoneBoard& HexState::Position()
00065 {
00066     return m_brd;
00067 }
00068 
00069 inline const StoneBoard& HexState::Position() const
00070 {
00071     return m_brd;
00072 }
00073 
00074 inline void HexState::SetToPlay(HexColor toPlay)
00075 {
00076     m_toPlay = toPlay;
00077 }
00078 
00079 inline HexColor HexState::ToPlay() const
00080 {
00081     return m_toPlay;
00082 }
00083 
00084 inline hash_t HexState::Hash() const
00085 {
00086     return m_brd.Hash(m_toPlay);
00087 }
00088 
00089 inline void HexState::PlayMove(HexPoint move)
00090 {
00091     m_brd.PlayMove(m_toPlay, move);
00092     FlipColorToPlay();
00093 }
00094 
00095 inline void HexState::UndoMove(HexPoint move)
00096 {
00097     m_brd.UndoMove(move);
00098     FlipColorToPlay();
00099 }
00100 
00101 inline void HexState::FlipColorToPlay()
00102 {
00103     m_toPlay = !m_toPlay;
00104 }
00105 
00106 //----------------------------------------------------------------------------
00107 
00108 _END_BENZENE_NAMESPACE_
00109 
00110 #endif // HEXSTATE_H


6 Jan 2011 Doxygen 1.6.3