Example #1
0
void IMAstar(node root, int moves)
{
	int bound = root.getHueristic();
	std::vector<node> results;
	while (true)
	{
		results.push_back(root);
		int f = search(root, bound, results);
		if (f ==  -1)//is solution
		{
			return;//return found
		}
		else if (f == std::numeric_limits<int>::max())//no solution
		{
			std::cout << "There is no solution / solution is larger than 32bit int " << std::endl;
			return;
		}
		else
		{
			bound = f;
		}
	}
	

}
Example #2
0
int search(node n, int bound, std::vector<node>& results)
{
	int f = n.getHueristic() + n.getDepth();
	if (f > bound)
	{
		return f;
	}
	if (n.solution())
	{
		solutionStat(results, n);
		return -1;//found
	}
	int min = std::numeric_limits<int>::max();
	//make children here
	node children[3];
	node child = n.makeChild();
	children[0] = child; 
	//child.board.display();
	child = n.makeChild();
	children[1] = child; 
	//child.board.display();
	child = n.makeChild();
	children[2] = child; ;
	for (int i = 0; i < 3; i++)
	{
		exploredNodes++;
		int t = search(children[i], bound, results);
		if (t == -1)//found
		{
			results.push_back(children[i]);
			return t;//found
		}
		else if (t < min)
		{
			results.push_back(children[i]);
			min = t;
		}
	}

	return min;
}