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
40f00e8b
Commit
40f00e8b
authored
Jul 12, 2017
by
drallensmith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial draft of random high-level action, low-level feature space agent
parent
6cc07497
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
0 deletions
+60
-0
example/high_action_random_agent.py
example/high_action_random_agent.py
+60
-0
No files found.
example/high_action_random_agent.py
0 → 100755
View file @
40f00e8b
#!/usr/bin/env python
# encoding: utf-8
# Before running this program, first Start HFO server:
# $> ./bin/HFO --offense-agents 1
import
argparse
import
itertools
import
random
try
:
import
hfo
except
ImportError
:
print
(
'Failed to import hfo. To install hfo, in the HFO directory'
\
' run:
\"
pip install .
\"
'
)
exit
()
def
main
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--port'
,
type
=
int
,
default
=
6000
,
help
=
"Server port"
)
parser
.
add_argument
(
'--seed'
,
type
=
int
,
default
=
None
,
help
=
"Python randomization seed; uses python default if 0 or not given"
)
args
=
parser
.
parse_args
()
if
args
.
seed
:
random
.
seed
(
args
.
seed
)
# Create the HFO Environment
hfo_env
=
hfo
.
HFOEnvironment
()
# Connect to the server with the specified
# feature set. See feature sets in hfo.py/hfo.hpp.
hfo_env
.
connectToServer
(
hfo
.
LOW_LEVEL_FEATURE_SET
,
'bin/teams/base/config/formations-dt'
,
args
.
port
,
'localhost'
,
'base_left'
,
False
)
for
episode
in
itertools
.
count
():
status
=
hfo
.
IN_GAME
while
status
==
hfo
.
IN_GAME
:
# Get the vector of state features for the current state
state
=
hfo_env
.
getState
()
# Perform the action
if
state
[
12
]
>
0
:
# State[12] is 1 when the player can kick the ball
if
random
.
random
()
<
0.5
:
# more efficient than random.choice for 2
hfo_env
.
act
(
hfo
.
SHOOT
)
else
:
hfo_env
.
act
(
hfo
.
DRIBBLE
)
# 8 is frozen; rest are self or ball position/velocity valid
elif
(
state
[
8
]
>
0
)
or
(
min
(
state
[
0
],
state
[
1
],
state
[
50
],
state
[
54
])
<
0
):
hfo_env
.
act
(
hfo
.
REORIENT
)
else
:
hfo_env
.
act
(
hfo
.
MOVE
)
# Advance the environment and get the game status
status
=
hfo_env
.
step
()
# Check the outcome of the episode
print
((
'Episode
%
d ended with
%
s'
%
(
episode
,
hfo
.
statusToString
(
status
))))
# Quit if the server goes down
if
status
==
hfo
.
SERVER_DOWN
:
hfo_env
.
act
(
hfo
.
QUIT
)
exit
()
if
__name__
==
'__main__'
:
main
()
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