コード例 #1
0
ファイル: HTMLParser.cpp プロジェクト: aphill70/ckWC1984
void HTMLParser::processLink(HTMLToken & token){
  if(token.AttributeExists("href") && !isFragment(token.GetAttribute("href"))){
    links[linkcount++] = token.GetAttribute("href");
    if(linkcount == linkarraysize)
      growLinkArray();
  }
}
コード例 #2
0
ファイル: GameLoader.cpp プロジェクト: jeffnuss/chess
void GameLoader::LoadBoard(HTMLTokenizer & tokenizer, Board * boardPtr) const
{
	HTMLToken currentToken = tokenizer.GetNextToken();
	while (currentToken.GetValue() != "board")
	{
		CheckForEndToken(currentToken);
		currentToken = tokenizer.GetNextToken();
	}

	currentToken = tokenizer.GetNextToken();
	while (currentToken.GetValue() != "board")
	{
		CheckForEndToken(currentToken);
		if (currentToken.GetValue() == "piece")
		{
			int pieceType = ConvertTypeStrToInt(currentToken.GetAttribute("type"));
			int pieceColor = ConvertColorStrToInt(currentToken.GetAttribute("color"));
			int col = atoi(currentToken.GetAttribute("column").c_str());
			int row = atoi(currentToken.GetAttribute("row").c_str());
			boardPtr->SetPiece(BoardPosition(row, col), pieceType, pieceColor);
		}
		currentToken = tokenizer.GetNextToken();
	}
}
コード例 #3
0
ファイル: XMLReader.cpp プロジェクト: accolver/chess
//------------------------------------------------------------------------------------------------
void XMLReader::HandleStart (HTMLToken t) {
	string val = StringUtil::ToLowerCopy(t.GetValue());

	if (val == "board")
		inBoard = true;
	else if (val == "history")
		inHistory = true;
	else if (val == "move") {
		moveNum = 1;
		move.SetCaptured(NOTYPE);
		inMove = true;
	}


	if (val == "piece" && inMove) {
		switch(moveNum) {
			case 0 : 
				break;
			case 1 : {
				move.SetType(GetTypeByName(t.GetAttribute("type")));
				move.SetColor(GetColorByName(t.GetAttribute("color")));
				Position pstart;
				pstart.SetRow(atoi((t.GetAttribute("row")).c_str()));
				pstart.SetCol(atoi((t.GetAttribute("column")).c_str()));
				move.SetStart(pstart);
				moveNum++;
				break;
			}
			case 2 : {
				Position pend;
				pend.SetRow(atoi((t.GetAttribute("row")).c_str()));
				pend.SetCol(atoi((t.GetAttribute("column")).c_str()));
				move.SetEnd(pend);
				moveNum++;
				break;
			}
			case 3 :
				move.SetCaptured(GetTypeByName(t.GetAttribute("type")));
				moveNum++;
				break;
		}
	}
}
コード例 #4
0
ファイル: GameLoader.cpp プロジェクト: jeffnuss/chess
void GameLoader::LoadMoveHistory(HTMLTokenizer & tokenizer, MoveHistory * gameHistory) const
{
	HTMLToken currentToken = tokenizer.GetNextToken();
	while (currentToken.GetValue() != "history")
	{
		CheckForEndToken(currentToken);
		currentToken = tokenizer.GetNextToken();
	}

	currentToken = tokenizer.GetNextToken();
	while (currentToken.GetValue() != "history")
	{
		CheckForEndToken(currentToken);
		if (currentToken.GetValue() == "move"
				&& currentToken.GetType() == HTMLTokenType::TAG_START)
		{
			while (currentToken.GetValue() != "piece")
			{
				CheckForEndToken(currentToken);
				currentToken = tokenizer.GetNextToken();
			}
			HTMLToken origin = currentToken;

			currentToken = tokenizer.GetNextToken();
			while (currentToken.GetValue() != "piece")
			{
				CheckForEndToken(currentToken);
				currentToken = tokenizer.GetNextToken();
			}
			HTMLToken destination = currentToken;

			currentToken = tokenizer.GetNextToken();

			int originPieceType = ConvertTypeStrToInt(origin.GetAttribute("type"));
			int originPieceColor = ConvertColorStrToInt(origin.GetAttribute("color"));
			int originCol = atoi(origin.GetAttribute("column").c_str());
			int originRow = atoi(origin.GetAttribute("row").c_str());
			int destinationCol = atoi(destination.GetAttribute("column").c_str());
			int destinationRow = atoi(destination.GetAttribute("row").c_str());
			int capturedPieceType = -1;
			int capturedCol = -1;
			int capturedRow = -1;

			while (currentToken.GetValue() != "piece"
					&& currentToken.GetValue() != "move")
			{
				CheckForEndToken(currentToken);
				currentToken = tokenizer.GetNextToken();
			}

			if (currentToken.GetValue() == "piece")
			{
				capturedPieceType = ConvertTypeStrToInt(currentToken.GetAttribute("type"));
				capturedCol = atoi(currentToken.GetAttribute("column").c_str());
				capturedRow = atoi(currentToken.GetAttribute("row").c_str());
			}

			gameHistory->AddMove(Move(originPieceType,
					originPieceColor, BoardPosition(originRow, originCol),
					BoardPosition(destinationRow, destinationCol),
					capturedPieceType, BoardPosition(capturedRow, capturedCol)));
		}
		else
		{
			currentToken = tokenizer.GetNextToken();
		}
	}
}