void Agent::SaveActiveBehavior(const ActiveBehavior & beh) { BehaviorType type = beh.GetType(); Assert(type > BT_None && type < BT_Max); if (mActiveBehavior[type] != 0) { if (*mActiveBehavior[type] < beh) { delete mActiveBehavior[type]; mActiveBehavior[type] = new ActiveBehavior(beh); } } else { mActiveBehavior[type] = new ActiveBehavior(beh); } }
void Player::Run() { //TIMETEST("Run"); static Time last_time = Time(-100, 0); mpObserver->Lock(); /** 下面几个更新顺序不能变 */ //Formation::instance.SetTeammateFormations(); //Hereo CommunicateSystem::instance().Update(); //在这里解析hear信息,必须首先更新 mpAgent->CheckCommands(mpObserver); mpWorldModel->Update(mpObserver); mpObserver->UnLock(); const Time & time = mpAgent->GetWorldState().CurrentTime(); if (last_time.T() >= 0) { if (time != Time(last_time.T() + 1, 0) && time != Time(last_time.T(), last_time.S() + 1)) { if (time == last_time) { mpAgent->World().SetCurrentTime(Time(last_time.T(), last_time.S() + 1)); //否则决策数据更新会出问题 } } } last_time = time; //Look here - Player logic starts from here PlayMode mpCurrentPlayMode = mpAgent->World().GetPlayMode(); PlayerState mpCurrentPlayerState = mpAgent->GetSelf(); PositionInfo mpCurrentPositionInfo = mpAgent->Info().GetPositionInfo(); Vector myPosition = mpAgent->GetSelf().GetPos(); double myDisToBall = mpCurrentPositionInfo.GetBallDistToPlayer(mpAgent->GetSelfUnum()); Vector ballpos = mpAgent->GetWorldState().GetBall().GetPos(); if(mpCurrentPlayMode==PM_Before_Kick_Off){ //TODO: Replace with an array + loop //std::cout<<PlayerParam::instance().teamName()<<std::endl; if(!isPositioned){ if(mpAgent->GetSelfUnum() == 1){ Vector player_pos = Vector(-45.0, 0.0); mpAgent->Move(player_pos); isPositioned = true; } if(mpAgent->GetSelfUnum() == 2){ Vector player_pos = Vector(-45.0, 10.0); mpAgent->Move(player_pos); isPositioned = true; } if(mpAgent->GetSelfUnum() == 3){ Vector player_pos = Vector(-45.0, -10.0); mpAgent->Move(player_pos); isPositioned = true; } if(mpAgent->GetSelfUnum() == 4){ Vector player_pos = Vector(-20.0, 0.0); mpAgent->Move(player_pos); isPositioned = true; } if(mpAgent->GetSelfUnum() == 5){ Vector player_pos = Vector(-20.0, -20.0); mpAgent->Move(player_pos); isPositioned = true; } if(mpAgent->GetSelfUnum() == 6){ Vector player_pos = Vector(-20.0, 20.0); mpAgent->Move(player_pos); isPositioned = true; } if(mpAgent->GetSelfUnum() == 7){ Vector player_pos = Vector(-15.0, -15.0); mpAgent->Move(player_pos); isPositioned = true; } if(mpAgent->GetSelfUnum() == 8){ Vector player_pos = Vector(-15.0, 15.0); mpAgent->Move(player_pos); isPositioned = true; } if(mpAgent->GetSelfUnum() == 9){ Vector player_pos = Vector(0.0, -20.0); mpAgent->Move(player_pos); isPositioned = true; } if(mpAgent->GetSelfUnum() == 10){ Vector player_pos = Vector(0.0, 1.0); mpAgent->Move(player_pos); isPositioned = true; } if(mpAgent->GetSelfUnum() == 11){ Vector player_pos = Vector(0.0, 20.0); mpAgent->Move(player_pos); isPositioned = true; } std::cout << "Positioned" << std::endl; } } else { if(mpAgent->GetFollowBall()){ if(mpCurrentPlayerState.IsKickable()){ std::cout<<"player "<< mpAgent->GetSelfUnum()<<" - ball kickable"<<std::endl; Vector nearestHole = RoundToNearestHole(myPosition); if(PassPlayersAvailable()){ std::cout <<"--------------------------------------------------------"<<std::endl; std::cout<<"player "<< mpAgent->GetSelfUnum()<<" - pass players available"<<std::endl; if(PassToBestPlayer()) mpAgent->SetFollowBall(false); } else{ std::cout<<"player "<< mpAgent->GetSelfUnum()<<" - holding ball"<<std::endl; ActiveBehavior beh = ActiveBehavior(*mpAgent, BT_Hold); if (beh.GetType() != BT_None) { mpAgent->SetActiveBehaviorInAct(beh.GetType()); if(beh.Execute()); //mpAgent->SetFollowBall(false); //std::cout<<"Holding ball."<<std::endl; } } } else Dasher::instance().GetBall(*mpAgent, -1, true, false); //std::cout<<"Player "<<mpAgent->GetSelfUnum() <<" following ball"<<std::endl; //std::cout<<mpAgent->RecvdMsg<<std::endl; //mpIntransit = true; //mpTarget = ballpos; //mpAgent->SetFollowBall(false); } /* if(mpAgent->GetFollowBall()){ mpIntransit = true; mpTarget = ballpos; } */ //TODO: Use transit variable for faster calling of the OccupyHole/Dasher functions //TODO: Better dash function //TODO: Look at buffer values //TODO: Find why ball holding is competed by players //TODO: Look at TODOs in the header file //TODO: Create a 'holding'/'waiting' variable which is true when the player is sspposed to kick the ball else if(mpIntransit){ if(!AreSamePoints(myPosition, mpTarget, 0.3)) Dasher::instance().GoToPoint(*mpAgent, mpTarget, 0.3, 100, true, false); else{ mpIntransit = false; //mpAgent->SetFollowBall(false); } } else if(mpCurrentPlayerState.IsKickable()){ //mpAgent->SetFollowBall(false); //mpAgent->SetFollowBall(false); //&&!BallKickableByATeammate() //if suitable holes have players available, pass //else, hold on to ball std::cout<<"player "<< mpAgent->GetSelfUnum()<<" - ball kickable"<<std::endl; Vector nearestHole = RoundToNearestHole(myPosition); if(PassPlayersAvailable()){ std::cout <<"--------------------------------------------------------"<<std::endl; std::cout<<"player "<< mpAgent->GetSelfUnum()<<" - pass players available"<<std::endl; if(PassToBestPlayer()) mpAgent->SetFollowBall(false); } else{ std::cout<<"player "<< mpAgent->GetSelfUnum()<<" - holding ball"<<std::endl; ActiveBehavior beh = ActiveBehavior(*mpAgent, BT_Hold); if (beh.GetType() != BT_None) { mpAgent->SetActiveBehaviorInAct(beh.GetType()); if(beh.Execute()); //mpAgent->SetFollowBall(false); //std::cout<<"Holding ball."<<std::endl; } } } else if(myDisToBall<=1){ //Dasher::instance().GoToPoint(*mpAgent, ballpos, 0.3, 100, true, false); std::cout<<"player "<< mpAgent->GetSelfUnum()<<" - in transit towards ball"<<std::endl; //mpIntransit = true; //mpTarget = ballpos; Dasher::instance().GetBall(*mpAgent, -1, true, false); //mpAgent->SetFollowBall(true); } else { //if(myDisToBall>1) if(BallKickableByATeammate()){ std::cout<<"ball kickable by teammate - will decide and occupy hole - "<<mpAgent->GetSelfUnum()<<std::endl; DecideAndOccupyHole(); } //else if(mpAgent->GetSelfUnum()==10); //Dasher::instance().GoToPoint(*mpAgent, ballpos, 0.3, 100, true, false); //if ball is with a player //if player has empty holes, dash to the hole //else, do nothing //else, do nothing } } //Formation::instance.UpdateOpponentRole(); //TODO: 暂时放在这里,教练未发来对手阵型信息时自己先计算 //Hereo VisualSystem::instance().ResetVisualRequest(); //mpDecisionTree->Decision(*mpAgent); // TODO:V: Replace or remove //Hereo VisualSystem::instance().Decision(); CommunicateSystem::instance().Decision(); mpAgent->SetHistoryActiveBehaviors(); //Hereo Logger::instance().LogSight(); }