00001 //---------------------------------------------------------------------------- 00002 /** @file GoRules.cpp */ 00003 //---------------------------------------------------------------------------- 00004 00005 #include "SgSystem.h" 00006 #include "GoRules.h" 00007 00008 #include <cmath> 00009 #include <limits> 00010 #include <iostream> 00011 #include "SgException.h" 00012 00013 using namespace std; 00014 00015 //---------------------------------------------------------------------------- 00016 00017 GoRules::GoRules(int handicap, const GoKomi& komi, bool japanese, 00018 bool twoPassesEndGame) 00019 : m_allowSuicide(false), 00020 m_captureDead(false), 00021 m_japaneseScoring(japanese), 00022 m_extraHandicapKomi(false), 00023 m_handicap(handicap), 00024 m_komi(komi), 00025 m_japaneseHandicap(japanese), 00026 m_twoPassesEndGame(twoPassesEndGame), 00027 m_koRule(SUPERKO) 00028 { 00029 } 00030 00031 bool GoRules::operator==(const GoRules& rules) const 00032 { 00033 return m_allowSuicide == rules.m_allowSuicide 00034 && m_captureDead == rules.m_captureDead 00035 && m_handicap == rules.m_handicap 00036 && m_komi == rules.m_komi 00037 && m_japaneseHandicap == rules.m_japaneseHandicap 00038 && m_japaneseScoring == rules.m_japaneseScoring 00039 && m_extraHandicapKomi == rules.m_extraHandicapKomi 00040 && m_twoPassesEndGame == rules.m_twoPassesEndGame 00041 && m_koRule == rules.m_koRule; 00042 } 00043 00044 void GoRules::SetNamedRules(const std::string& namedRules) 00045 { 00046 if (namedRules == "cgos") 00047 { 00048 SetAllowSuicide(false); 00049 SetJapaneseHandicap(false); 00050 SetJapaneseScoring(false); 00051 SetKoRule(POS_SUPERKO); 00052 SetCaptureDead(true); 00053 SetExtraHandicapKomi(false); 00054 } 00055 else if (namedRules == "chinese") 00056 { 00057 SetAllowSuicide(false); 00058 SetJapaneseHandicap(false); 00059 SetJapaneseScoring(false); 00060 SetKoRule(POS_SUPERKO); 00061 SetCaptureDead(false); 00062 SetExtraHandicapKomi(false); 00063 } 00064 else if (namedRules == "japanese") 00065 { 00066 SetAllowSuicide(false); 00067 SetJapaneseHandicap(true); 00068 SetJapaneseScoring(true); 00069 SetKoRule(SIMPLEKO); 00070 SetCaptureDead(false); 00071 SetExtraHandicapKomi(false); 00072 } 00073 else if (namedRules == "kgs") 00074 { 00075 SetAllowSuicide(false); 00076 SetJapaneseHandicap(false); 00077 SetJapaneseScoring(false); 00078 SetKoRule(POS_SUPERKO); 00079 SetCaptureDead(false); 00080 SetExtraHandicapKomi(true); 00081 } 00082 else 00083 throw SgException("Unknown rules: " + namedRules); 00084 } 00085 00086 //---------------------------------------------------------------------------- 00087 00088 std::ostream& operator<<(std::ostream& out, GoRules::KoRule koRule) 00089 { 00090 switch (koRule) 00091 { 00092 case GoRules::SIMPLEKO: 00093 out << "simple"; 00094 break; 00095 case GoRules::SUPERKO: 00096 out << "superko"; 00097 break; 00098 case GoRules::POS_SUPERKO: 00099 out << "positional_superko"; 00100 break; 00101 default: 00102 SG_ASSERT(false); 00103 } 00104 return out; 00105 } 00106 00107 //---------------------------------------------------------------------------- 00108