-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathborkAutomator.py
46 lines (38 loc) · 1.61 KB
/
borkAutomator.py
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
import random
class Bork:
exitsMap = {
'Home': { 'Future': 'Heat death of the universe', 'East': 'Swamp', 'West': 'Town' },
'Town': { 'South': 'Home', 'North': 'Forest' },
'Swamp': { 'West': 'Town', 'Hubward': 'Sagitarius A*' },
'Forest': { 'East': 'Swamp', 'widdershins': 'Heat death of the universe' },
'Big bang': { 'Futast': 'Forest', 'turnwise': 'Home'},
'Sagitarius A*': { 'Pasorth': 'Big bang', 'rimwards': 'Town' },
'Heat death of the universe': { 'Past': 'Sagitarius A*' }
}
startLocation = 'Home'
def __init__(self, hardCore = False):
self.hardCore = hardCore
self.location = self.startLocation
self.saveGames = dict()
def restart(self):
self.location = self.startLocation
def description(self):
return self.location
def exits(self):
return set(self.exitsMap[self.location].keys())
def move(self, exit):
if exit not in self.exits():
raise ValueError(f"Attempted to move to non-existant exit {exit} from location {self.location}.")
self.location = self.exitsMap[self.location][exit]
def save(self):
if self.hardCore:
raise ValueError('Attempted to save in hard-core mode!')
saveGame = random.randint(0, 2**29)
self.saveGames[saveGame] = self.location
return saveGame
def restore(self, saveGame):
if self.hardCore:
raise ValueError('Attempted to restore in hard-core mode!')
if saveGame not in self.saveGames:
raise ValueError("Attempted to restore a non-existant save game.")
self.location = self.saveGames[saveGame]