Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- initial_state = [3, 3, 0, 0, 0]
- movement_opt = [[1, 0],
- [0, 1],
- [2, 0],
- [0, 2],
- [1, 1], ]
- def move(state, move):
- validState = []
- if state[4] == 0:
- leftMiss = state[0] - move[0]
- rightMiss = state[1] + move[0]
- leftCann = state[2] - move[1]
- rightCann = state[3] + move[1]
- children = [leftMiss, rightMiss, leftCann, rightCann, 1]
- else:
- rightMiss = state[1] - move[0]
- leftMiss = state[0] + move[0]
- rightCann = state[3] - move[1]
- leftCann = state[2] + move[1]
- children = [leftMiss, rightMiss, leftCann, rightCann, 0]
- print(children)
- if validState(children):
- validState.append(children)
- def validState(state):
- if state[0] < 0 and state[1] < 0 and state[2] < 0 and state[3] < 0:
- return False
- # Não permitir mais canibais que missionários
- if state[0] == 0 or state[0] >= state[1] and state[2] == 0 or state[2] >= state[3]:
- return True
- move(initial_state, movement_opt[0])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement