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
c94749b2
Commit
c94749b2
authored
5 years ago
by
Tessaris Sergio
Browse files
Options
Downloads
Patches
Plain Diff
added blind player to examples
parent
01b75411
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
examples/wumpus-usage.py
+29
-4
29 additions, 4 deletions
examples/wumpus-usage.py
with
29 additions
and
4 deletions
examples/wumpus-usage.py
+
29
−
4
View file @
c94749b2
...
...
@@ -4,6 +4,7 @@
import
json
import
random
import
sys
import
wumpus
as
wws
...
...
@@ -86,16 +87,40 @@ def play_fixed(world_json: str = WUMPUS_WORLD):
world
.
run_episode
(
hunter
,
MyPlayer
.
player
(
world
=
world
,
agent
=
hunter
))
EXAMPLES
=
(
play_classic
,
play_classic_informed
,
play_fixed
)
def
real_deal
(
size
:
int
=
0
):
"""
Play the classic version of the wumpus without being able to see the actual layout, that is as the actual software agent will do.
"""
# create the world
world
=
wws
.
WumpusWorld
.
classic
(
size
=
size
if
size
>
3
else
random
.
randint
(
4
,
8
))
# get the hunter agent
hunter
=
next
(
iter
(
o
for
o
in
world
.
objects
if
isinstance
(
o
,
wws
.
Hunter
)),
None
)
# Run a player without any knowledge about the world
world
.
run_episode
(
hunter
,
wws
.
UserPlayer
.
player
(),
show
=
False
)
EXAMPLES
=
(
play_classic
,
play_classic_informed
,
play_fixed
,
real_deal
)
def
main
(
*
args
):
# Randomly play one of the examples
ex
=
random
.
choice
(
EXAMPLES
)
ex_names
=
{
ex
.
__name__
.
lower
():
ex
for
ex
in
EXAMPLES
}
ex
=
None
if
len
(
args
)
>
0
:
ex_name
=
args
[
0
]
if
ex_name
.
lower
()
in
ex_names
:
ex
=
ex_names
[
ex_name
.
lower
()]
else
:
print
(
'
Example {} not among the available {}
'
.
format
(
ex_name
,
list
(
ex_names
.
keys
())))
return
-
1
else
:
# Randomly play one of the examples
ex
=
random
.
choice
(
EXAMPLES
)
print
(
'
Example {}:
'
.
format
(
ex
.
__name__
))
print
(
'
'
+
ex
.
__doc__
)
ex
()
return
0
if
__name__
==
"
__main__
"
:
main
(
)
sys
.
exit
(
main
(
*
sys
.
argv
[
1
:])
)
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