0

I was trying to create nodes of minimax algorithm. However, I was debugging the function and I saw that my local variable 'newstate' changes when the 'state' changes. Is there something that I should know about python? Because I am a new programmer and I want to know why it changes. Thank you for your time.

def successorsgenerator(state):

    state=list(state)
    print (state)
    state[-1]=toggle(state[-1])
    print (state)
    newstate=state
    i=0
    while newstate[0]>=0 and i<3:

        state.append(tuple(newstate))
        newstate[0] -= 1
        i+=1

        print(state)

    print('result', state)

def toggle(state):
  state = 'min' if state == 'max' else 'max'
  return state


successorsgenerator(5,'max')

result>> [2, 'min', (5, 'min'), (4, 'min', (5, 'min')), (3, 'min', (5, 'min'), (4, 'min', (5, 'min')))]

vrd.gn
  • 198
  • 1
  • 18

0 Answers0