Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

GoRules.h

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file GoRules.h
00003     Class GoRules. */
00004 //----------------------------------------------------------------------------
00005 
00006 #ifndef GO_RULES_H
00007 #define GO_RULES_H
00008 
00009 #include <iosfwd>
00010 #include <string>
00011 #include "GoKomi.h"
00012 
00013 //----------------------------------------------------------------------------
00014 
00015 /** Parameters describing game rules and handicap. */
00016 class GoRules
00017 {
00018 public:
00019     /** Ko rule. */
00020     enum KoRule
00021     {
00022         /** Positional superko.
00023             Full board repetition is forbidden, independent on who is to play. */
00024         POS_SUPERKO,
00025 
00026         /** Only repetition of the position two moves ago is forbidden. */
00027         SIMPLEKO,
00028 
00029         /** Situational superko.
00030             Full board repetition is forbidden, including who is to play. */
00031         SUPERKO
00032     };
00033 
00034     GoRules(int handicap = 0, const GoKomi& komi = GoKomi(6.5),
00035             bool japanese = false, bool twoPassesEndGame = true);
00036 
00037     bool operator==(const GoRules& rules) const;
00038 
00039     bool operator!=(const GoRules& rules) const;
00040 
00041     /** @name Set and query rule details */
00042     // @{
00043 
00044     /** Default is false. */
00045     bool AllowSuicide() const;
00046 
00047     void SetAllowSuicide(bool allowSuicide);
00048 
00049     /** Whether it necessary to capture dead stones.
00050         With some rules all un-captured stones count as alive.
00051         Default is false. */
00052     bool CaptureDead() const;
00053 
00054     /** See CaptureDead() */
00055     void SetCaptureDead(bool captureDead);
00056 
00057     KoRule GetKoRule() const;
00058 
00059     void SetKoRule(KoRule koRule);
00060 
00061     int Handicap() const;
00062 
00063     void SetHandicap(int handicap);
00064 
00065     /** True if using Japanese style handicap. */
00066     bool JapaneseHandicap() const;
00067 
00068     void SetJapaneseHandicap(bool japaneseHandicap);
00069 
00070     /** True if using Japanese style scoring.
00071         Japanese style scoring counts territory and prisoners, but not
00072         own stones. */
00073     bool JapaneseScoring() const;
00074 
00075     void SetJapaneseScoring(bool japaneseScoring);
00076 
00077     const GoKomi& Komi() const;
00078 
00079     void SetKomi(const GoKomi& komi);
00080 
00081     /** True if two passes end the game, false if 3 passes needed. */
00082     bool TwoPassesEndGame() const;
00083 
00084     void SetTwoPassesEndGame(bool twoPassesEndGame);
00085 
00086     /** Each handicap stone counts as an extra komi point for white.
00087         This extra komi point is not included in the komi settings. Used by
00088         the KGS Go server. Default is false. */
00089     bool ExtraHandicapKomi() const;
00090 
00091     /** See ExtraHandicapKomi() */
00092     void SetExtraHandicapKomi(bool enable);
00093 
00094     // @} // name
00095 
00096 
00097     /** Set several rule settings according to rule name.
00098         Currently supported:
00099         <table>
00100         <tr>
00101         <th>Name</th>
00102         <th>Suicide</th>
00103         <th>JapaneseHandicap</th>
00104         <th>JapaneseScoring</th>
00105         <th>KoRule</th>
00106         <th>CaptureDead</th>
00107         <th>ExtraHandicapKomi</th>
00108         </tr>
00109         <tr>
00110         <td>cgos</td>
00111         <td>no</td>
00112         <td>no</td>
00113         <td>no</td>
00114         <td>positional superko</td>
00115         <td>yes</td>
00116         <td>no</td>
00117         </tr>
00118         <tr>
00119         <td>chinese</td>
00120         <td>no</td>
00121         <td>no</td>
00122         <td>no</td>
00123         <td>positional superko</td>
00124         <td>no</td>
00125         <td>no</td>
00126         </tr>
00127         <tr>
00128         <td>japanese</td>
00129         <td>no</td>
00130         <td>yes</td>
00131         <td>yes</td>
00132         <td>simple</td>
00133         <td>no</td>
00134         <td>no</td>
00135         </tr>
00136         <tr>
00137         <td>kgs</td>
00138         <td>no</td>
00139         <td>no</td>
00140         <td>no</td>
00141         <td>positional superko</td>
00142         <td>no</td>
00143         <td>yes</td>
00144         </tr>
00145         </table>
00146         @param namedRules The named rules.
00147         @exception SgException If rule name is not known. */
00148     void SetNamedRules(const std::string& namedRules);
00149 
00150 private:
00151     bool m_allowSuicide;
00152 
00153     bool m_captureDead;
00154 
00155     bool m_japaneseScoring;
00156 
00157     /** See ExtraHandicapKomi() */
00158     bool m_extraHandicapKomi;
00159 
00160     /** Initial handicap for this game. */
00161     int m_handicap;
00162 
00163     /** The komi. */
00164     GoKomi m_komi;
00165 
00166     bool m_japaneseHandicap;
00167 
00168     bool m_twoPassesEndGame;
00169 
00170     KoRule m_koRule;
00171 };
00172 
00173 inline bool GoRules::operator!=(const GoRules& rules) const
00174 {
00175     return ! (*this == rules);
00176 }
00177 
00178 inline bool GoRules::AllowSuicide() const
00179 {
00180     return m_allowSuicide;
00181 }
00182 
00183 inline bool GoRules::CaptureDead() const
00184 {
00185     return m_captureDead;
00186 }
00187 
00188 inline bool GoRules::ExtraHandicapKomi() const
00189 {
00190     return m_extraHandicapKomi;
00191 }
00192 
00193 inline GoRules::KoRule GoRules::GetKoRule() const
00194 {
00195     return m_koRule;
00196 }
00197 
00198 inline int GoRules::Handicap() const
00199 {
00200     return m_handicap;
00201 }
00202 
00203 inline bool GoRules::JapaneseHandicap() const
00204 {
00205     return m_japaneseHandicap;
00206 }
00207 
00208 inline bool GoRules::JapaneseScoring() const
00209 {
00210     return m_japaneseScoring;
00211 }
00212 
00213 inline const GoKomi& GoRules::Komi() const
00214 {
00215     return m_komi;
00216 }
00217 
00218 inline void GoRules::SetAllowSuicide(bool allowSuicide)
00219 {
00220     m_allowSuicide = allowSuicide;
00221 }
00222 
00223 inline void GoRules::SetCaptureDead(bool captureDead)
00224 {
00225     m_captureDead = captureDead;
00226 }
00227 
00228 inline void GoRules::SetExtraHandicapKomi(bool enable)
00229 {
00230     m_extraHandicapKomi = enable;
00231 }
00232 
00233 inline void GoRules::SetHandicap(int handicap)
00234 {
00235     SG_ASSERT(handicap >= 0);
00236     m_handicap = handicap;
00237 }
00238 
00239 inline void GoRules::SetJapaneseHandicap(bool japaneseHandicap)
00240 {
00241     m_japaneseHandicap = japaneseHandicap;
00242 }
00243 
00244 inline void GoRules::SetJapaneseScoring(bool japaneseScoring)
00245 {
00246     m_japaneseScoring = japaneseScoring;
00247 }
00248 
00249 inline void GoRules::SetKomi(const GoKomi& komi)
00250 {
00251     m_komi = komi;
00252 }
00253 
00254 inline void GoRules::SetKoRule(KoRule koRule)
00255 {
00256     m_koRule = koRule;
00257 }
00258 
00259 inline void GoRules::SetTwoPassesEndGame(bool twoPassesEndGame)
00260 {
00261     m_twoPassesEndGame = twoPassesEndGame;
00262 }
00263 
00264 inline bool GoRules::TwoPassesEndGame() const
00265 {
00266     return m_twoPassesEndGame;
00267 }
00268 
00269 std::ostream& operator<<(std::ostream& out, GoRules::KoRule koRule);
00270 
00271 //----------------------------------------------------------------------------
00272 
00273 #endif // GO_RULES_H
00274 


Sun Mar 13 2011 Doxygen 1.7.1