def _pawnHit(state, user, y):
not_user = _notUser(user)
hit = 0
a=[]
for coordinate in y[1]:
if(state.whichUserProper(coordinate[0], coordinate[1]) == not_user):
hit = 1
a.append(coordinate)
if(hit==1):
return [a,True]
for coordinate in y[0]:
if(state.whichUserProper(coordinate[0],coordinate[1] == 7)):
a.append(coordinate)
else:
break
return [a,False]
In C/C++ we cannot return any variable by reference (especially talking about arrays) declared inside a function(its scope ends as the function returns and the variable is destroyed) unless its memory is allocated using new/malloc and then also we return the pointer to the array.
In python as I don't know how the returning of the lists happen. So I don't know whether this will work or not. The list 'a' has been created inside a function. Will it be destroyed once the function's scope ends? If yes, what's a possible way around it?
P.S. I know I can easily return things like these return [i,j,[k,m]] where i,j,k,m are normal variables.