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
a625a971
Commit
a625a971
authored
Jun 17, 2016
by
Matthew Hausknecht
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored example python agents.
parent
abc00c38
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
18 deletions
+45
-18
example/communication_agent.py
example/communication_agent.py
+21
-11
example/hfo_example_agent.py
example/hfo_example_agent.py
+14
-4
example/high_level_random_agent.py
example/high_level_random_agent.py
+10
-3
No files found.
example/communication_agent.py
View file @
a625a971
...
...
@@ -4,29 +4,39 @@
# Before running this program, first Start HFO server:
# $> ./bin/HFO --offense-agents 1
import
sys
import
sys
,
itertools
from
hfo
import
*
if
__name__
==
'__main__'
:
def
main
()
:
# Create the HFO Environment
hfo
=
hfo
.
HFOEnvironment
()
hfo
=
HFOEnvironment
()
# Connect to the server with the specified
# feature set. See feature sets in hfo.py/hfo.hpp.
hfo
.
connectToServer
(
HIGH_LEVEL_FEATURE_SET
,
'bin/teams/base/config/formations-dt'
,
6000
,
'localhost'
,
'base_left'
,
False
)
for
episode
in
xrange
(
10
):
for
episode
in
itertools
.
count
(
):
status
=
IN_GAME
while
status
==
IN_GAME
:
# Grab the state features from the environment
features
=
hfo
.
getState
()
# Get any incoming communication
msg
=
hfo
.
hear
()
# Do something with incoming communication
print
'Heard: '
,
msg
# Take an action and get the current game status
hfo
.
act
(
DASH
,
20.0
,
0
)
# Do something with outgoing communication
hfo
.
say
(
'Message'
)
# Print the incoming communication
if
msg
:
print
(
'Heard:
%
s'
%
msg
)
# Take an action
hfo
.
act
(
DASH
,
20.0
,
0.
)
# Create outgoing communication
hfo
.
say
(
'Hello!'
)
# Advance the environment and get the game status
status
=
hfo
.
step
()
print
'Episode'
,
episode
,
'ended with'
,
hfo
.
statusToString
(
status
)
# Check the outcome of the episode
print
(
'Episode
%
d ended with
%
s'
%
(
episode
,
hfo
.
statusToString
(
status
)))
# Quit if the server goes down
if
status
==
SERVER_DOWN
:
hfo
.
act
(
QUIT
)
break
if
__name__
==
'__main__'
:
main
()
example/hfo_example_agent.py
View file @
a625a971
...
...
@@ -4,9 +4,10 @@
# Before running this program, first Start HFO server:
# $> ./bin/HFO --offense-agents 1
import
itertools
from
hfo
import
*
if
__name__
==
'__main__'
:
def
main
()
:
# Create the HFO Environment
hfo
=
HFOEnvironment
()
# Connect to the server with the specified
...
...
@@ -14,12 +15,21 @@ if __name__ == '__main__':
hfo
.
connectToServer
(
LOW_LEVEL_FEATURE_SET
,
'bin/teams/base/config/formations-dt'
,
6000
,
'localhost'
,
'base_left'
,
False
)
for
episode
in
xrange
(
10
):
for
episode
in
itertools
.
count
(
):
status
=
IN_GAME
while
status
==
IN_GAME
:
# Grab the state features from the environment
features
=
hfo
.
getState
()
# Take an action and get the current game status
hfo
.
act
(
DASH
,
20.0
,
0
)
hfo
.
act
(
DASH
,
20.0
,
0.
)
# Advance the environment and get the game status
status
=
hfo
.
step
()
print
'Episode'
,
episode
,
'ended with'
,
hfo
.
statusToString
(
status
)
# Check the outcome of the episode
print
(
'Episode
%
d ended with
%
s'
%
(
episode
,
hfo
.
statusToString
(
status
)))
# Quit if the server goes down
if
status
==
SERVER_DOWN
:
hfo
.
act
(
QUIT
)
break
if
__name__
==
'__main__'
:
main
()
example/
example_
high_level_random_agent.py
→
example/high_level_random_agent.py
View file @
a625a971
...
...
@@ -4,7 +4,7 @@
# Before running this program, first Start HFO server:
# $> ./bin/HFO --offense-agents 1
import
random
import
random
,
itertools
from
hfo
import
*
def
main
():
...
...
@@ -15,17 +15,24 @@ def main():
hfo
.
connectToServer
(
HIGH_LEVEL_FEATURE_SET
,
'bin/teams/base/config/formations-dt'
,
6000
,
'localhost'
,
'base_left'
,
False
)
for
episode
in
xrange
(
10
):
for
episode
in
itertools
.
count
(
):
status
=
IN_GAME
while
status
==
IN_GAME
:
# Get the vector of state features for the current state
state
=
hfo
.
getState
()
# Perform the action
if
state
[
5
]
==
1
:
# State[5] is 1 when the player can kick the ball
hfo
.
act
(
random
.
choice
([
SHOOT
,
DRIBBLE
]))
else
:
hfo
.
act
(
MOVE
)
# Advance the environment and get the game status
status
=
hfo
.
step
()
#
print 'Episode', episode, 'ended with', hfo.statusToString(status)
#
Check the outcome of the episode
print
(
'Episode
%
d ended with
%
s'
%
(
episode
,
hfo
.
statusToString
(
status
)))
# Quit if the server goes down
if
status
==
SERVER_DOWN
:
hfo
.
act
(
QUIT
)
break
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