Experiment Numbe1
Experiment Numbe1
Experiment Numbe1
Code:
import copy
a=0
# Calculate f value
def calculate_f(state, goal_state):
return a + num_misplaced_tiles(state, goal_state)
# initial_state = [
# [2,8,3],
# [1,6,4],
# [7,0,5]
# ]
# goal_state = [
# [1,2,3],
# [8,0,4],
# [7,6,5]
# ]
initial_state = []
print("Enter initial state:")
for _ in range(3):
row = list(map(int, input().split()))
initial_state.append(row)
print("Initial State:")
[print(row) for row in initial_state]
initial_f = calculate_f(initial_state, goal_state)
print("f(x) =", initial_f)
a=a+1
next_states = get_next_states(initial_state)
def calculate_f_for_key(state):
return calculate_f(state, goal_state)
Output:
Enter initial state:
102
356
748
Enter goal state:
123
456
789
Initial State:
[1, 0, 2]
[3, 5, 6]
[7, 4, 8]
f(x) = 5