Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
Seminar-HFO
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
Seminar-HFO
Commits
37af3268
Commit
37af3268
authored
Jun 12, 2015
by
Matthew Hausknecht
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Threading in high level random agent.
parent
86cf7950
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
42 deletions
+33
-42
example/example_high_level_random_agent.py
example/example_high_level_random_agent.py
+33
-42
No files found.
example/example_high_level_random_agent.py
View file @
37af3268
...
@@ -2,48 +2,39 @@
...
@@ -2,48 +2,39 @@
# encoding: utf-8
# encoding: utf-8
# First Start the server: $> bin/start.py
# First Start the server: $> bin/start.py
import
random
import
random
,
threading
,
argparse
if
__name__
==
'__main__'
:
try
:
try
:
from
hfo
import
*
from
hfo
import
*
except
:
except
:
print
'Failed to import hfo. To install hfo, in the HFO directory'
\
print
'Failed to import hfo. To install hfo, in the HFO directory'
\
' run:
\"
pip install .
\"
'
' run:
\"
pip install .
\"
'
exit
()
exit
()
# Connect 4 agents
agents
=
[]
def
get_random_action
():
for
i
in
xrange
(
4
):
""" Returns a random high-level action """
agents
.
append
(
hfo
.
HFOEnvironment
())
high_lv_actions
=
[
HFO_Actions
.
MOVE
,
HFO_Actions
.
SHOOT
,
agents
[
i
]
.
connectToAgentServer
(
6000
-
i
,
HFO_Features
.
HIGH_LEVEL_FEATURE_SET
)
HFO_Actions
.
PASS
,
HFO_Actions
.
DRIBBLE
]
return
(
random
.
choice
(
high_lv_actions
),
0
,
0
)
def
play_hfo
(
num
):
""" Method called by a thread to play 5 games of HFO """
hfo_env
=
hfo
.
HFOEnvironment
()
hfo_env
.
connectToAgentServer
(
6000
+
num
,
HFO_Features
.
HIGH_LEVEL_FEATURE_SET
)
for
episode
in
xrange
(
5
):
for
episode
in
xrange
(
5
):
status
=
HFO_Status
.
IN_GAME
status
=
HFO_Status
.
IN_GAME
while
status
==
HFO_Status
.
IN_GAME
:
while
status
==
HFO_Status
.
IN_GAME
:
# Grab the state features from the environment from the first agent
state
=
hfo_env
.
getState
()
features
=
agents
[
0
]
.
getState
()
status
=
hfo_env
.
act
(
get_random_action
())
# Take an action and get the current game status
hfo_env
.
cleanup
()
for
agent
in
agents
:
rand_int
=
random
.
randint
(
0
,
3
)
def
main
():
if
rand_int
==
0
:
parser
=
argparse
.
ArgumentParser
()
status
=
agent
.
act
((
HFO_Actions
.
MOVE
,
0
,
0
))
parser
.
add_argument
(
'num_agents'
,
type
=
int
,
help
=
'Number of agents to start. '
\
elif
rand_int
==
1
:
'NOTE: server must be started with this number of agents.'
)
status
=
agent
.
act
((
HFO_Actions
.
SHOOT
,
0
,
0
))
args
=
parser
.
parse_args
()
elif
rand_int
==
2
:
for
i
in
xrange
(
args
.
num_agents
):
status
=
agent
.
act
((
HFO_Actions
.
PASS
,
0
,
0
))
t
=
threading
.
Thread
(
target
=
play_hfo
,
args
=
(
i
,))
elif
rand_int
==
3
:
t
.
start
()
status
=
agent
.
act
((
HFO_Actions
.
DRIBBLE
,
0
,
0
))
print
'Episode'
,
episode
,
'ended with'
,
if
__name__
==
'__main__'
:
# Check what the outcome of the episode was
main
()
if
status
==
HFO_Status
.
GOAL
:
print
'goal'
elif
status
==
HFO_Status
.
CAPTURED_BY_DEFENSE
:
print
'captured by defense'
elif
status
==
HFO_Status
.
OUT_OF_BOUNDS
:
print
'out of bounds'
elif
status
==
HFO_Status
.
OUT_OF_TIME
:
print
'out of time'
else
:
print
'Unknown status'
,
status
exit
()
# Cleanup when finished
for
agent
in
agents
:
agent
.
cleanup
()
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