Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
wumpus-tessaris
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lanti Davide
wumpus-tessaris
Commits
9a6830df
Commit
9a6830df
authored
5 years ago
by
Tessaris Sergio
Browse files
Options
Downloads
Patches
Plain Diff
included hunter orientation in JSON dump
parent
cea81755
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
wumpus/wumpus.py
+12
-5
12 additions, 5 deletions
wumpus/wumpus.py
with
12 additions
and
5 deletions
wumpus/wumpus.py
+
12
−
5
View file @
9a6830df
...
...
@@ -264,7 +264,7 @@ class WumpusWorld(GridWorld):
size
=
coordLst
(
'
size
'
)[
0
]
blocks
=
coordLst
(
'
blocks
'
)
hunters
=
coordLs
t
(
'
hunters
'
)
hunters
=
json_obj
.
ge
t
(
'
hunters
'
,
[]
)
pits
=
coordLst
(
'
pits
'
)
wumpuses
=
coordLst
(
'
wumpuses
'
)
exits
=
coordLst
(
'
exits
'
)
...
...
@@ -272,8 +272,13 @@ class WumpusWorld(GridWorld):
world
=
cls
(
size
,
blocks
)
for
pos
in
hunters
:
world
.
addObject
(
Hunter
(
orientation
=
Hunter
.
Orientation
.
N
),
pos
)
for
hunter
in
(
hunters
if
(
len
(
hunters
)
==
0
)
or
isinstance
(
hunters
[
0
],
Sequence
)
else
[
hunters
]):
pos
=
getCoord
(
hunter
)
try
:
orientation
=
Hunter
.
Orientation
[
str
(
hunter
[
2
]).
upper
()]
except
Exception
:
orientation
=
Hunter
.
Orientation
.
N
world
.
addObject
(
Hunter
(
orientation
=
orientation
),
pos
)
for
pos
in
(
exits
or
hunters
or
[
coord
(
0
,
0
)]):
world
.
addObject
(
Exit
(),
pos
)
...
...
@@ -361,7 +366,7 @@ class WumpusWorld(GridWorld):
golds
=
[]
for
obj
in
self
.
objects
:
if
isinstance
(
obj
,
Hunter
):
hunters
.
append
(
coord_tuple
(
obj
.
location
))
hunters
.
append
(
coord_tuple
(
obj
.
location
)
+
(
obj
.
orientation
.
name
,)
)
elif
isinstance
(
obj
,
Pit
):
pits
.
append
(
coord_tuple
(
obj
.
location
))
elif
isinstance
(
obj
,
Wumpus
):
...
...
@@ -451,6 +456,8 @@ if __name__ == "__main__":
world
.
run_episode
(
hunter
,
UserPlayer
.
player
())
print
(
json
.
dumps
(
world
.
to_JSON
()))
JSON_STRING
=
'
{
"
size
"
: [7, 7],
"
hunters
"
: [[0, 0]],
"
pits
"
: [[4, 0], [3, 1], [2, 2], [6, 2], [4, 4], [3, 5], [4, 6], [5, 6]],
"
wumpuses
"
: [[1, 2]],
"
exits
"
: [[0, 0]],
"
golds
"
: [[6, 3]]}
'
JSON_STRING
=
'
{
"
size
"
: [7, 7],
"
hunters
"
: [[0, 0
,
"
E
"
]],
"
pits
"
: [[4, 0], [3, 1], [2, 2], [6, 2], [4, 4], [3, 5], [4, 6], [5, 6]],
"
wumpuses
"
: [[1, 2]],
"
exits
"
: [[0, 0]],
"
golds
"
: [[6, 3]]}
'
world
=
WumpusWorld
.
from_JSON
(
json
.
loads
(
JSON_STRING
))
print
(
world
)
print
(
json
.
dumps
(
world
.
to_JSON
()))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment