📄 bs03_neck_bmn.c
字号:
/*Brainstormers 2D (Soccer Simulation League 2D)PUBLIC SOURCE CODE RELEASE 2005Copyright (C) 1998-2005 Neuroinformatics Group, University of Osnabrueck, GermanyThis program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/#include "bs03_neck_bmn.h"#include "mdp_info.h"#include <stdlib.h>#include <stdio.h>#include "types.h"#include "tools.h"#include "valueparser.h"#include "options.h"#include "cmd.h"#include "log_macros.h"#include "../policy/positioning.h"#include "angle.h"#include "ws_info.h"#include "../policy/policy_tools.h"#include "geometry2d.h"//#define LOG_AGE#define BASELEVEL 3#if 0 #define DBLOG_POL(LLL,XXX) LOG_POL(LLL,<<"BS02Neck: "<<XXX)#define DBLOG_DRAW(LLL,XXX) LOG_POL(LLL,<<_2D<<XXX)#else#define DBLOG_POL(LLL,XXX) #define DBLOG_DRAW(LLL,XXX)#endif #if 1#define MYLOG_POL(LLL,XXX) LOG_POL(LLL,<<"NECK: "<<XXX)#define MYLOG_DRAW(LLL,XXX) LOG_POL(LLL,<<_2D<<XXX)#else#define MYLOG_POL(LLL,XXX) #define MYLOG_DRAW(LLL,XXX)#endif /** Parameters */#define NUM_ANGLES 17 /* Number of possible view angles (Caution: time!) */#define MAX_VISIBLE_DISTANCE 50.0 /* Ignore objects/points further away */#define MAX_BALL_AGE 3 /* Look to ball if older! */#define MAX_FASTEST_OPP_AGE 2 /* ...if DECISION_TYPE_BLOCKBALLHOLDER is set! */#define MAX_GOALIE_AGE 2 /* only if we are carrying the ball... */#define SQR_MAX_VISIBLE_DISTANCE SQUARE(MAX_VISIBLE_DISTANCE)#define OFFSIDE_TOLERANCE 6#define IGNORE_OFFSIDE_GOAL_DISTANCE 18 #define MAX_OFFSIDE_LINE_AGE 3#define SECT_X BS02_NECK_SECT_X#define SECT_Y BS02_NECK_SECT_Y//#define VALUE_BASEDbool BS03Neck::initialized = false;BS03Neck::BS03Neck() { xunit=ServerOptions::pitch_length/SECT_X; yunit=ServerOptions::pitch_width/SECT_Y; norm_view_ang=ServerOptions::visible_angle * PI/180.0; ball_already_searched=false; need_lookto_ball=false; last_looked_to_goalie=-2; ValueParser vp(CommandLineOptions::policy_conf,"BS03Neck"); vp.get("intercept_look_mode",intercept_look_mode,1); vp.get("opp_has_ball_look_mode",opp_has_ball_look_mode,1); vp.get("own_has_ball_look_mode",own_has_ball_look_mode,1); vp.get("ball_holder_look_mode",ball_holder_look_mode,1); // ridi 04: Warum? vp.get("ignore_neck_intentions",ignore_neck_intentions,true); vp.get("ignore_neck_intentions",ignore_neck_intentions,false); vp.get("use_1v1_mode",use_1v1_mode,false); neck_cmd = new NeckCmd(); goalie_neck = new GoalieNeck();}BS03Neck::~BS03Neck() { delete neck_cmd; delete goalie_neck;}bool BS03Neck::get_cmd(Cmd &cmd) { //long starttime=Tools::get_current_ms_time(); if(!WSinfo::me) { cerr << "\nERROR [BS02_Neck]: WSinfo::me not set!\n"; return true; //return Move_Factory::get_Neck_Move(); } if ( WSinfo::ws->play_mode == PM_my_BeforeKickOff || WSinfo::ws->play_mode == PM_his_BeforeKickOff || WSinfo::ws->play_mode == PM_my_KickOff || WSinfo::ws->play_mode == PM_his_KickOff) { neck_cmd->set_turn_neck_abs( Tools::range_random( -PI/2.0, PI/2.0)); return neck_cmd->get_cmd(cmd); } if (ClientOptions::consider_goalie) { if(WSinfo::ws->play_mode == PM_PlayOn || WSinfo::ws->play_mode == PM_my_BeforePenaltyKick || WSinfo::ws->play_mode == PM_his_BeforePenaltyKick || WSinfo::ws->play_mode == PM_my_PenaltyKick || WSinfo::ws->play_mode == PM_his_PenaltyKick) { // Sput03: goalie should turn neck during standards... return goalie_neck->get_cmd(cmd); //::get_Dynamic_Neck_Goalie_Policy(); } } // Sput03: this will be called for the goalie during standards. //if(mdpInfo::am_I_goalie()) { //obsolete; should never be the case // cerr << "\nERROR [BS02_Neck]: BS02_Neck policy cannot handle the goalie!"; // return Move_Factory::get_Neck_Move(); //} if(WSinfo::ws->ms_time_of_see<WSinfo::ws->ms_time_of_sb) { //LOG_ERR(1,<<"WARNING: BS02_Neck: Did not get see update!"); MYLOG_POL(0,"TURN NECK- WARNING: Did not get see update!"); //cerr << "\n### Player "<<WSinfo::me->number<<", Cycle "<<WSinfo::ws->time<<": NO SEE UPDATE!"; got_update=false; } else got_update=true; init_cycle(cmd); MYLOG_POL(0,"NECK: regular looking!"); /* This is necessary for Face_Ball move! Do not remove! */ if(neck_intention.type==NECK_INTENTION_SCANFORBALL) { MYLOG_POL(0,"NECK: schanforball!"); //cerr << "\nP"<<WSinfo::me->number<<"cyc #"<<WSinfo::ws->time<<": Neck Lock!"; return neck_lock(cmd); } Angle target=-1; center_target=false; /* Daisy Chain */ if(target!=-1); else if(-1!=(target=check_neck_1v1())); // for penalty situations; use_1v1_mode must be 1 else if(-1!=(target=check_direct_opponent_defense())); else if(-1!=(target=check_search_ball())); else if(-1!=(target=check_neck_intention())); else if(-1!=(target=check_players_near_ball())); //else if(-1!=(target=check_block_ball_holder())); // obsolete - covered by neck intention! else if(-1!=(target=check_intercept())); else if(-1!=(target=check_offside()));#ifndef VALUE_BASED else if(-1!=(target=check_goalie()));#endif else if((-1!=(target=check_relevant_teammates()))); /* Wertfunktion / Defaultmove */ if(target==-1 || !center_target) { #ifdef VALUE_BASED Angle vb_target=neck_value_based(target);#else Angle vb_target=neck_default(target); /* new (pre-Padova) default move */ //Angle vb_target=-1;#endif if(target!=-1) { if(vb_target!=-1 && fabs(target-vb_target)<Tools::next_view_angle_width().get_value()*.5-DEG2RAD(4)) { MYLOG_POL(0,"Modifying selected target by "<<fabs(target-vb_target)<<"."); target=vb_target; } } else target=vb_target; } /* Move ausfuehren */ //long endtime=Tools::get_current_ms_time(); //DBLOG_POL(0,"Needed "<<endtime-starttime<<"ms."); if(target>-1) { #if 1 Vector pol; pol.init_polar(40,target);pol+=WSinfo::me->pos; DBLOG_DRAW(1,"LINE("<<WSinfo::me->pos.x<<","<<WSinfo::me->pos.y<<","<<pol.x<<","<<pol.y<<");");#endif DBLOG_POL(0, "Turning to " <<target<<" ("<<RAD2DEG(target)<<")..."); neck_cmd->set_turn_neck_abs(target); return neck_cmd->get_cmd(cmd); //return Move_Factory::get_Neck_Turn_Abs(target); } DBLOG_POL(0,"WARNING: No neck turn executed!"); ERROR_OUT << "WARNING: No neck turn executed!"; return true; //return Move_Factory::get_Neck_Move();}/** prepare all for current cycle, init variables and so on */void BS03Neck::init_cycle(Cmd &cmd) { mdpInfo::get_my_neck_intention(neck_intention); minang=Tools::my_minimum_abs_angle_to_see().get_value(); maxang=Tools::my_maximum_abs_angle_to_see().get_value(); //bool center_target=false; // look exactly to target? /* Model next cycle */ Tools::model_cmd_main(WSinfo::me->pos,WSinfo::me->vel,WSinfo::me->ang.get_value(),WSinfo::ball->pos, WSinfo::ball->vel,cmd.cmd_main, my_new_pos,my_new_vel,my_new_angle,new_ball_pos,new_ball_vel); own_players_near_ball=WSinfo::valid_teammates_without_me; opp_players_near_ball=WSinfo::valid_opponents; own_players_near_ball.keep_players_in_circle(WSinfo::ball->pos,1.8); opp_players_near_ball.keep_players_in_circle(WSinfo::ball->pos,1.8); players_near_ball=own_players_near_ball; players_near_ball+=opp_players_near_ball; distance_to_ball=(my_new_pos-new_ball_pos).norm(); ballinfeelrange=distance_to_ball<0.9*ServerOptions::visible_distance; //changed from 0.95 to 0.9 /*TG_OSAKA*/ potentialcollision = distance_to_ball < 2.5 * WSinfo::me->radius; dir_to_ball=(new_ball_pos-my_new_pos).ARG(); /* Update age information */#ifdef VALUE_BASED get_single_sector_weights();#endif Vector dum; dum.init_polar(1.0,WSinfo::me->neck_ang); Cone2d viewcone(WSinfo::me->pos,dum,ANGLE(Tools::cur_view_angle_width().get_value()-DEG2RAD(7))); Vector pos; if(WSinfo::ws->time>0) { cur_info.sector_avg=0; pos.y=-(SECT_Y-1)/2*yunit; for(int y=0; y<SECT_Y;y++,pos.y+= yunit) { pos.x=-(SECT_X-1)/2*xunit; for(int x=0;x<SECT_X;x++,pos.x+= xunit) { if(got_update && (WSinfo::me->pos-pos).sqr_norm()<MAX_VISIBLE_DISTANCE*MAX_VISIBLE_DISTANCE && viewcone.inside(pos)) cur_info.sector[x][y]=0; else cur_info.sector[x][y]++;#ifdef VALUE_BASED cur_info.sector_avg+=cur_info.sector[x][y]*single_sector_weight[x][y];#endif#ifdef LOG_AGE if(x%2) { DBLOG_DRAW(0,"STRING("<<pos.x<<","<<pos.y<<",\""<<cur_info.sector[x][y]<<"\");"); }#endif } }#ifdef VALUE_BASED cur_info.sector_avg/=single_sector_divisor; DBLOG_POL(1,"cur_info.sector_avg="<<cur_info.sector_avg);#endif } cur_info.ball=WSinfo::ball->age; if(WSinfo::ball->age<MAX_BALL_AGE) ball_already_searched=false;#ifdef VALUE_BASED cur_info.opponents=0; for(int p=0;p<WSinfo::valid_opponents.num;p++) { cur_info.opponents+=WSinfo::valid_opponents[p]->age; } if(WSinfo::valid_opponents.num>0) cur_info.opponents/=(Value)WSinfo::valid_opponents.num;#endif #ifdef LOG_AGE DBLOG_DRAW(1,"STRING col=555555 ("<<WSinfo::ball->pos.x<<","<<WSinfo::ball->pos.y <<",\"[-"<<cur_info.ball<<"-]\");");#endif //pos.x=mdpInfo::opponent_goalpos().x; //pos.y=mdpInfo::opponent_goalpos().y; //DBLOG_POL(1,"col=000000 CIRCLE("<<pos.x<<","<<pos.y<<",3);"); if(WSinfo::his_goalie) { cur_info.opp_goalie=WSinfo::his_goalie->age; } else { cur_info.opp_goalie=-1; } if(got_update && viewcone.inside(HIS_GOAL_RIGHT_CORNER)) { cur_info.opp_goal_right=0; } else { cur_info.opp_goal_right++; } if(got_update && viewcone.inside(HIS_GOAL_LEFT_CORNER)) { cur_info.opp_goal_left=0; } else { cur_info.opp_goal_left++; } if(got_update && viewcone.inside(HIS_GOAL_CENTER)) { cur_info.opp_goal=0; } else { cur_info.opp_goal++; } #ifdef LOG_AGE //DBLOG_POL(1,"STRING col=ffffff ("<<mdpInfo::opponent_goalpos().x<<"," // <<mdpInfo::opponent_goalpos().y<<",\"[-"<<cur_info.opp_goal_left<<"-]\");"); #endif}bool BS03Neck::can_see_object(Vector mypos,ANGLE neckdir,Vector objpos) { if((objpos-mypos).sqr_norm()>SQR_MAX_VISIBLE_DISTANCE) return false; Angle target=Tools::get_angle_between_null_2PI((objpos-mypos).angle()); Angle minang=(neckdir-ANGLE(.5*mdpInfo::view_angle_width_rad())).get_value(); Angle maxang=(neckdir+ANGLE(.5*mdpInfo::view_angle_width_rad())).get_value(); if(minang>maxang && (target<minang && target>maxang)) return false; if(minang<maxang && (target<minang || target>maxang)) return false; return true;}#ifdef VALUE_BASED/***************************************************************************************** * Value based neck policy *****************************************************************************************//** This function creates a new neck_info based on given parameters. * Attention: This does not check if ball is in feel range! * Invalid objects/players will be ignored and need to be already set to -1 * in the given neckinfo */Neck_Info BS03Neck::get_neck_info(Vector mypos,ANGLE neckdir,Vector ballpos, Neck_Info neckinfo) { Vector dum; dum.init_polar(1.0,neckdir); Cone2d viewcone(mypos,dum,Tools::next_view_angle_width()); Vector pos; neckinfo.sector_avg=0; pos.y=-(SECT_Y-1)/2*yunit; //int sectors_counted=0; for(int y=0; y<SECT_Y;y++, pos.y+= yunit) { pos.x=-(SECT_X-1)/2*xunit; for(int x=0;x<SECT_X;x++,pos.x+= xunit) { if((mypos-pos).sqr_norm()<SQR_MAX_VISIBLE_DISTANCE && viewcone.inside(pos)) neckinfo.sector[x][y]=0; else neckinfo.sector[x][y]++; neckinfo.sector_avg+=neckinfo.sector[x][y]*single_sector_weight[x][y]; //sectors_counted++; } } neckinfo.sector_avg/=single_sector_divisor; if(WSinfo::is_ball_pos_valid() && //(mypos-WSinfo::ball->pos).sqr_norm()<MAX_VISIBLE_DISTANCE*MAX_VISIBLE_DISTANCE && viewcone.inside(ballpos)) neckinfo.ball=0; else neckinfo.ball++; #if 0 for(int p=0;p<WSinfo::valid_opponents.num;p++) { if(can_see_object(mypos,neckdir,WSinfo::valid_opponents[p]->pos)) neckinfo.opp_player[WSinfo::valid_opponents[p]->number]=0; else neckinfo.opp_player[WSinfo::valid_opponents[p]->number]++; }#endif#if 0 for(int p=0;p<WSinfo::valid_teammates_without_me.num;p++) { if(can_see_object(mypos,neckdir,WSinfo::valid_teammates_without_me[p]->pos)) neckinfo.own_player[WSinfo::valid_teammates_without_me[p]->number]=0; else neckinfo.own_player[WSinfo::valid_teammates_without_me[p]->number]++; }#endif neckinfo.opponents=0; for(int p=0;p<WSinfo::valid_opponents.num;p++) { if(!viewcone.inside(WSinfo::valid_opponents[p]->pos)) { neckinfo.opponents+=WSinfo::valid_opponents[p]->age; } } if(WSinfo::valid_opponents.num>0) neckinfo.opponents/=(Value)WSinfo::valid_opponents.num; if(WSinfo::his_goalie) { if(viewcone.inside(WSinfo::his_goalie->pos)) { neckinfo.opp_goalie=0; } else { if(neckinfo.opp_goalie>=0) neckinfo.opp_goalie++; } } else { neckinfo.opp_goalie=-1; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -