Example #1
0
Move::Move(Work& work, MoveNode const* move, bool isEmptyGame, unsigned varNo, unsigned varCount)
	:KeyNode(work.key)
	,m_ply(0)
{
	if (work.m_level == 0)
	{
		if (work.isEmpty && isEmptyGame)
			m_list.push_back(new Space(Empty));
		else
			m_list.push_back(new Space(Start));
	}
	else
	{
		if (/*varCount > 1 && */(work.m_displayStyle & display::ShowVariationNumbers))
			work.pushOpen(varNo == 1, varNo);
		else
			work.pushOpen(varNo == 1);

		work.pushSpace();
		work.needMoveNo = true;
	}

	if (work.isFolded)
		return;

	if (move->hasMark())
	{
		work.pop(m_list);
		m_list.push_back(new Marks(move->marks()));
		work.m_isVirgin = false;
		work.pushSpace();
	}

	bool needSpace = false;

	mstl::string info;
	getMoveInfo(work, move, info);

	if (move->hasComment(move::Post))
	{
		db::Comment comm(move->comment(move::Post));
		comm.strip(*work.wantedLanguages);

		if (!comm.isEmpty())
		{
			work.pop(m_list);
			m_list.push_back(new Comment(comm, move::Post, Comment::AtStart));
			needSpace = true;
		}
	}

	if (!info.empty())
	{
		if (needSpace)
			work.pushSpace();
		work.pop(m_list);
		m_list.push_back(new Comment(db::Comment(info, false, false), move::Post, Comment::Finally));
		needSpace = true;
	}

	if (needSpace)
	{
		work.m_isVirgin = false;
//		work.pushParagraph(Spacing::PreComment);
		if (!move->hasMark())
			work.pushSpaceOrParagraph(Spacing::Comment);
		work.needMoveNo = true;
	}
}
Example #2
0
void
Root::makeList(Work& work,
					KeyNode::List& result,
					MoveNode const* node,
					unsigned varNo,
					unsigned varCount)
{
	//M_ASSERT(node);
	//M_ASSERT(node->atLineStart());

	bool isFolded = node->isFolded();

	work.isFolded = isFolded;
	result.reserve(2*node->countHalfMoves() + 10);
	work.key.addPly(work.board.plyNumber());

	if (node->prev())
		++work.m_level;

	result.push_back(new Move(work, node, node->isEmptyLine(), varNo, varCount));

	if (	!work.isFolded
		&& (work.m_displayStyle & display::ShowDiagrams)
		&& (	node->annotation().contains(nag::Diagram)
			|| node->annotation().contains(nag::DiagramFromBlack)))
	{
		work.pushParagraph(Spacing::Diagram);
		work.pop(const_cast<Move*>(static_cast<Move const*>(result.back()))->m_list);
		result.push_back(new Diagram(
			work, node->annotation().contains(nag::Diagram) ? color::White : color::Black));
		work.m_isVirgin = false;
		work.pushParagraph(Spacing::Diagram);
		work.needMoveNo = true;
	}

	work.key.removePly();
	node = node->next();
	//M_ASSERT(node);

	if (work.isFolded)
	{
//		too confusing!
//		if (node->next()->atLineEnd() && !node->hasNote() && !node->prev()->hasNote())
//			work.isFolded = false;
		work.key.addPly(work.board.plyNumber() + 1);
		result.push_back(new Move(work, node));
		work.board.doMove(node->move());
		work.key.removePly();
	}
	else
	{
		for ( ; !node->atLineEnd(); node = node->next())
		{
			work.key.addPly(work.board.plyNumber() + 1);
			result.push_back(new Move(work, node));

			if (	(work.m_displayStyle & display::ShowDiagrams)
				&& (	node->annotation().contains(nag::Diagram)
					|| node->annotation().contains(nag::DiagramFromBlack)))
			{
				work.pushParagraph(Spacing::Diagram);
				work.pop(const_cast<Move*>(static_cast<Move const*>(result.back()))->m_list);
				work.board.doMove(node->move());
				result.push_back(new Diagram(
					work,
					node->annotation().contains(nag::Diagram) ? color::White : color::Black));
				work.board.undoMove(node->move());
				work.pushParagraph(Spacing::Diagram);
				work.needMoveNo = true;
			}

			if (node->hasVariation())
			{
				work.pushParagraph(Spacing::StartVariation);

				for (unsigned i = 0; i < node->variationCount(); ++i)
				{
					Board	board(work.board);
					Key	succKey(work.key);

					if (i + 1 < node->variationCount())
					{
						succKey.addVariation(i + 1);
						succKey.addPly(work.board.plyNumber());
					}
					else
					{
						succKey.exchangePly(work.board.plyNumber() + 2);
					}

					work.key.addVariation(i);
					work.pushBreak();
					work.needMoveNo = true;

					Variation* var = new Variation(work.key, succKey);
					result.push_back(var);

					unsigned linebreakMaxLineLength = work.m_linebreakMaxLineLength;

					if (	work.m_linebreakMaxLineLength != ::DontSetBreaks
						&& work.linebreakMaxLineLengthVar > 0
						&& node->variation(i)->countNodes() > work.linebreakMaxLineLengthVar)
					{
						work.m_linebreakMaxLineLength = work.linebreakMaxLineLengthVar;
					}
					else
					{
						work.m_linebreakMaxLineLength = ::DontSetBreaks;
					}

					makeList(work, var->m_list, node->variation(i), i + 1, node->variationCount());
					work.m_linebreakMaxLineLength = linebreakMaxLineLength;
					//M_ASSERT(work.m_level > 0);
					--work.m_level;
					work.key.removeVariation();
					work.board = board;
				}

				work.pushParagraph(Spacing::EndVariation);
				work.needMoveNo = true;
			}

			work.isFolded = isFolded;
			work.board.doMove(node->move());
			work.key.removePly();
		}
	}

	work.key.addPly(work.board.plyNumber() + 1);
	result.push_back(new Move(work, node->comment(move::Post), varNo, varCount));
	work.key.removePly();
}