Created
May 6, 2019 12:49
-
-
Save lironsade/a47a84f0c5ed653b091d0f7e3f746208 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from search import SearchProblem, a_star_search | |
class NiceProblem(SearchProblem): | |
def __init__(self): | |
self.node = (0,0) | |
self.expanded = 0 | |
def get_start_state(self): | |
""" | |
Returns the start state for the search problem | |
""" | |
return self.node | |
def is_goal_state(self, state): | |
""" | |
state: Search state | |
Returns True if and only if the state is a valid goal state | |
""" | |
return state == (5,4) | |
def get_successors(self, state): | |
""" | |
state: Search state | |
For a given state, this should return a list of triples, | |
(successor, action, stepCost), where 'successor' is a | |
successor to the current state, 'action' is the action | |
required to get there, and 'stepCost' is the incremental | |
cost of expanding to that successor | |
""" | |
# Note that for the search problem, there is only one player - #0 | |
self.expanded = self.expanded + 1 | |
return [((state[0] + 1, state[1]), 'l', 1), ((state[0], state[1] + 1), 'r', 1)] | |
def get_cost_of_actions(self, actions): | |
""" | |
actions: A list of actions to take | |
This method returns the total cost of a particular sequence of actions. The sequence must | |
be composed of legal moves | |
""" | |
return len(actions) | |
print(a_star_search(NiceProblem())) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment