-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrid.py
65 lines (50 loc) · 1.98 KB
/
grid.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from random import *
class Grid:
def __init__(self, m, n, robotPos, teleportalPos, unmovables, rocksPos, pressurePos):
self.m = m
self.n = n
self.robotPos = robotPos
self.teleportalPos = teleportalPos
self.unmovables = unmovables
self.rocksPos = rocksPos
self.pressurePos = pressurePos
def GenGrid():
# Base
m = randint(3,5)
n = randint(3,5)
# R2D2
robotPos = (randint(0, m-1), randint(0, n-1))
# Teleportal
teleportalPos = (randint(0, m-1), randint(0, n-1))
# Unmovable Objects
unmovableNum = randint(1, max(m,n))
unmovablesPos = []
for i in range(0, unmovableNum):
currUnmovable = (randint(0, m-1), randint(0, n-1))
# if occupied pick another one
while ((currUnmovable in unmovablesPos) or (currUnmovable == teleportalPos) or (currUnmovable == robotPos)):
currUnmovable = (randint(0, m-1), randint(0, n-1))
unmovablesPos.append(currUnmovable)
# Rocks & Pressure Pads
rocksNum = randint(1, max(m,n)) # Same no. of pressure pads
rocksPos = []
pressurePos = []
for j in range(0, rocksNum):
currRock = (randint(1,m-2), randint(1,n-2))
currPressure = (randint(0,m-1), randint(0,n-1))
while ((currPressure in pressurePos) or (currPressure in unmovablesPos) or (currPressure == teleportalPos)):
currPressure = (randint(0,m-1), randint(0,n-1))
pressurePos.append(currPressure)
while ((currRock in rocksPos) or (currRock in unmovablesPos) or (currRock in pressurePos) or (currRock == teleportalPos) or (currRock == robotPos)):
currRock = (randint(1,m-2), randint(1,n-2))
rocksPos.append(currRock)
# Testing
print("m = ",m)
print("n = ", n)
print("The robot is at ", robotPos)
print("Teleportal is at ", teleportalPos)
print("There is unmovable objects at ", unmovablesPos)
print("The rocks' positions are ", rocksPos)
print("And the pressure pads' positions are ", pressurePos)
# Generate a grid object
return Grid(m, n, robotPos, teleportalPos, unmovablesPos, rocksPos, pressurePos);