Skip to content

Commit 36651ae

Browse files
committed
fix trainer bugs
1 parent 8b06f74 commit 36651ae

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/grpc-client/grpc_client_trainer.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <rcsc/player/say_message_builder.h>
55
#include <rcsc/common/player_param.h>
6+
#include "grpc-client/state_generator.h"
67

78
#include <chrono>
89
#include <rcsc/common/logger.h>
@@ -14,8 +15,8 @@ using std::chrono::milliseconds;
1415
#define DEBUG
1516

1617
#ifdef DEBUG
17-
#define LOG(x) std::cout << x << std::endl
18-
#define LOGV(x) std::cout << #x << ": " << x << std::endl
18+
#define LOG(x) std::cout << "Trainer: " << x << std::endl
19+
#define LOGV(x) std::cout << "Trainer: " << #x << ": " << x << std::endl
1920
#else
2021
#define LOG(x)
2122
#define LOGV(x)
@@ -277,8 +278,8 @@ void GrpcClientTrainer::getActions()
277278
State GrpcClientTrainer::generateState() const
278279
{
279280
auto &wm = M_agent->world();
280-
// WorldModel * worldModel = StateGenerator::convertCoachWorldModel(wm);
281+
protos::WorldModel * worldModel = StateGenerator::convertCoachWorldModel(wm);
281282
State state;
282-
// state.set_allocated_world_model(worldModel);
283+
state.set_allocated_world_model(worldModel);
283284
return state;
284285
}

src/grpc-client/state_generator.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,10 @@ void StateGenerator::updatePlayerObject(protos::Player *p, const rcsc::CoachPlay
272272
p->set_is_kicking(player->isKicking());
273273
p->set_ball_reach_steps(player->ballReachStep());
274274
p->set_is_tackling(player->isTackling());
275-
p->set_type_id(player->playerTypePtr()->id());
275+
if (player->playerTypePtr() != nullptr)
276+
p->set_type_id(player->playerTypePtr()->id());
277+
else
278+
p->set_type_id(0);
276279
}
277280

278281
/**
@@ -475,19 +478,23 @@ protos::WorldModel *StateGenerator::convertWorldModel(const rcsc::WorldModel &wm
475478
*/
476479
protos::WorldModel *StateGenerator::convertCoachWorldModel(const rcsc::CoachWorldModel &wm)
477480
{
478-
auto *res = new WorldModel();
481+
auto *res = new protos::WorldModel();
479482
res->set_allocated_our_team_name(new std::string(wm.ourTeamName()));
480483
res->set_allocated_their_team_name(new std::string(wm.theirTeamName()));
481484
res->set_our_side(convertSide(wm.ourSide()));
482485
res->set_last_set_play_start_time(wm.lastSetPlayStartTime().cycle());
483486
res->set_allocated_ball(convertBall(wm.ball()));
484487
for (auto player : wm.teammates())
485488
{
489+
if (player == nullptr)
490+
continue;
486491
auto p = res->add_teammates();
487492
updatePlayerObject(p, player);
488493
}
489494
for (auto player : wm.opponents())
490495
{
496+
if (player == nullptr)
497+
continue;
491498
auto p = res->add_opponents();
492499
updatePlayerObject(p, player);
493500
}

src/train.sh.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ fi
135135
#if [ "${usecoach}" = "true" ]; then
136136
# $coach -h $host -t $teamname &
137137
#fi
138+
$player ${OPT} -n 1 --rpc-type ${rpc_type} &
139+
$sleepprog $sleeptime
138140
trainer_opt="-h $host -t $teamname"
139141
trainer_opt="${trainer_opt} --g-port ${g_port}"
140142
trainer_opt="${trainer_opt} --rpc-type ${rpc_type}"

0 commit comments

Comments
 (0)