0

Why does the 22 line not work

from Queue import priorityQueue class state(object): def __init__(self,value,parent, start = 0, goal = 0, solover = 0): self.children = [] self.parent = parent self.value = value self.dist = 0 if parent: self.path = parent.path[:] self.path.append(value) self.start = parent.start self.goal = parent.goal self.solver = parent.solver else: self.path = [value] self.start = start self.goal = goal self.solver = solver def GetDist(self): pass def creatchildren(self): pass class State_String(State): def__init__(self, value, parent, start == 0, goal == 0): super(State_String, self).__init__(value, parent, start, goal) self.dist = self.GetDist() def GetDist(self): if self.value == self.goal: return 0 dist = 0 for i in range(len(self.goal)): letter = self.goal[i] dist += abs(i - self.value.index(letter)) return dist def CreateChildren(self): if not self.childern for i in xrange(len(self.goal)-1): val = self.value val = val[:i] + val[i+1] + val[i] + val child = State.String(val, self) self.children.append(child)

31st Dec 2016, 7:28 PM
Nate
1 ответ
0
I notice you have conditional '==' in your init, not sure if a typo but they should be only one = to be an optional argument. which line is your line 22 and what error are you getting? could you also show the initialisation of your State_String class object. I.e x = State_String(1, self, start = 2) not near a computer to pop the code in and test so need a little more info to know why it is failing for you. in your state class you have parent being a required argument however you test if parent was supplied. Is this what you expect or maybe you might want to make it optional?
1st Jan 2017, 1:02 PM
Elric Hindy
Elric Hindy - avatar