Example #1
0
func makeNodeFromState(b *board.Board, parentNode *Node) *Node {
	newNode := &Node{
		g:      parentNode.g + 1,
		h:      b.GetH(),
		key:    b.StateString(),
		parent: parentNode,
		b:      b,
	}
	newNode.f = newNode.g + newNode.h
	return newNode
}
Example #2
0
func New(b *board.Board) *Solver {
	s := &Solver{
		BoardStates: make(map[string]*Node),
		OpenList:    new(PriorityQueue),
	}
	heap.Init(s.OpenList)
	currentNode := &Node{
		parent: nil,
		key:    b.StateString(),
		h:      b.GetH(),
		g:      0,
		b:      b,
		open:   true,
	}
	currentNode.f = currentNode.g + currentNode.h
	s.BoardStates[currentNode.key] = currentNode
	heap.Push(s.OpenList, currentNode)
	s.Goal = b.GoalString()
	return s
}