00001 //---------------------------------------------------------------------------- 00002 /** @file SgProp.h 00003 Properties for nodes in a game tree. 00004 00005 Module SgProp defines properties that are stored in each node of a game 00006 tree. Most properties correspond to items written in the SGF file format, 00007 but there are other properties that are hidden and only used by the 00008 system. */ 00009 //---------------------------------------------------------------------------- 00010 00011 #ifndef SG_PROP_H 00012 #define SG_PROP_H 00013 00014 #include <string> 00015 #include <vector> 00016 #include "SgBlackWhite.h" 00017 #include "SgPoint.h" 00018 #include "SgVector.h" 00019 00020 class SgProp; 00021 00022 //---------------------------------------------------------------------------- 00023 00024 /** The ID associated with this property */ 00025 typedef int SgPropID; 00026 00027 /** The flags describing this property */ 00028 typedef int SgPropFlags; 00029 00030 //---------------------------------------------------------------------------- 00031 00032 /** Game dependent format for point values of SGF properties. */ 00033 enum SgPropPointFmt { 00034 /** Point format used in Go. 00035 Points are written as two letters. 'aa' is top left corner. */ 00036 SG_PROPPOINTFMT_GO, 00037 00038 /** Point format used in Hex and Reversi. 00039 Points are written as letter/number. 'a1' is top left corner. 00040 Both letters 'i' and 'j' are used ('i' is not skipped as in standard 00041 Go coordinates) */ 00042 SG_PROPPOINTFMT_HEX 00043 }; 00044 00045 //---------------------------------------------------------------------------- 00046 00047 namespace SgPropUtil 00048 { 00049 std::string EscapeSpecialCharacters(const std::string& s, 00050 bool escapeColon); 00051 00052 /** Return point format for a given game. 00053 Returns SG_PROPPOINTFMT_GO for unknown game numbers. */ 00054 SgPropPointFmt GetPointFmt(int gameNumber); 00055 00056 /** Convert point to SGF point string. */ 00057 std::string PointToSgfString(SgMove p, int boardSize, 00058 SgPropPointFmt fmt, int fileFormat = 4); 00059 00060 /** Convert SGF point string to point. 00061 @return The point or SG_PASS (only allowed if point format is 00062 SG_PROPPOINTFMT_GO) or SG_NULLMOVE, if s is not a valid point. */ 00063 SgPoint SgfStringToPoint(const std::string& s, int boardSize, 00064 SgPropPointFmt fmt); 00065 } 00066 00067 //---------------------------------------------------------------------------- 00068 00069 /** Maximum number of property classes defined */ 00070 const int SG_MAX_PROPCLASS = 150; 00071 00072 /** Contains information related to Black player */ 00073 const int SG_PROPCLASS_BLACK = 1 << 0; 00074 00075 /** Contains information related to White player */ 00076 const int SG_PROPCLASS_WHITE = 1 << 1; 00077 00078 /** Game info */ 00079 const int SG_PROPCLASS_INFO = 1 << 2; 00080 00081 /** Annotation */ 00082 const int SG_PROPCLASS_ANNO = 1 << 3; 00083 00084 /** Statistics generated by the program */ 00085 const int SG_PROPCLASS_STAT = 1 << 4; 00086 00087 /** Property can only be stored in root */ 00088 const int SG_PROPCLASS_ROOT = 1 << 5; 00089 00090 /** Move annotation */ 00091 const int SG_PROPCLASS_ANNO_MOVE = 1 << 6; 00092 00093 /** Position annotation */ 00094 const int SG_PROPCLASS_ANNO_POS = 1 << 7; 00095 00096 /** Black or white move */ 00097 const int SG_PROPCLASS_MOVE = 1 << 8; 00098 00099 /** Marks on board points */ 00100 const int SG_PROPCLASS_MARK = 1 << 9; 00101 00102 /** Time left info */ 00103 const int SG_PROPCLASS_TIME = 1 << 10; 00104 00105 /** Abstract property */ 00106 const int SG_PROPCLASS_ABSTRACT = 1 << 11; 00107 00108 /** Property is not part of the FF[3] standard */ 00109 const int SG_PROPCLASS_NOT_FF3 = 1 << 12; 00110 00111 /** Property is not part of the FF[4] standard */ 00112 const int SG_PROPCLASS_NOT_FF4 = 1 << 13; 00113 00114 /** Custom Smart Go property */ 00115 const int SG_PROPCLASS_CUSTOM = 1 << 14; 00116 00117 /** Don't write prop when publishing clean file */ 00118 const int SG_PROPCLASS_NOTCLEAN = 1 << 15; 00119 00120 /** Write out this property starting on a new line */ 00121 const int SG_PROPCLASS_NEWLINE = 1 << 16; 00122 00123 //---------------------------------------------------------------------------- 00124 00125 /** Property list. 00126 Implemented as list of pointers to objects derived from Property. */ 00127 class SgPropList 00128 { 00129 public: 00130 SgPropList(); 00131 00132 ~SgPropList(); 00133 00134 /** Return whether this list contains zero elements. */ 00135 bool IsEmpty() const; 00136 00137 /** Remove all elements in this list, disposing each property. */ 00138 void Clear(); 00139 00140 /** Return the first property in the list that matches the given ID. 00141 Note that SG_PROP_INFO, SG_PROP_ANNOTATE, SG_PROP_POS_ANNO, 00142 SG_PROP_MOVE_ANNO, and SG_PROP_COUNT match any property that has the 00143 corresponding flag set. 00144 @return 0 if there is no such property. */ 00145 SgProp* Get(SgPropID id) const; 00146 00147 /** Return the first property in the list that matches the given text. */ 00148 SgProp* GetPropContainingText(const std::string& findText) const; 00149 00150 /** Add the property to this property list. 00151 Enforces that no two properties of the same kind are added. */ 00152 void Add(const SgProp* prop); 00153 00154 /** If the property with the given ID exists, move it to the front of this 00155 property list. */ 00156 void MoveToFront(SgPropID id); 00157 00158 /** Remove the property from the property list. 00159 Return true if the property was in the list. */ 00160 bool Remove(const SgProp* prop); 00161 00162 /** Remove any properties that match 'id' from this list, and 00163 dispose them, except don't touch *protectProp if it's in 00164 the list. */ 00165 void Remove(SgPropID id, const SgProp* protectProp); 00166 00167 void RemoveProp(SgPropID id) { Remove(id, 0); } 00168 00169 /** Add the move annotations at the end of '*string'. 00170 !! very good move SG_PROP_GOOD_MOVE[2] <br> 00171 ! good move SG_PROP_GOOD_MOVE[1] <br> 00172 !? interesting move SG_PROP_INTERESTING <br> 00173 ?! doubtful move SG_PROP_DOUBTFUL <br> 00174 ? bad move SG_PROP_BAD_MOVE[1] <br> 00175 ?? very bad move SG_PROP_BAD_MOVE[2] <br> 00176 Return true if a move annotation was added. */ 00177 bool AppendMoveAnnotation(std::string* s) const; 00178 00179 private: 00180 friend class SgPropListIterator; 00181 00182 /** property list implemented as list of properties */ 00183 SgVectorOf<SgProp> m_list; 00184 00185 /** not implemented */ 00186 SgPropList(const SgPropList&); 00187 00188 /** not implemented */ 00189 SgPropList& operator=(const SgPropList&); 00190 }; 00191 00192 inline bool SgPropList::IsEmpty() const 00193 { 00194 return m_list.IsEmpty(); 00195 } 00196 00197 //---------------------------------------------------------------------------- 00198 00199 /** Iterate through Properties in a PropList */ 00200 class SgPropListIterator 00201 { 00202 public: 00203 /** Create a list iterator to iterate through list. */ 00204 SgPropListIterator(const SgPropList& propList); 00205 00206 void operator++(); 00207 00208 SgProp* operator*() const; 00209 00210 operator bool() const; 00211 00212 private: 00213 SgVectorIteratorOf<SgProp> m_listIterator; 00214 00215 /** Not implemented */ 00216 SgPropListIterator(const SgPropListIterator&); 00217 00218 /** Not implemented */ 00219 SgPropListIterator& operator=(const SgPropListIterator&); 00220 }; 00221 00222 inline SgPropListIterator::SgPropListIterator(const SgPropList& propList) 00223 : m_listIterator(propList.m_list) 00224 { 00225 } 00226 00227 inline void SgPropListIterator::operator++() 00228 { 00229 m_listIterator.operator++(); 00230 } 00231 00232 inline SgProp* SgPropListIterator::operator*() const 00233 { 00234 return m_listIterator.operator*(); 00235 } 00236 00237 inline SgPropListIterator::operator bool() const 00238 { 00239 return m_listIterator.operator bool(); 00240 } 00241 00242 //---------------------------------------------------------------------------- 00243 00244 /** Property base class */ 00245 class SgProp 00246 { 00247 public: 00248 explicit SgProp(SgPropID id); 00249 00250 virtual ~SgProp(); 00251 00252 /** Override this function for each property class to return an exact 00253 duplicate of this property. */ 00254 virtual SgProp* Duplicate() const = 0; 00255 00256 /** Return the property type of this property. */ 00257 SgPropID ID() const; 00258 00259 /** Get the flags for this property type. 00260 Not normally overridden. */ 00261 virtual SgPropFlags Flags() const; 00262 00263 /** Get the the label for this property type. 00264 Overridden only by SgPropUnknown. */ 00265 virtual std::string Label() const; 00266 00267 /** Return whether any of the given flags are set for this property. */ 00268 bool Flag(SgPropFlags flags) const; 00269 00270 /** Convert the property into string representation. 00271 Escapes special characters if needed (this depends on the property, 00272 e.g. the colon needs to be escaped only by some properties) 00273 Use the default file format if 'fileFormat' is 00274 zero; use the proper version of the sgf file format if 'fileFormat' 00275 is 3 or greater. 00276 @return true if the property should be written to file */ 00277 virtual bool ToString(std::vector<std::string>& values, int boardSize, 00278 SgPropPointFmt fmt, int fileFormat) const = 0; 00279 00280 /** Override this method to convert the string read from disk to the value 00281 of this property, and set the value of this property. 00282 @return true, if the string could be converted to a valid property. */ 00283 virtual bool FromString(const std::vector<std::string>& values, 00284 int boardSize, SgPropPointFmt fmt) = 0; 00285 00286 /** Call this function with a property of the right type to register that 00287 property type. 00288 Ownership of 'prop' is passed to the Property class; 00289 it will dispose the property upon exit. 00290 Register returns the property identifier to be used to refer to this 00291 property. 00292 Abstract properties can be registered with 'prop' set to 0. 00293 No property object of that type can be instantiated. 00294 (?? useful for searching?) 00295 This method asserts and returns 0 if the registry is full. */ 00296 static SgPropID Register(SgProp* prop, const char* label, 00297 SgPropFlags flags = 0); 00298 00299 /** Create a property with the given property ID. */ 00300 static SgProp* CreateProperty(SgPropID id); 00301 00302 /** Return the ID for a given label. 00303 Return SG_PROP_NONE if there is no property with that label. */ 00304 static SgPropID GetIDOfLabel(const std::string& label); 00305 00306 /** Convert the text specified in the Find dialog to special propIDs to 00307 search for. 00308 Return SG_PROP_NONE if the literal text should be searched for. */ 00309 static SgPropID ConvertFindTextToPropID(const std::string& findText); 00310 00311 /** Initialize properties. 00312 Registers most properties. Does not register SG_PROP_MOVE_BLACK ("B") 00313 and SG_PROP_MOVE_WHITE ("W"), because they are game dependent. */ 00314 static void Init(); 00315 00316 /** Finalize properties. */ 00317 static void Fini(); 00318 00319 /** If this property is marked as either SG_PROPCLASS_BLACK or 00320 SG_PROPCLASS_WHITE, return that property. 00321 Otherwise the return value is undefined (checked with assertion). */ 00322 SgBlackWhite Player() const; 00323 00324 bool IsPlayer(SgBlackWhite player) const; 00325 00326 /** If the given property is marked as either SG_PROPCLASS_BLACK or 00327 SG_PROPCLASS_WHITE, return the property of the opposite color, 00328 otherwise return 'id'. */ 00329 static SgPropID OpponentProp(SgPropID id); 00330 00331 /** If the given property is marked as either SG_PROPCLASS_BLACK or 00332 SG_PROPCLASS_WHITE, return the property of player's color, otherwise 00333 return 'id'. */ 00334 static SgPropID PlayerProp(SgPropID id, SgBlackWhite player); 00335 00336 /** Override this method to do something special when changing the color 00337 of a property (e.g. a value might need to be negated). */ 00338 virtual void ChangeToOpponent(); 00339 00340 /** Return true if the given 'id' matches this property. 00341 The special properties SG_PROP_INFO, SG_PROP_ANNOTATE, 00342 SG_PROP_POS_ANNO, SG_PROP_MOVE_ANNO, and SG_PROP_COUNT match any 00343 property that has the corresponding flag set. */ 00344 bool MatchesID(SgPropID id) const; 00345 00346 /** Return true if this property matches the given text. 00347 Override for specific properties. */ 00348 virtual bool ContainsText(const std::string& findText); 00349 00350 protected: 00351 SgPropID m_id; 00352 00353 static bool Initialized(); 00354 00355 private: 00356 /** Was SgProp::Init() called? */ 00357 static bool s_initialized; 00358 00359 static int s_numPropClasses; 00360 00361 static SgPropFlags s_flags[SG_MAX_PROPCLASS]; 00362 00363 static std::string s_label[SG_MAX_PROPCLASS]; 00364 00365 static SgProp* s_prop[SG_MAX_PROPCLASS]; 00366 00367 /** not implemented */ 00368 SgProp(const SgProp&); 00369 00370 /** not implemented */ 00371 SgProp& operator=(const SgProp&); 00372 }; 00373 00374 inline SgProp::SgProp(SgPropID id) 00375 : m_id(id) 00376 { 00377 } 00378 00379 inline SgPropID SgProp::ID() const 00380 { 00381 return m_id; 00382 } 00383 00384 inline bool SgProp::Flag(SgPropFlags flags) const 00385 { 00386 return (Flags() & flags) != 0; 00387 } 00388 00389 //---------------------------------------------------------------------------- 00390 00391 /** Unknown property. 00392 Unknown properties are used to store properties read from file but not 00393 understood by this version. This property keeps the label and the string 00394 that were read in, so that it can be written out again in exactly the same 00395 way. */ 00396 class SgPropUnknown 00397 : public SgProp 00398 { 00399 public: 00400 explicit SgPropUnknown(SgPropID id); 00401 00402 SgPropUnknown(SgPropID id, std::string label, 00403 const std::vector<std::string>& values); 00404 00405 SgProp* Duplicate() const; 00406 00407 bool ToString(std::vector<std::string>& values, int boardSize, 00408 SgPropPointFmt fmt, int fileFormat) const; 00409 00410 bool FromString(const std::vector<std::string>& values, 00411 int boardSize, SgPropPointFmt fmt); 00412 00413 std::string Label() const; 00414 00415 private: 00416 std::string m_label; 00417 00418 std::vector<std::string> m_values; 00419 }; 00420 00421 inline SgPropUnknown::SgPropUnknown(SgPropID id) 00422 : SgProp(id) 00423 { 00424 } 00425 00426 inline SgPropUnknown::SgPropUnknown(SgPropID id, std::string label, 00427 const std::vector<std::string>& values) 00428 : SgProp(id), 00429 m_label(label), 00430 m_values(values) 00431 { 00432 } 00433 00434 inline std::string SgPropUnknown::Label() const 00435 { 00436 return m_label; 00437 } 00438 00439 //---------------------------------------------------------------------------- 00440 00441 /** A property with integer value. */ 00442 class SgPropInt 00443 : public SgProp 00444 { 00445 public: 00446 explicit SgPropInt(SgPropID id); 00447 00448 SgPropInt(SgPropID id, int value); 00449 00450 SgProp* Duplicate() const; 00451 00452 bool ToString(std::vector<std::string>& values, int boardSize, 00453 SgPropPointFmt fmt, int fileFormat) const; 00454 00455 bool FromString(const std::vector<std::string>& values, 00456 int boardSize, SgPropPointFmt fmt); 00457 00458 /** Return the integer value of this property. */ 00459 int Value() const; 00460 00461 bool IsValue(int value) const; 00462 00463 /** Set the integer value of this property. */ 00464 void SetValue(int value); 00465 00466 protected: 00467 int m_value; 00468 }; 00469 00470 inline SgPropInt::SgPropInt(SgPropID id) 00471 : SgProp(id), 00472 m_value(0) 00473 { 00474 } 00475 00476 inline SgPropInt::SgPropInt(SgPropID id, int value) 00477 : SgProp(id), 00478 m_value(value) 00479 { 00480 } 00481 00482 inline int SgPropInt::Value() const 00483 { 00484 SG_ASSERT(Initialized()); 00485 return m_value; 00486 } 00487 00488 inline bool SgPropInt::IsValue(int value) const 00489 { 00490 return m_value == value; 00491 } 00492 00493 inline void SgPropInt::SetValue(int value) 00494 { 00495 m_value = value; 00496 } 00497 00498 //---------------------------------------------------------------------------- 00499 00500 /** A property with a double value. Optionally can specify precision, too. */ 00501 class SgPropReal 00502 : public SgProp 00503 { 00504 public: 00505 explicit SgPropReal(SgPropID id); 00506 00507 /** Create property with double value and given precision. 00508 @param id Property ID 00509 @param value Value 00510 @param precision Precision after dot. 00511 0 means default precision. */ 00512 SgPropReal(SgPropID id, double value, int precision = 0); 00513 00514 SgProp* Duplicate() const; 00515 00516 bool ToString(std::vector<std::string>& values, int boardSize, 00517 SgPropPointFmt fmt, int fileFormat) const; 00518 00519 bool FromString(const std::vector<std::string>& values, 00520 int boardSize, SgPropPointFmt fmt); 00521 00522 double Value() const; 00523 00524 void SetValue(double value, int precision = 0); 00525 00526 protected: 00527 int m_precision; 00528 00529 double m_value; 00530 }; 00531 00532 inline SgPropReal::SgPropReal(SgPropID id) 00533 : SgProp(id), 00534 m_precision(0), 00535 m_value(0) 00536 { 00537 } 00538 00539 inline SgPropReal::SgPropReal(SgPropID id, double value, int precision) 00540 : SgProp(id), 00541 m_precision(precision), 00542 m_value(value) 00543 { 00544 } 00545 00546 inline double SgPropReal::Value() const 00547 { 00548 return m_value; 00549 } 00550 00551 inline void SgPropReal::SetValue(double value, int precision) 00552 { 00553 m_value = value; 00554 m_precision = precision; 00555 } 00556 00557 //---------------------------------------------------------------------------- 00558 00559 /** A property with no associated value. 00560 Works as a flag (property present/absent). */ 00561 class SgPropSimple 00562 : public SgProp 00563 { 00564 public: 00565 explicit SgPropSimple(SgPropID id); 00566 00567 SgProp* Duplicate() const; 00568 00569 bool ToString(std::vector<std::string>& values, int boardSize, 00570 SgPropPointFmt fmt, int fileFormat) const; 00571 00572 bool FromString(const std::vector<std::string>& values, 00573 int boardSize, SgPropPointFmt fmt); 00574 }; 00575 00576 inline SgPropSimple::SgPropSimple(SgPropID id) 00577 : SgProp(id) 00578 { 00579 } 00580 00581 //---------------------------------------------------------------------------- 00582 00583 /** Multiple property. 00584 @todo AR: Make sure it's in range[1..2]. Should be deleted if it's 0. 00585 @todo AR: could do away with this after all, set flag instead? */ 00586 class SgPropMultiple 00587 : public SgPropInt 00588 { 00589 public: 00590 explicit SgPropMultiple(SgPropID id); 00591 00592 SgPropMultiple(SgPropID id, int value); 00593 00594 SgProp* Duplicate() const; 00595 }; 00596 00597 inline SgPropMultiple::SgPropMultiple(SgPropID id) 00598 : SgPropInt(id, 1) 00599 { 00600 } 00601 00602 inline SgPropMultiple::SgPropMultiple(SgPropID id, int value) 00603 : SgPropInt(id, value) 00604 { 00605 } 00606 00607 //---------------------------------------------------------------------------- 00608 00609 /** Like SgPropInt but can change sign for opponent's value. */ 00610 class SgPropValue 00611 : public SgPropInt 00612 { 00613 public: 00614 explicit SgPropValue(SgPropID id); 00615 00616 SgPropValue(SgPropID id, int value); 00617 00618 SgProp* Duplicate() const; 00619 00620 virtual void ChangeToOpponent(); 00621 }; 00622 00623 inline SgPropValue::SgPropValue(SgPropID id) 00624 : SgPropInt(id) 00625 { 00626 } 00627 00628 inline SgPropValue::SgPropValue(SgPropID id, int value) 00629 : SgPropInt(id, value) 00630 { 00631 } 00632 00633 //---------------------------------------------------------------------------- 00634 00635 /** A property with time value. */ 00636 class SgPropTime 00637 : public SgPropReal 00638 { 00639 public: 00640 SgPropTime(SgPropID id, double value = 0, int precision = 1); 00641 00642 virtual ~SgPropTime(); 00643 00644 SgProp* Duplicate() const; 00645 }; 00646 00647 inline SgPropTime::SgPropTime(SgPropID id, double value, int precision) 00648 : SgPropReal(id, value, precision) 00649 { 00650 } 00651 00652 //---------------------------------------------------------------------------- 00653 00654 /** Like SgPropTime, but gets stored with millisecond precision rather than 00655 tenths of a second. */ 00656 class SgPropMSec 00657 : public SgPropTime 00658 { 00659 public: 00660 explicit SgPropMSec(SgPropID id); 00661 00662 SgPropMSec(SgPropID id, double value); 00663 00664 virtual ~SgPropMSec(); 00665 00666 SgProp* Duplicate() const; 00667 }; 00668 00669 inline SgPropMSec::SgPropMSec(SgPropID id) 00670 : SgPropTime(id, 0, 3) 00671 { 00672 } 00673 00674 inline SgPropMSec::SgPropMSec(SgPropID id, double value) 00675 : SgPropTime(id, value, 3) 00676 { 00677 } 00678 00679 //---------------------------------------------------------------------------- 00680 00681 /** A property storing a point-move for games. 00682 Only for games in which a move can be described by a point. */ 00683 class SgPropMove 00684 : public SgProp 00685 { 00686 public: 00687 explicit SgPropMove(SgPropID id); 00688 00689 SgPropMove(SgPropID id, SgMove move); 00690 00691 SgProp* Duplicate() const; 00692 00693 /** Return the move value of this property. */ 00694 SgPoint Value() const; 00695 00696 bool IsValue(SgPoint move) const; 00697 00698 bool ToString(std::vector<std::string>& values, int boardSize, 00699 SgPropPointFmt fmt, int fileFormat) const; 00700 00701 bool FromString(const std::vector<std::string>& values, 00702 int boardSize, SgPropPointFmt fmt); 00703 00704 protected: 00705 SgPoint m_move; 00706 }; 00707 00708 inline SgPropMove::SgPropMove(SgPropID id) 00709 : SgProp(id), 00710 m_move(SG_NULLMOVE) 00711 { 00712 } 00713 00714 inline SgPropMove::SgPropMove(SgPropID id, SgMove move) 00715 : SgProp(id), 00716 m_move(move) 00717 { 00718 } 00719 00720 inline SgPoint SgPropMove::Value() const 00721 { 00722 return m_move; 00723 } 00724 00725 inline bool SgPropMove::IsValue(SgPoint move) const 00726 { 00727 return m_move == move; 00728 } 00729 00730 //---------------------------------------------------------------------------- 00731 00732 /** A property storing a list of points. */ 00733 class SgPropPointList 00734 : public SgProp 00735 { 00736 public: 00737 explicit SgPropPointList(SgPropID id); 00738 00739 SgPropPointList(SgPropID id, const SgVector<SgPoint>& list); 00740 00741 virtual ~SgPropPointList(); 00742 00743 SgProp* Duplicate() const; 00744 00745 /** Return the vector stored in this property. */ 00746 const SgVector<SgPoint>& Value() const; 00747 SgVector<SgPoint>& Value(); 00748 00749 /** Set the vector of this property. */ 00750 void SetValue(const SgVector<SgPoint>& list); 00751 00752 void PushBack(SgPoint p); 00753 00754 bool ToString(std::vector<std::string>& values, int boardSize, 00755 SgPropPointFmt fmt, int fileFormat) const; 00756 00757 bool FromString(const std::vector<std::string>& values, 00758 int boardSize, SgPropPointFmt fmt); 00759 00760 private: 00761 SgVector<SgPoint> m_list; 00762 }; 00763 00764 inline SgPropPointList::SgPropPointList(SgPropID id) 00765 : SgProp(id) 00766 { 00767 } 00768 00769 inline const SgVector<SgPoint>& SgPropPointList::Value() const 00770 { 00771 return m_list; 00772 } 00773 00774 inline SgVector<SgPoint>& SgPropPointList::Value() 00775 { 00776 return m_list; 00777 } 00778 00779 inline void SgPropPointList::SetValue(const SgVector<SgPoint>& list) 00780 { 00781 m_list = list; 00782 } 00783 00784 inline void SgPropPointList::PushBack(SgPoint p) 00785 { 00786 m_list.PushBack(p); 00787 } 00788 00789 //---------------------------------------------------------------------------- 00790 00791 /** A property storing a text string. */ 00792 class SgPropText 00793 : public SgProp 00794 { 00795 public: 00796 explicit SgPropText(SgPropID id); 00797 00798 SgPropText(SgPropID id, const std::string& text); 00799 00800 SgProp* Duplicate() const; 00801 00802 /** Return the string value of this property. */ 00803 const std::string& Value() const; 00804 00805 std::string& Value(); 00806 00807 void SetValue(const std::string& value); 00808 00809 void AppendText(const std::string& text); 00810 00811 bool ToString(std::vector<std::string>& values, int boardSize, 00812 SgPropPointFmt fmt, int fileFormat) const; 00813 00814 bool FromString(const std::vector<std::string>& values, 00815 int boardSize, SgPropPointFmt fmt); 00816 00817 virtual bool ContainsText(const std::string& findText); 00818 00819 private: 00820 std::string m_text; 00821 }; 00822 00823 inline SgPropText::SgPropText(SgPropID id) 00824 : SgProp(id), 00825 m_text() 00826 { 00827 } 00828 00829 inline SgPropText::SgPropText(SgPropID id, const std::string& text) 00830 : SgProp(id), 00831 m_text(text) 00832 { 00833 } 00834 00835 inline const std::string& SgPropText::Value() const 00836 { 00837 return m_text; 00838 } 00839 00840 inline std::string& SgPropText::Value() 00841 { 00842 return m_text; 00843 } 00844 00845 inline void SgPropText::SetValue(const std::string& value) 00846 { 00847 m_text = value; 00848 } 00849 00850 inline void SgPropText::AppendText(const std::string& text) 00851 { 00852 m_text += text; 00853 } 00854 00855 //---------------------------------------------------------------------------- 00856 00857 /** Keeps a string for each point in a set of points. */ 00858 class SgPropTextList 00859 : public SgProp 00860 { 00861 public: 00862 explicit SgPropTextList(SgPropID id); 00863 00864 SgPropTextList(SgPropID id, const SgVector<SgPoint>& points, 00865 SgVectorOf<std::string> strings); 00866 00867 virtual ~SgPropTextList(); 00868 00869 SgProp* Duplicate() const; 00870 00871 /** Return a list with all the points that have text associated with 00872 them. */ 00873 const SgVector<SgPoint>& GetPointsWithText() const; 00874 00875 /** If point 'p' has a string, copy that string into '*string' and return 00876 true. 00877 Otherwise return false and don't change '*string'. */ 00878 bool GetStringAtPoint(SgPoint p, std::string* s) const; 00879 00880 /** Set the string for point 'p' to 'string'. 00881 If that point already has a string, replace it with the new string. */ 00882 void AddStringAtPoint(SgPoint p, const std::string& s); 00883 00884 /** Append 'string' to the string for point 'p'. 00885 If that point has no string, create a new one. */ 00886 void AppendToStringAtPoint(SgPoint p, const std::string& s); 00887 00888 /** Remove any existing string for point 'p'. */ 00889 void ClearStringAtPoint(SgPoint p); 00890 00891 bool ToString(std::vector<std::string>& values, int boardSize, 00892 SgPropPointFmt fmt, int fileFormat) const; 00893 00894 bool FromString(const std::vector<std::string>& values, 00895 int boardSize, SgPropPointFmt fmt); 00896 00897 virtual bool ContainsText(const std::string& findText); 00898 00899 private: 00900 SgVector<SgPoint> m_points; 00901 00902 SgVectorOf<std::string> m_strings; 00903 }; 00904 00905 inline SgPropTextList::SgPropTextList(SgPropID id) 00906 : SgProp(id), 00907 m_points(), 00908 m_strings() 00909 { 00910 } 00911 00912 inline const SgVector<SgPoint>& SgPropTextList::GetPointsWithText() const 00913 { 00914 return m_points; 00915 } 00916 00917 //---------------------------------------------------------------------------- 00918 00919 /** A property storing a player color (Black or White). */ 00920 class SgPropPlayer 00921 : public SgProp 00922 { 00923 public: 00924 explicit SgPropPlayer(SgPropID id); 00925 00926 SgPropPlayer(SgPropID id, int player); 00927 00928 SgProp* Duplicate() const; 00929 00930 SgBlackWhite Value() const; 00931 00932 void SetValue(SgBlackWhite player); 00933 00934 virtual void ChangeToOpponent(); 00935 00936 bool ToString(std::vector<std::string>& values, int boardSize, 00937 SgPropPointFmt fmt, int fileFormat) const; 00938 00939 bool FromString(const std::vector<std::string>& values, 00940 int boardSize, SgPropPointFmt fmt); 00941 00942 private: 00943 SgBlackWhite m_player; 00944 }; 00945 00946 inline SgPropPlayer::SgPropPlayer(SgPropID id) 00947 : SgProp(id), 00948 m_player(SG_BLACK) 00949 { 00950 } 00951 00952 inline SgPropPlayer::SgPropPlayer(SgPropID id, int player) 00953 : SgProp(id), 00954 m_player(player) 00955 { 00956 } 00957 00958 inline SgBlackWhite SgPropPlayer::Value() const 00959 { 00960 return m_player; 00961 } 00962 00963 inline void SgPropPlayer::SetValue(SgBlackWhite player) 00964 { 00965 m_player = player; 00966 } 00967 00968 //---------------------------------------------------------------------------- 00969 00970 /** A property storing a list of stones to add to the board, 00971 or points to make empty. */ 00972 class SgPropAddStone 00973 : public SgPropPointList 00974 { 00975 public: 00976 explicit SgPropAddStone(SgPropID id); 00977 00978 SgPropAddStone(SgPropID id, const SgVector<SgPoint>& list); 00979 00980 virtual ~SgPropAddStone(); 00981 00982 SgProp* Duplicate() const; 00983 }; 00984 00985 inline SgPropAddStone::SgPropAddStone(SgPropID id) 00986 : SgPropPointList(id) 00987 { 00988 } 00989 00990 inline SgPropAddStone::SgPropAddStone(SgPropID id, 00991 const SgVector<SgPoint>& list) 00992 : SgPropPointList(id, list) 00993 { 00994 } 00995 00996 //---------------------------------------------------------------------------- 00997 00998 /** @name General */ 00999 //@{ 01000 01001 /** Default value returned by some functions */ 01002 extern SgPropID SG_PROP_NONE; 01003 01004 /** Unknown property read from disk */ 01005 extern SgPropID SG_PROP_UNKNOWN; 01006 01007 //@} 01008 01009 /** @name Moves */ 01010 //@{ 01011 01012 /** Generic property for black and white move */ 01013 extern SgPropID SG_PROP_MOVE; 01014 01015 /** Black move */ 01016 extern SgPropID SG_PROP_MOVE_BLACK; 01017 01018 /** White move */ 01019 extern SgPropID SG_PROP_MOVE_WHITE; 01020 01021 //@} 01022 01023 /** @name Board edits */ 01024 //@{ 01025 01026 /** Add a list of black stones to the current position */ 01027 extern SgPropID SG_PROP_ADD_BLACK; 01028 01029 /** Add a list of white stones to the current position */ 01030 extern SgPropID SG_PROP_ADD_WHITE; 01031 01032 /** Remove stones from the board */ 01033 extern SgPropID SG_PROP_ADD_EMPTY; 01034 01035 /** Whose turn it is to move after executing the node */ 01036 extern SgPropID SG_PROP_PLAYER; 01037 01038 01039 /** @name Value and territory */ 01040 //@{ 01041 01042 /** Node value expressed as positive = good for Black */ 01043 extern SgPropID SG_PROP_VALUE; 01044 01045 /** Black surrounded territory and dead white stones */ 01046 extern SgPropID SG_PROP_TERR_BLACK; 01047 01048 /** White surrounded territory and dead black stones */ 01049 extern SgPropID SG_PROP_TERR_WHITE; 01050 01051 //@} 01052 01053 /** @name Marks drawn on the board */ 01054 //@{ 01055 01056 /** Generic property for marked board points */ 01057 extern SgPropID SG_PROP_MARKS; 01058 01059 /** Selected points used to temporarily mark points */ 01060 extern SgPropID SG_PROP_SELECT; 01061 01062 /** Crosses displayed on stones and empty points */ 01063 extern SgPropID SG_PROP_MARKED; 01064 01065 /** Triangles displayed on stones and empty points */ 01066 extern SgPropID SG_PROP_TRIANGLE; 01067 01068 /** Small squares or square stones */ 01069 extern SgPropID SG_PROP_SQUARE; 01070 01071 /** Diamond marks */ 01072 extern SgPropID SG_PROP_DIAMOND; 01073 01074 /** Board points marked with small grey circles */ 01075 extern SgPropID SG_PROP_CIRCLE; 01076 01077 /** Dimmed points */ 01078 extern SgPropID SG_PROP_DIMMED; 01079 01080 /** Sequence of pairs: point, four letter label */ 01081 extern SgPropID SG_PROP_LABEL; 01082 01083 //@} 01084 01085 /** @name Time control */ 01086 //@{ 01087 01088 /** Generic property for time left information */ 01089 extern SgPropID SG_PROP_TIMES; 01090 01091 /** Time left for the black player (TimeProp) */ 01092 extern SgPropID SG_PROP_TIME_BLACK; 01093 01094 /** Time left for the white player (TimeProp) */ 01095 extern SgPropID SG_PROP_TIME_WHITE; 01096 01097 /** Number of stones to play for black in this overtime period */ 01098 extern SgPropID SG_PROP_OT_BLACK; 01099 01100 /** Number of stones to play for white in this overtime period */ 01101 extern SgPropID SG_PROP_OT_WHITE; 01102 01103 /** Number of moves per overtime period (0 = no overtime) */ 01104 extern SgPropID SG_PROP_OT_NU_MOVES; 01105 01106 /** Length of each overtime period */ 01107 extern SgPropID SG_PROP_OT_PERIOD; 01108 01109 /** Seconds of operator overhead for each move */ 01110 extern SgPropID SG_PROP_OVERHEAD; 01111 01112 /** Added to root node if losing on time is enforced */ 01113 extern SgPropID SG_PROP_LOSE_TIME; 01114 01115 //@} 01116 01117 /** @name Statistics */ 01118 //@{ 01119 01120 /** Generic property subsuming all in statistics category */ 01121 extern SgPropID SG_PROP_COUNT; 01122 01123 /** The time used to solve a problem */ 01124 extern SgPropID SG_PROP_TIME_USED; 01125 01126 /** The number of nodes looked at to solve a problem */ 01127 extern SgPropID SG_PROP_NUM_NODES; 01128 01129 /** The number of leaf nodes inspected */ 01130 extern SgPropID SG_PROP_NUM_LEAFS; 01131 01132 /** The maximal depth reached during the search */ 01133 extern SgPropID SG_PROP_MAX_DEPTH; 01134 01135 /** The number of plies searched */ 01136 extern SgPropID SG_PROP_DEPTH; 01137 01138 /** The number of top level moves at deepest search */ 01139 extern SgPropID SG_PROP_PART_DEPTH; 01140 01141 /** A value computed for a position */ 01142 extern SgPropID SG_PROP_EVAL; 01143 01144 /** The move expected from the current player */ 01145 extern SgPropID SG_PROP_EXPECTED; 01146 01147 /** Moves tried at a node in self-test mode */ 01148 extern SgPropID SG_PROP_SELF_TEST; 01149 01150 //@} 01151 01152 /** @name Root props */ 01153 //@{ 01154 01155 /** The file format used to store the game */ 01156 extern SgPropID SG_PROP_FORMAT; 01157 01158 /** The board size */ 01159 extern SgPropID SG_PROP_SIZE; 01160 01161 /** The game (encoding see SgTypes.TheGame) */ 01162 extern SgPropID SG_PROP_GAME; 01163 01164 /** Species of the black player (human, computer, modem) */ 01165 extern SgPropID SG_PROP_SPEC_BLACK; 01166 01167 /** Species of the white player (human, computer, modem) */ 01168 extern SgPropID SG_PROP_SPEC_WHITE; 01169 01170 /** Number of Chinese handicap stones */ 01171 extern SgPropID SG_PROP_CHINESE; 01172 01173 /** The application that wrote this file */ 01174 extern SgPropID SG_PROP_APPLIC; 01175 01176 //@} 01177 01178 /** @name Annotations */ 01179 //@{ 01180 01181 /** Generic property subsuming all annotation properties */ 01182 extern SgPropID SG_PROP_ANNOTATE; 01183 01184 /** The textual comment of a node */ 01185 extern SgPropID SG_PROP_COMMENT; 01186 01187 /** Short textual comment */ 01188 extern SgPropID SG_PROP_NAME; 01189 01190 /** Position marked with a check mark */ 01191 extern SgPropID SG_PROP_CHECK; 01192 01193 /** Position marked with a sigma icon */ 01194 extern SgPropID SG_PROP_SIGMA; 01195 01196 /** General position mark */ 01197 extern SgPropID SG_PROP_HOTSPOT; 01198 01199 /** Divides the game into sections to be printed */ 01200 extern SgPropID SG_PROP_FIGURE; 01201 01202 //@} 01203 01204 /** @name Position annotations */ 01205 //@{ 01206 01207 /** Generic property subsuming all position annotations */ 01208 extern SgPropID SG_PROP_POS_ANNO; 01209 01210 /** Good position for Black */ 01211 extern SgPropID SG_PROP_GOOD_BLACK; 01212 01213 /** Good position for White */ 01214 extern SgPropID SG_PROP_GOOD_WHITE; 01215 01216 /** Even position */ 01217 extern SgPropID SG_PROP_EVEN_POS; 01218 01219 /** Unclear position */ 01220 extern SgPropID SG_PROP_UNCLEAR; 01221 01222 //@} 01223 01224 /** @name Move annotations */ 01225 //@{ 01226 01227 /** Generic property subsuming all move annotations */ 01228 extern SgPropID SG_PROP_MOVE_ANNO; 01229 01230 /** Denotes an exceptionally good move (! or !!) */ 01231 extern SgPropID SG_PROP_GOOD_MOVE; 01232 01233 /** Denotes a bad move (? or ??) */ 01234 extern SgPropID SG_PROP_BAD_MOVE; 01235 01236 /** Denotes an interesting move (!?) */ 01237 extern SgPropID SG_PROP_INTERESTING; 01238 01239 /** Denotes a doubtful move (?!) */ 01240 extern SgPropID SG_PROP_DOUBTFUL; 01241 01242 //@} 01243 01244 /** @name Game info */ 01245 //@{ 01246 01247 /** Generic property subsuming all game info props */ 01248 extern SgPropID SG_PROP_INFO; 01249 01250 /** The file name of the game */ 01251 extern SgPropID SG_PROP_GAME_NAME; 01252 01253 /** Comment pertaining to the whole game */ 01254 extern SgPropID SG_PROP_GAME_COMMENT; 01255 01256 /** Text describing the event */ 01257 extern SgPropID SG_PROP_EVENT; 01258 01259 /** The round of the tournament */ 01260 extern SgPropID SG_PROP_ROUND; 01261 01262 /** The date when the game was played */ 01263 extern SgPropID SG_PROP_DATE; 01264 01265 /** Where the game was played */ 01266 extern SgPropID SG_PROP_PLACE; 01267 01268 /** Name of the black player */ 01269 extern SgPropID SG_PROP_PLAYER_BLACK; 01270 01271 /** Name of the white player */ 01272 extern SgPropID SG_PROP_PLAYER_WHITE; 01273 01274 /** Who won the game */ 01275 extern SgPropID SG_PROP_RESULT; 01276 01277 /** The person who entered the game and comments */ 01278 extern SgPropID SG_PROP_USER; 01279 01280 /** The time allocated to each player */ 01281 extern SgPropID SG_PROP_TIME; 01282 01283 /** Where the game was copied from */ 01284 extern SgPropID SG_PROP_SOURCE; 01285 01286 /** Who has the copyright on the material */ 01287 extern SgPropID SG_PROP_COPYRIGHT; 01288 01289 /** Who analyzed the game */ 01290 extern SgPropID SG_PROP_ANALYSIS; 01291 01292 /** Ranking of black player */ 01293 extern SgPropID SG_PROP_RANK_BLACK; 01294 01295 /** Ranking of white player */ 01296 extern SgPropID SG_PROP_RANK_WHITE; 01297 01298 /** Team of black player */ 01299 extern SgPropID SG_PROP_TEAM_BLACK; 01300 01301 /** Team of white player */ 01302 extern SgPropID SG_PROP_TEAM_WHITE; 01303 01304 /** The opening played in the game */ 01305 extern SgPropID SG_PROP_OPENING; 01306 01307 /** Special rules (Go: Japanese or Chinese) */ 01308 extern SgPropID SG_PROP_RULES; 01309 01310 /** Number of handicap stones */ 01311 extern SgPropID SG_PROP_HANDICAP; 01312 01313 /** Komi value */ 01314 extern SgPropID SG_PROP_KOMI; 01315 01316 //@} 01317 01318 /** @name Abstract properties */ 01319 //@{ 01320 01321 /** Indicates that depth-first traversal searches text */ 01322 extern SgPropID SG_PROP_FIND_MOVE; 01323 01324 /** Indicates that depth-first traversal searches move */ 01325 extern SgPropID SG_PROP_FIND_TEXT; 01326 01327 /** Used to search for branch points */ 01328 extern SgPropID SG_PROP_BRANCH; 01329 01330 /** A terminal node, only used for display */ 01331 extern SgPropID SG_PROP_TERMINAL; 01332 01333 //@} 01334 01335 /** @name Smart Go specific properties */ 01336 //@{ 01337 01338 /** Move motive: why move was generated */ 01339 extern SgPropID SG_PROP_MOTIVE; 01340 01341 /** Sequence of moves expected by computer player */ 01342 extern SgPropID SG_PROP_SEQUENCE; 01343 01344 /** Constraint: points must not be empty */ 01345 extern SgPropID SG_PROP_NOT_EMPTY; 01346 01347 /** Constraint: points must not be black */ 01348 extern SgPropID SG_PROP_NOT_BLACK; 01349 01350 /** Constraint: points must not be white */ 01351 extern SgPropID SG_PROP_NOT_WHITE; 01352 01353 //@} 01354 01355 //---------------------------------------------------------------------------- 01356 01357 #endif // SG_PROP_H