Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CrnoBelo(Problem):
- def __init__(self, initial, goal):
- self.initial = str(initial)
- self.goal = str(goal)
- def goal_test(self, state):
- return state == self.goal
- def successor(self, state):
- successors = dict()
- dx = [-1, 0, 1, 0]
- dy = [0, 1, 0, -1]
- for x in range(0, N):
- for y in range(0, N):
- Matrix = eval(state)
- Matrix[x][y] = 1 - Matrix[x][y]
- for k in range(4):
- newX = x + dx[k]
- newY = y + dy[k]
- if newX >= 0 and newX < N and newY >= 0 and newY < N:
- Matrix[newX][newY] = (Matrix[newX][newY] + 1) % 2
- stateNew = Matrix
- akcija = "x: " + str(x) + ", y: " + str(y)
- successors[akcija] = str(stateNew)
- return successors
- def actions(self, state):
- return self.successor(state).keys()
- def result(self, state, action):
- possible = self.successor(state)
- return possible[action]
- if __name__ == '__main__':
- N = int(input())
- polinja = map(int, input().split(','))
- polinjaList = list(polinja)
- InitialMatrix = [[0 for x in range(N)] for y in range(N)]
- for i in range(0, N):
- for j in range(0, N):
- InitialMatrix[i][j] = polinjaList[i * N + j]
- GoalMatrix = [[1 for x in range(N)] for y in range(N)]
- crnoBeloinstance = CrnoBelo(InitialMatrix, GoalMatrix)
- answer = breadth_first_graph_search(crnoBeloinstance).solution()
- print(answer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement