Exemplo n.º 1
0
bool AgentMCTS::Node::from_s(std::string s) {
	auto dict = parse_dict(s, ", ", " ");

	if(dict.size() == 8){
		move = Move(dict["move"]);
		exp = ExpPair(dict["exp"]);
		know = from_str<int>(dict["know"]);
		outcome = Outcome(from_str<int>(dict["outcome"]));
		proofdepth = from_str<int>(dict["depth"]);
		bestmove = Move(dict["best"]);
		// ignore children
		return true;
	}
	return false;
}
Exemplo n.º 2
0
/*** Execute this node ***/
Outcome Input::execute()
{
	for(int i = 0; i < (int) exprs.size(); i++)
	{
		if(exprs.at(i)->getType() != OP_VARIABLE)
			throw Excep(getLineNumber(), getColumnNumber(), "Expected variable name to input statement!");

		// Input text
		if(getText)
		{
			char str[256];
			std::cin.getline(str, 256);
			Assign(static_cast<Variable*>(exprs.at(i))->clone(), new Text(std::string(str))).execute();
			continue;
		}

		// Input a number or logical
		std::string text;
		do
		{
			char str[256];
			std::cin.getline(str, 256);
			text = std::string(str);
		}
		while(text == "" || (!isInteger(text) && !isReal(text) && text != "yes" && text != "no"));

		if(isInteger(text))
			Assign(static_cast<Variable*>(exprs.at(i))->clone(), new Integer(text)).execute();
		else if(isReal(text))
			Assign(static_cast<Variable*>(exprs.at(i))->clone(), new Real(text)).execute();
		else if(text == "yes")
			Assign(static_cast<Variable*>(exprs.at(i))->clone(), new Logical(true)).execute();
		else
			Assign(static_cast<Variable*>(exprs.at(i))->clone(), new Logical(false)).execute();
	}

	return Outcome(S_SUCCESS);
}