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
b387747e
You need to sign in or sign up before continuing.
Commit
b387747e
authored
Feb 23, 2016
by
Matthew Hausknecht
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplified includes.
parent
875bde45
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
34 deletions
+49
-34
hfo/hfo_c_wrapper.h
hfo/hfo_c_wrapper.h
+1
-1
setup.py
setup.py
+1
-1
src/HFO.cpp
src/HFO.cpp
+36
-23
src/HFO.hpp
src/HFO.hpp
+8
-9
src/common.hpp
src/common.hpp
+3
-0
No files found.
hfo/hfo_c_wrapper.h
View file @
b387747e
...
...
@@ -2,7 +2,7 @@
#define __HFO_C_WRAPPER_H__
#include <vector>
#include <string.h>
#include <HFO.hpp>
#include <common.hpp>
...
...
setup.py
View file @
b387747e
...
...
@@ -8,7 +8,7 @@ if not os.path.isfile(hfo_c_lib):
module1
=
Extension
(
'hfo.hfo_c_wrapper'
,
libraries
=
[
'hfo_c'
],
include_dirs
=
[
'src'
,
'src/chain_action'
,
'build/librcsc-prefix/src/librcsc'
],
include_dirs
=
[
'src'
],
library_dirs
=
[
'hfo'
],
extra_compile_args
=
[
'-D__STDC_CONSTANT_MACROS'
],
sources
=
[
'hfo/hfo_c_wrapper.cpp'
])
...
...
src/HFO.cpp
View file @
b387747e
...
...
@@ -11,9 +11,22 @@
#include <iostream>
#include <stdarg.h>
#include <agent.h>
#include <rcsc/common/basic_client.h>
#include <rcsc/player/player_config.h>
#include <rcsc/player/world_model.h>
using
namespace
hfo
;
HFOEnvironment
::
HFOEnvironment
()
{
client
=
new
rcsc
::
BasicClient
();
agent
=
new
Agent
();
}
HFOEnvironment
::~
HFOEnvironment
()
{
delete
client
;
delete
agent
;
}
void
HFOEnvironment
::
connectToServer
(
feature_set_t
feature_set
,
std
::
string
config_dir
,
int
uniform_number
,
...
...
@@ -21,37 +34,37 @@ void HFOEnvironment::connectToServer(feature_set_t feature_set,
std
::
string
server_addr
,
std
::
string
team_name
,
bool
play_goalie
)
{
agent
.
setFeatureSet
(
feature_set
);
rcsc
::
PlayerConfig
&
config
=
agent
.
mutable_config
();
agent
->
setFeatureSet
(
feature_set
);
rcsc
::
PlayerConfig
&
config
=
agent
->
mutable_config
();
config
.
setConfigDir
(
config_dir
);
config
.
setPlayerNumber
(
uniform_number
);
config
.
setPort
(
server_port
);
config
.
setHost
(
server_addr
);
config
.
setTeamName
(
team_name
);
config
.
setGoalie
(
play_goalie
);
if
(
!
agent
.
init
(
&
client
,
0
,
NULL
))
{
if
(
!
agent
->
init
(
client
,
0
,
NULL
))
{
std
::
cerr
<<
"Init failed"
<<
std
::
endl
;
exit
(
1
);
}
client
.
setClientMode
(
rcsc
::
BasicClient
::
ONLINE
);
if
(
!
client
.
startAgent
(
&
agent
))
{
client
->
setClientMode
(
rcsc
::
BasicClient
::
ONLINE
);
if
(
!
client
->
startAgent
(
agent
))
{
std
::
cerr
<<
"Unable to start agent"
<<
std
::
endl
;
exit
(
1
);
}
assert
(
client
.
isServerAlive
()
==
true
);
while
(
agent
.
getState
().
empty
())
{
assert
(
client
->
isServerAlive
()
==
true
);
while
(
agent
->
getState
().
empty
())
{
step
();
}
}
const
std
::
vector
<
float
>&
HFOEnvironment
::
getState
()
{
return
agent
.
getState
();
return
agent
->
getState
();
}
void
HFOEnvironment
::
act
(
action_t
action
,
...)
{
agent
.
setAction
(
action
);
agent
->
setAction
(
action
);
int
n_args
=
NumParams
(
action
);
std
::
vector
<
float
>
*
params
=
agent
.
mutable_params
();
std
::
vector
<
float
>
*
params
=
agent
->
mutable_params
();
params
->
resize
(
n_args
);
va_list
vl
;
va_start
(
vl
,
action
);
...
...
@@ -62,35 +75,35 @@ void HFOEnvironment::act(action_t action, ...) {
}
void
HFOEnvironment
::
act
(
action_t
action
,
const
std
::
vector
<
float
>&
params
)
{
agent
.
setAction
(
action
);
agent
->
setAction
(
action
);
int
n_args
=
NumParams
(
action
);
assert
(
n_args
==
params
.
size
());
std
::
vector
<
float
>
*
agent_params
=
agent
.
mutable_params
();
std
::
vector
<
float
>
*
agent_params
=
agent
->
mutable_params
();
(
*
agent_params
)
=
params
;
}
void
HFOEnvironment
::
say
(
const
std
::
string
&
message
)
{
agent
.
setSayMsg
(
message
);
agent
->
setSayMsg
(
message
);
}
std
::
string
HFOEnvironment
::
hear
()
{
return
agent
.
getHearMsg
();
return
agent
->
getHearMsg
();
}
Player
HFOEnvironment
::
playerOnBall
()
{
return
agent
.
getPlayerOnBall
();
return
agent
->
getPlayerOnBall
();
}
status_t
HFOEnvironment
::
step
()
{
bool
end_of_trial
=
agent
.
getGameStatus
()
!=
IN_GAME
;
long
start_cycle
=
agent
.
cycle
();
while
((
agent
.
cycle
()
<=
start_cycle
)
||
(
agent
.
getLastDecisionTime
()
<
agent
.
cycle
())
||
(
end_of_trial
&&
agent
.
getGameStatus
()
!=
IN_GAME
))
{
client
.
runStep
(
&
agent
);
if
(
!
client
.
isServerAlive
())
{
bool
end_of_trial
=
agent
->
getGameStatus
()
!=
IN_GAME
;
long
start_cycle
=
agent
->
cycle
();
while
((
agent
->
cycle
()
<=
start_cycle
)
||
(
agent
->
getLastDecisionTime
()
<
agent
->
cycle
())
||
(
end_of_trial
&&
agent
->
getGameStatus
()
!=
IN_GAME
))
{
client
->
runStep
(
agent
);
if
(
!
client
->
isServerAlive
())
{
return
SERVER_DOWN
;
}
}
return
agent
.
getGameStatus
();
return
agent
->
getGameStatus
();
}
src/HFO.hpp
View file @
b387747e
...
...
@@ -3,18 +3,17 @@
#include <string>
#include <vector>
#include <rcsc/common/basic_client.h>
#include <rcsc/player/player_config.h>
#include <rcsc/player/world_model.h>
#include "agent.h"
#include "common.hpp"
class
Agent
;
namespace
rcsc
{
class
BasicClient
;
}
namespace
hfo
{
class
HFOEnvironment
{
public:
HFOEnvironment
()
{}
;
virtual
~
HFOEnvironment
()
{}
;
HFOEnvironment
();
virtual
~
HFOEnvironment
();
/**
* Connect to the server on the specified port. The
...
...
@@ -54,9 +53,9 @@ class HFOEnvironment {
// progress. Returns the game status after the step
virtual
status_t
step
();
pr
otected
:
rcsc
::
BasicClient
client
;
Agent
agent
;
pr
ivate
:
rcsc
::
BasicClient
*
client
;
Agent
*
agent
;
};
}
// namespace hfo
...
...
src/common.hpp
View file @
b387747e
#ifndef __COMMON_HPP__
#define __COMMON_HPP__
#include <assert.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
namespace
hfo
{
...
...
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