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
2480c374
Commit
2480c374
authored
Jul 12, 2017
by
drallensmith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes for rand-pass
parent
39201fcc
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
31 deletions
+51
-31
example/high_level_custom_agent.py
example/high_level_custom_agent.py
+51
-31
No files found.
example/high_level_custom_agent.py
View file @
2480c374
#!/usr/bin/env python
from
__future__
import
print_function
# encoding: utf-8
#MODIFIED#
# First Start the server: $> bin/start.py
import
argparse
import
itertools
import
random
try
:
import
hfo
...
...
@@ -27,9 +29,6 @@ def has_better_pos(dist_to_op, goal_angle, pass_angle, curr_goal_angle):
return
False
return
True
def
can_dribble
(
dist_to_op
):
return
bool
(
dist_to_op
>
params
[
'DRIB_DST'
])
def
get_action
(
state
,
hfo_env
,
num_teammates
,
rand_pass
):
"""Decides and performs the action to be taken by the agent."""
...
...
@@ -38,10 +37,9 @@ def get_action(state,hfo_env,num_teammates,rand_pass):
if
can_shoot
(
goal_dist
,
goal_op_angle
):
hfo_env
.
act
(
hfo
.
SHOOT
)
return
team_list
=
list
(
range
(
num_teammates
))
if
rand_pass
and
(
num_teammates
>
1
):
team_list
=
random
.
shuffle
(
range
(
num_teammates
))
else
:
team_list
=
range
(
num_teammates
)
random
.
shuffle
(
team_list
)
for
i
in
team_list
:
teammate_uniform_number
=
state
[
10
+
3
*
num_teammates
+
3
*
i
+
2
]
if
has_better_pos
(
dist_to_op
=
float
(
state
[
10
+
num_teammates
+
i
]),
...
...
@@ -50,14 +48,10 @@ def get_action(state,hfo_env,num_teammates,rand_pass):
curr_goal_angle
=
goal_op_angle
):
hfo_env
.
act
(
hfo
.
PASS
,
teammate_uniform_number
)
return
# not sure if below check is needed - doDribble in agent.cpp includes
# (via doPreprocess) doForceKick, which may cover this situation depending
# on what existKickableOpponent returns.
if
can_dribble
(
dist_to_op
=
state
[
9
]):
# no check for can_dribble is needed; doDribble in agent.cpp includes
# (via doPreprocess) doForceKick, which will cover this situation since
# existKickableOpponent is based on distance.
hfo_env
.
act
(
hfo
.
DRIBBLE
)
else
:
# If nothing can be done, do not do anything
hfo_env
.
act
(
hfo
.
NOOP
)
return
...
...
@@ -79,8 +73,21 @@ def main():
hfo_env
.
connectToServer
(
hfo
.
HIGH_LEVEL_FEATURE_SET
,
'bin/teams/base/config/formations-dt'
,
args
.
port
,
'localhost'
,
'base_left'
,
False
)
status
=
hfo
.
IN_GAME
while
status
!=
hfo
.
SERVER_DOWN
:
if
args
.
seed
:
if
args
.
rand_pass
or
(
args
.
eps
>
0
):
print
(
"Python randomization seed: {0:d}"
.
format
(
args
.
seed
))
else
:
print
(
"Python randomization seed setting is useless without --rand-pass or --eps >0"
)
if
args
.
rand_pass
and
(
args
.
numTeammates
>
0
):
print
(
"Randomizing order of checking for a pass"
)
if
args
.
eps
>
0
:
print
(
"Using eps(ilon) {0:n}"
.
format
(
args
.
eps
))
for
episode
in
itertools
.
count
():
num_eps
=
0
num_had_ball
=
0
num_move
=
0
status
=
hfo
.
IN_GAME
while
status
==
hfo
.
IN_GAME
:
state
=
hfo_env
.
getState
()
#print(state)
if
int
(
state
[
5
])
==
1
:
# state[5] is 1 when player has the ball
...
...
@@ -89,16 +96,29 @@ def main():
hfo_env
.
act
(
hfo
.
SHOOT
)
else
:
hfo_env
.
act
(
hfo
.
DRIBBLE
)
num_eps
+=
1
else
:
get_action
(
state
,
hfo_env
,
args
.
numTeammates
,
args
.
rand_pass
)
num_had_ball
+=
1
else
:
hfo_env
.
act
(
hfo
.
MOVE
)
num_move
+=
1
status
=
hfo_env
.
step
()
#print(status)
# Quit if the server goes down
if
status
==
hfo
.
SERVER_DOWN
:
hfo_env
.
act
(
hfo
.
QUIT
)
exit
()
# Check the outcome of the episode
print
(
"Episode {0:d} ended with {1:s}"
.
format
(
episode
,
hfo_env
.
statusToString
(
status
)))
if
args
.
eps
>
0
:
print
(
"
\t
Num move: {0:d}; Random action: {1:d}; Nonrandom: {2:d}"
.
format
(
num_move
,
num_eps
,
(
num_had_ball
-
num_eps
)))
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