Advertisement
IcaroPeretti

NovaTentativa

Apr 5th, 2022
1,033
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. initial_state = [3, 3, 0, 0, 0]
  2.  
  3. movement_opt = [[1, 0],
  4.                 [0, 1],
  5.                 [2, 0],
  6.                 [0, 2],
  7.                 [1, 1], ]
  8.  
  9.  
  10. def move(state, move):
  11.     validState = []
  12.  
  13.     if state[4] == 0:
  14.  
  15.         leftMiss = state[0] - move[0]
  16.         rightMiss = state[1] + move[0]
  17.  
  18.         leftCann = state[2] - move[1]
  19.         rightCann = state[3] + move[1]
  20.  
  21.         children = [leftMiss, rightMiss, leftCann, rightCann, 1]
  22.     else:
  23.  
  24.         rightMiss = state[1] - move[0]
  25.         leftMiss = state[0] + move[0]
  26.  
  27.         rightCann = state[3] - move[1]
  28.         leftCann = state[2] + move[1]
  29.  
  30.         children = [leftMiss, rightMiss, leftCann, rightCann, 0]
  31.  
  32.     print(children)
  33.     if validState(children):
  34.         validState.append(children)
  35.  
  36.  
  37. def validState(state):
  38.     if state[0] < 0 and state[1] < 0 and state[2] < 0 and state[3] < 0:
  39.         return False
  40.  
  41.     # Não permitir mais canibais que missionários
  42.     if state[0] == 0 or state[0] >= state[1] and state[2] == 0 or state[2] >= state[3]:
  43.         return True
  44.  
  45.  
  46. move(initial_state, movement_opt[0])
  47.  
Advertisement
RAW Paste Data Copied
Advertisement