SgNode* GoNodeUtil::CreatePosition(int boardSize, SgBlackWhite toPlay, const SgVector<SgPoint>& bPoints, const SgVector<SgPoint>& wPoints) { SgNode* node = new SgNode(); node->Add(new SgPropInt(SG_PROP_SIZE, boardSize)); node->Add(new SgPropPlayer(SG_PROP_PLAYER, toPlay)); node->Add(new SgPropAddStone(SG_PROP_ADD_BLACK, bPoints)); node->Add(new SgPropAddStone(SG_PROP_ADD_WHITE, wPoints)); return node; }
void GoGame::PlaceHandicap(const SgVector<SgPoint>& stones) { SG_ASSERT(GoBoardUtil::IsBoardEmpty(m_board)); SgNode* node = m_current; if (node->HasSon()) node = node->NewRightMostSon(); SgPropAddStone* addBlack = new SgPropAddStone(SG_PROP_ADD_BLACK); for (SgVectorIterator<SgPoint> it(stones); it; ++it) addBlack->PushBack(*it); node->Add(addBlack); SgPropInt* handicap = new SgPropInt(SG_PROP_HANDICAP, stones.Length()); node->Add(handicap); node->Add(new SgPropPlayer(SG_PROP_PLAYER, SG_WHITE)); m_board.Rules().SetHandicap(stones.Length()); GoToNode(node); }
void SgGameWriter::WriteGame(SgNode& root, bool allProps, int fileFormat, const string& application, int gameNumber, int defaultSize) { if (! m_out) throw SgException("SgGameWriter: write error"); // Add file format property to root. If file format not specified, // default to file format read in, or FF[4] for new files. if (fileFormat != 0) m_fileFormat = fileFormat; else if (root.HasProp(SG_PROP_FORMAT)) m_fileFormat = root.GetIntProp(SG_PROP_FORMAT); root.Add(new SgPropInt(SG_PROP_FORMAT, m_fileFormat)); if (application != "") root.Add(new SgPropText(SG_PROP_APPLIC, application)); root.Add(new SgPropInt(SG_PROP_GAME, gameNumber)); // Reorder the main root properties in a fixed order to make games more // human-readable and to avoid unnecessary diffs. Note that they'll end // up in the opposite sequence. SgPropList& props = root.Props(); props.MoveToFront(SG_PROP_PLAYER); props.MoveToFront(SG_PROP_ADD_EMPTY); props.MoveToFront(SG_PROP_ADD_WHITE); props.MoveToFront(SG_PROP_ADD_BLACK); props.MoveToFront(SG_PROP_USER); props.MoveToFront(SG_PROP_SOURCE); props.MoveToFront(SG_PROP_ROUND); props.MoveToFront(SG_PROP_EVENT); props.MoveToFront(SG_PROP_PLACE); props.MoveToFront(SG_PROP_DATE); props.MoveToFront(SG_PROP_RESULT); props.MoveToFront(SG_PROP_PLAYER_BLACK); props.MoveToFront(SG_PROP_RANK_BLACK); props.MoveToFront(SG_PROP_TEAM_BLACK); props.MoveToFront(SG_PROP_PLAYER_WHITE); props.MoveToFront(SG_PROP_RANK_WHITE); props.MoveToFront(SG_PROP_TEAM_WHITE); props.MoveToFront(SG_PROP_GAME_NAME); props.MoveToFront(SG_PROP_APPLIC); props.MoveToFront(SG_PROP_SIZE); props.MoveToFront(SG_PROP_FORMAT); props.MoveToFront(SG_PROP_GAME); SgPropPointFmt fmt = GetPointFmt(gameNumber); WriteSubtree(root, allProps, defaultSize, fmt); m_out.put('\n'); }
void GoGame::SetupPosition(const SgBWArray<SgPointSet>& stones) { SgPropAddStone* addBlack = new SgPropAddStone(SG_PROP_ADD_BLACK); SgPropAddStone* addWhite = new SgPropAddStone(SG_PROP_ADD_WHITE); for (SgSetIterator it(stones[SG_BLACK]); it; ++it) if (m_board.GetColor(*it) != SG_BLACK) addBlack->PushBack(*it); for (SgSetIterator it(stones[SG_WHITE]); it; ++it) if (m_board.GetColor(*it) != SG_WHITE) addWhite->PushBack(*it); SgNode* node = m_current->NewRightMostSon(); node->Add(addBlack); node->Add(addWhite); GoToNode(node); }