Skip to content

Commit

Permalink
Rework aimacode#2
Browse files Browse the repository at this point in the history
  • Loading branch information
EdmondTongyou committed Feb 26, 2022
1 parent 3d3b361 commit 04c2f34
Showing 1 changed file with 37 additions and 32 deletions.
69 changes: 37 additions & 32 deletions wolfgoatcabbage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,68 @@ class WolfGoatCabbage(Problem):
# 0 denotes that the object is on the west bank
# 1 denotes that the object is on the east bank
# Farmer must always move per action
def __init__(self, initial=({"F", "G", "W", "C"}, {"", "", "", ""}), goal=({"", "", "", ""}, {"F", "G", "W", "C"})):
def __init__(self, initial=(("F", "G", "W", "C"), ("", "", "", "")), goal=(("", "", "", ""), ("F", "G", "W", "C"))):
super().__init__(initial, goal)

def actions(self, state):
possible_actions = [{"F", "G"},
{"F", "W"},
{"F", "C"},
{"F"}
possible_actions = [["FG"],
["FW"],
["FC"],
["F"]
]

if (state == ({"F", "W", "G", "C"}, {"", "", "", ""})):
possible_actions.remove({"F", "W"},
{"F", "C"})
if (state == (["F", "W", "G", "C"], ["", "", "", ""])):
possible_actions.remove(["FW"])
possible_actions.remove(["FC"])

elif (state == ({"", "W", "", "C"}, {"F", "", "G", ""}) or ({"F", "", "G", ""}, {"", "W", "", "C"})):
possible_actions.remove({"F", "W"},
{"F", "C"})
elif (state == (["", "W", "", "C"], ["F", "", "G", ""]) or (["F", "", "G", ""], ["", "W", "", "C"])):
possible_actions.remove(["FW"])
possible_actions.remove(["FC"])

elif (state == ({"F" , "W" , "", "C" }, {"", "", "G", ""}) or ({"" , "" , "G", "" }, {"F", "W", "", "C"})):
possible_actions.remove({"F" , "G" })
elif (state == (["F" , "W" , "", "C" ], ["", "", "G", ""]) or (["" , "" , "G", "" ], ["F", "W", "", "C"])):
possible_actions.remove(["FG" ])

elif (state == ({"F", "W", "G", "" }, {"", "", "","C"}) or ({"" , "" , "", "C" }, {"F", "W", "G", ""})):
possible_actions.remove({"F" , "C" },
{"F"})
elif (state == (["F", "W", "G", "" ], ["", "", "","C"]) or (["" , "" , "", "C" ], ["F", "W", "G", ""])):
possible_actions.remove(["FC" ])
possible_actions.remove(["F"])

elif (state == ({"F" , "" , "G", "C" }, {"", "W", "", ""}) or ({"" , "W" , "", "" }, {"F", "", "G", "C"})):
possible_actions.remove({"F", "W"},
{"F"})
elif (state == (["F" , "" , "G", "C" ], ["", "W", "", ""]) or (["" , "W" , "", "" ], ["F", "", "G", "C"])):
possible_actions.remove(["FW"])
possible_actions.remove(["F"])

else:
return

return frozenset(possible_actions)
return possible_actions

def result(self, state, action):
new_state = set(state)
new_state = list(state)

illegal_states = (
# All Illegal States
({"", "", "G" , "C"} , {"F", "W", "", ""}) ,
({"F", "W", "" , ""} , {"", "", "G", "C"}) ,
({"", "W", "G" , "C"} , {"F", "", "", ""}) ,
({"F", "", "" , ""} , {"", "W", "G", "C"}),
({"", "W", "G" , ""} , {"F", "", "", "C"}) ,
({"F", "", "" , "C"} , {"", "W", "G", ""}) ,
(["", "", "G" , "C"] , ["F", "W", "", ""]) ,
(["F", "W", "" , ""] , ["", "", "G", "C"]) ,
(["", "W", "G" , "C"] , ["F", "", "", ""]) ,
(["F", "", "" , ""] , ["", "W", "G", "C"]),
(["", "W", "G" , ""] , ["F", "", "", "C"]) ,
(["F", "", "" , "C"] , ["", "W", "G", ""]) ,
)

if (state in illegal_states):
return

new_state = action.actions(new_state)
return frozenset(new_state)
if (action == "FG"):
return
elif (action == "FW"):
return
elif (action == "FC"):
return
elif (action == "F"):
return

return tuple(new_state)

def goal_test(self, state):
if isinstance(self.goal, list):
return is_in(state, self.goal)
else:
return state == self.goal

if __name__ == '__main__':
Expand Down

0 comments on commit 04c2f34

Please sign in to comment.