forked from nbdSteve/comp3702-a1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.py
More file actions
112 lines (90 loc) · 3.69 KB
/
Copy pathsolution.py
File metadata and controls
112 lines (90 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from game_env import GameEnv
from game_state import GameState
"""
solution.py
This file is a template you should use to implement your solution.
You should implement each of the method stubs below. You may add additional methods and/or classes to this file if you
wish. You may also create additional source files and import to this file if you wish.
COMP3702 Assignment 1 "Cheese Hunter" Support Code, 2025
"""
class Solver:
def __init__(self, game_env):
self.game_env = game_env
#
#
# TODO: Define any class instance variables you require here (avoid performing any computationally expensive
# heuristic preprocessing operations here - use the preprocess_heuristic method below for this purpose).
#
#
@staticmethod
def get_testcases():
"""
Select which testcases you wish the autograder to test you on.
The autograder will not run any excluded testcases.
e.g. [1, 4, 6] will only run testcases 1, 4, and 6, excluding, 2, 3, and 5.
:return: a list containing which testcase numbers to run (testcases in 1-6).
"""
return [1, 2, 3, 4, 5, 6]
@staticmethod
def get_search():
"""
Select which search you wish the autograder to run.
The autograder will only run the specified search methods.
e.g. "both" will run both UCS and A*, but "a_star" will only run A* and exclude UCS.
:return: a string containing which search methods to run ("ucs" to only run UCS, "a_star" to only run A*,
and "both" to run both).
"""
return "both"
# === Uniform Cost Search ==========================================================================================
def search_ucs(self):
"""
Find a path which solves the environment using Uniform Cost Search (UCS).
:return: path (list of actions, where each action is an element of GameEnv.ACTIONS)
"""
#
#
# TODO: Implement your UCS code here.
#
#
pass
# === A* Search ====================================================================================================
def preprocess_heuristic(self):
"""
Perform pre-processing (e.g. pre-computing repeatedly used values) necessary for your heuristic,
"""
#
#
# TODO: (Optional) Implement code for any preprocessing required by your heuristic here (if your heuristic
# requires preprocessing).
#
# If you choose to implement code here, you should call this method from your search_a_star method (e.g. once at
# the beginning of your search).
#
#
pass
def compute_heuristic(self, state):
"""
Compute a heuristic value h(n) for the given state.
:param state: given state (GameState object)
:return a real number h(n)
"""
#
#
# TODO: Implement your heuristic function for A* search here. Note that your heuristic can be tested on
# gradescope even if you have not yet implemented search_a_star.
#
# You should call this method from your search_a_star method (e.g. every time you need to compute a heuristic
# value for a state).
#
pass
def search_a_star(self):
"""
Find a path which solves the environment using A* Search.
:return: path (list of actions, where each action is an element of GameEnv.ACTIONS)
"""
#
#
# TODO: Implement your A* search code here.
#
#
pass