Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Hacksaar
Haxotel
Commits
35dd6c4c
Commit
35dd6c4c
authored
Jul 31, 2014
by
Constantin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moar functiannzzz in labyRINT
parent
30476a55
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
0 deletions
+28
-0
labyrinth.py
labyrinth.py
+28
-0
No files found.
labyrinth.py
View file @
35dd6c4c
...
...
@@ -3,6 +3,8 @@
from
enum
import
Enum
from
functools
import
reduce
directions
=
{
"north"
:
(
-
1
,
0
),
"east"
:
(
0
,
1
),
"west"
:
(
0
,
-
1
),
"south"
:
(
1
,
0
)}
class
Labyrinth
:
class
GroundType
(
Enum
):
FLOOR
=
1
...
...
@@ -23,6 +25,11 @@ class Labyrinth:
assert
self
.
things
.
count
(
thing
)
==
0
assert
self
.
groundtype
!=
Labyrinth
.
GroundType
.
WALL
self
.
things
.
append
(
thing
)
def
neighbor
(
self
,
dy
,
dx
):
self
.
labyrinth
.
getTileAt
(
self
.
row
+
dy
,
self
.
column
+
dx
)
def
isWalkable
(
self
):
# this may be more complicated in the future
return
self
.
groundtype
==
Labyrinth
.
GroundType
.
FLOOR
def
toString
(
self
):
# always starts with there is/there are
if
self
.
groundtype
==
Labyrinth
.
GroundType
.
WALL
:
...
...
@@ -59,12 +66,33 @@ class Labyrinth:
tiles
.
append
(
row
)
return
tiles
def
getWidth
(
self
):
return
len
(
self
.
tiles
[
0
])
def
getHeight
(
self
):
return
len
(
self
.
tiles
)
def
outOfBounds
(
self
,
row
,
column
):
return
row
<
0
or
column
<
0
or
row
>=
self
.
getHeight
()
or
column
>=
self
.
getWidth
()
def
getTileAt
(
self
,
row
,
column
):
if
self
.
outOfBounds
(
row
,
column
):
return
None
else
:
return
self
.
tiles
[
row
][
column
]
def
getTiles
(
self
):
return
reduce
(
lambda
x
,
y
:
x
+
y
,
self
.
tiles
)
def
getFreeTiles
(
self
):
return
filter
(
lambda
f
:
f
.
groundtype
==
Labyrinth
.
GroundType
.
FLOOR
and
len
(
f
.
things
==
0
)
,
self
.
getTiles
)
def
getDescription
(
self
,
field
):
descr
=
""
for
name
,
field
in
zip
([
"North"
,
"South"
,
"West"
,
"East"
],
[
self
.
getTileAt
(
field
.
row
+
row
,
field
.
column
+
column
)
for
row
,
column
in
[(
-
1
,
0
),(
1
,
0
),(
0
,
-
1
),(
0
,
1
)]]):
descr
+=
"In the "
+
name
+
" "
+
(
"there is a wall"
if
field
is
None
else
str
(
field
))
+
".
\n
"
return
descr
def
moveThing
(
self
,
thing
,
newField
):
if
thing
.
onMove
(
newField
)
==
False
:
return
False
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment