quite new to python and struggling to achieve a value copy of a variable. have an algorithm that calls recursively another one but not getting the desired values since i think im instead using reference when assigning one variable to another in the following code:
def search(problem, strategy, depthl, depthi, pruning):
depthact = depthi
sol = None
while(not sol and depthact <= depthl):
sol = limSearch(problem, strategy, depthact, pruning)
depthact += depthi
return sol
i want to have in depthact the same value as depthi but instead i think im pointing to the same memory location and therefore when calling limSearch im doing it with whatever value is passed to the method in depthi instead of the other one that is the one i wanna use since i then increment it.
am i right? any help will be much appreciated.
edit: i know the solution to the limSearch algoritm is in a depth=35 but want this other algorithm to check if a solution exits for a given depth increment so, if i call search with depthl=40 and a depthi of 2, it should run limSearch passing in depthact the value 2 at first, then 4, 6, 8, 10.. until it reaches 36 that then it should find the solution cause of it being in 35 but it does not work, instead im getting a sol=None in all cases as if i was calling limSearch with other values.
def search(problem, strategy, 40, 2, pruning):
i want a call like this one to be in the loop calling limSearch until it reaches a solution in that algorithm that in this case is in depth=35. so my expected result is:
sol = limSearch(problem, strategy, 2, pruning)
sol = limSearch(problem, strategy, 4, pruning)
sol = limSearch(problem, strategy, 6, pruning)
...
sol = limSearch(problem, strategy, 36, pruning)
in this last iteration sol will not be none and then the while loop will no longer be executed returning me the desired solution.
the context where i call this function is the following:
if(strategy == 3): sol = search(p, strategy, depthl, depthi, pruning)
else: sol = limSearch(p, strategy, depthl, pruning)
after reading all the values values by user inputs.
depthl = int(input('depth: '))-1
if(strategy == 3): depthi = int(input('depth increment: '))
is
, which isn't being used here? – Siesta