Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

GoRules.cpp

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


17 Jun 2010 Doxygen 1.4.7