forked from nbdSteve/comp3702-a1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame_state.py
More file actions
38 lines (28 loc) · 1.39 KB
/
Copy pathgame_state.py
File metadata and controls
38 lines (28 loc) · 1.39 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
"""
game_state.py
This file contains a class representing a Cheese Hunter state. You should make use of this class in your solver.
COMP3702 Assignment 1 "Cheese Hunter" Support Code, 2025
"""
class GameState:
"""
Instance of a Cheese Hunter state. row and col represent the current player position. trap_status is 1 for
each activated lever/trap, and 0 for each remaining lever/trap.
You may use this class and its functions. You may add your own code to this class (e.g. get_successors function,
get_heuristic function, etc), but should avoid removing or renaming existing variables and functions to ensure
Tester functions correctly.
"""
def __init__(self, row, col, trap_status):
self.row = row
self.col = col
assert isinstance(trap_status, tuple), '!!! trap_status should be a tuple !!!'
self.trap_status = trap_status
def __eq__(self, other):
if not isinstance(other, GameState):
return False
return self.row == other.row and self.col == other.col and self.trap_status == other.trap_status
def __hash__(self):
return hash((self.row, self.col, self.trap_status))
def __repr__(self):
return f'row: {self.row},\t\t col: {self.col}, \t\t trap status: {self.trap_status}'
def deepcopy(self):
return GameState(self.row, self.col, self.trap_status)