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