📄 score_bms.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 "score_bms.h"#include "ws_info.h"#include "mdp_info.h"#include "oneortwo_step_kick_bms.h"#if 1#define BASELEVEL 0 // level for logging; should be 3 for quasi non-logging//#define LOG_DAN(YYY,XXX) LOG_DEB(YYY,XXX)#define LOG_DAN(YYY,XXX)#else#define BASELEVEL 3 // level for logging; should be 3 for quasi non-logging#define LOG_DAN(YYY,XXX)#endifbool Score::initialized = false;Score::Score() { last_time_look_to_goal = -1; goalshot_param1 = 0.3; goalshot_mode = 0; //standard goalshot nr_of_looks_to_goal = -1; ValueParser vp(CommandLineOptions::policy_conf,"score_bms"); vp.get("goalshot_param1", goalshot_param1); vp.get("goalshot_mode", goalshot_mode); oneortwo = new OneOrTwoStepKick();}Score::~Score() { delete oneortwo;}bool Score::get_cmd(Cmd &cmd) { /* Intention intention; Value speed; Vector target; if (test_shoot2goal(intention)) { speed = intention.kick_speed; target = intention.kick_target; mdpInfo::set_my_intention(DECISION_TYPE_SCORE, speed, 0, target.x, target.y,0); LOG_POL(BASELEVEL,<<"Score get_cmd: try to score w speed "<<speed<<" to target "<<target); neurokick->kick_to_pos_with_initial_vel(speed,target); neurokick->get_cmd(cmd); return true; } else { return false; } */}bool Score::test_shoot2goal(Intention &intention) { int multi_step; Value velocity, direction; Vector target; int best_index; int result = get_goalshot_chance(multi_step, velocity, direction, target, best_index); Value target_dir = (mdpInfo::opponent_goalpos()-WSinfo::me->pos).arg(); risky_goalshot_possible = 0; intention.immediatePass = false; //allow multi kicks via neurokick! if(goalshot_mode == 0){ if (result == 4) result = 1; } else{ if (result == 4) LOG_ERR(0,"Goalshot risky, continue planning"); } if (result == 0) { LOG_DAN(BASELEVEL,"no goalshot found"); //no shot found return false; } else if (result == 1) { //secure shot if (multi_step) { LOG_DAN(0, << "shoot with neuro_kick2! velocity = " << velocity << " target.x = " << target.x << " target.y = " << target.y); mdpInfo::set_my_neck_intention(NECK_INTENTION_LOOKINDIRECTION, target_dir);//direction); //set_aaction_score(aaction, target, velocity); intention.set_score(target, velocity, WSinfo::ws->time); return true; //return Move_Factory::get_1or2_Step_Kick(velocity, target); } else { LOG_DAN(0, << "shoot with one step kick! velocity = " << velocity << " dir = " << direction); intention.set_score(target, velocity, WSinfo::ws->time); return true; // return Move_Factory::get_1Step_Kick(velocity, direction); } } else if (result == 2) { //risky because of goalie_age? if ((mdpInfo::opponent_goalpos() - WSinfo::me->pos).norm() > 30.0) { LOG_DAN(BASELEVEL,"result 2 and too far away"); return false; }#if 0 // ridi 22.6.03 : replaced by new access to goalie WSpset alive_opps = WSinfo::alive_opponents; PPlayer goalie = alive_opps.get_player_by_number(WSinfo::ws->his_goalie_number);#endif PPlayer goalie; if(WSinfo::his_goalie) goalie = WSinfo::his_goalie; else return false; //if (goalie == NULL) return false; WSpset pset_tmp = WSinfo::valid_opponents; pset_tmp.keep_players_in_circle(WSinfo::me->pos, 3.0); if (pset_tmp.num > 0) { LOG_DAN(0, << "doing a risky shot because opponents are close!"); if (multi_step) { LOG_DAN(0, << "shoot with neuro_kick2! velocity = " << velocity << " target.x = " << target.x << " target.y = " << target.y); mdpInfo::set_my_intention(DECISION_TYPE_SCORE, velocity, direction, target.x, target.y, best_index); mdpInfo::set_my_neck_intention(NECK_INTENTION_LOOKINDIRECTION, target_dir);//direction); intention.set_score(target, velocity, WSinfo::ws->time); //set_aaction_score(aaction, target, velocity); return true; //return Move_Factory::get_Neuro_Kick2(5, velocity, target.x, target.y); } else { LOG_DAN(0, << "shoot with one step kick! velocity = " << velocity << " dir = " << direction); // return Move_Factory::get_1Step_Kick(velocity, direction); intention.set_score(target, velocity, WSinfo::ws->time); //set_aaction_score(aaction, target, velocity); return true; } } else { if (goalie->age <= 4) { LOG_DAN(0, << "opponent goalie too young, don't look to him"); return false; } LOG_DAN(0, << "opponent goalie too old, look to goal with hold ball"); //Value target_dir = (mdpInfo::opponent_goalpos()-WSinfo::me->pos).arg(); if (last_time_look_to_goal != WSinfo::ws->time - 1) { nr_of_looks_to_goal = 1; } else { ++nr_of_looks_to_goal; } last_time_look_to_goal = WSinfo::ws->time; /* if (nr_of_looks_to_goal == 1) { LOG_DAN(0, << "look to center of goal"); target_dir = (mdpInfo::opponent_goalpos()-WSinfo::me->pos).arg(); } else if (nr_of_looks_to_goal == 2) { LOG_DAN(0, << "look to left goalcorner"); target_dir = (ServerOptions::their_left_goal_corner-WSinfo::me->pos).arg(); } else if (nr_of_looks_to_goal == 3) { LOG_DAN(0, << "look to right goalcorner"); target_dir = (ServerOptions::their_right_goal_corner-WSinfo::me->pos).arg(); } else if (nr_of_looks_to_goal == 4) {*/ if (nr_of_looks_to_goal >= 3) { if (multi_step) { LOG_DAN(0, << "I looked to goal, didn't see goalie and I'm close to goal, shoot"); LOG_DAN(0, << "shoot with neuro_kick2! velocity = " << velocity << " target.x = " << target.x << " target.y = " << target.y); mdpInfo::set_my_neck_intention(NECK_INTENTION_LOOKINDIRECTION, direction); mdpInfo::set_my_intention(DECISION_TYPE_SCORE, velocity, direction, target.x, target.y, best_index); intention.set_score(target, velocity, WSinfo::ws->time); //set_aaction_score(aaction, target, velocity); return true; } else { LOG_DAN(0, << "shoot with one step kick! velocity = " << velocity << " dir = " << direction); //return Move_Factory::get_1Step_Kick(velocity, direction); intention.set_score(target, velocity, WSinfo::ws->time); //set_aaction_score(aaction, target, velocity); return true; } } mdpInfo::set_my_neck_intention(NECK_INTENTION_LOOKINDIRECTION, target_dir); if(mdpInfo::could_see_in_direction(target_dir) == true) { // I can see in direction by turning neck without turning body mdpInfo::set_my_neck_intention(NECK_INTENTION_LOOKINDIRECTION, target_dir); mdpInfo::set_my_intention(DECISION_TYPE_LOOKFORGOALIE, mdpInfo::opponent_goalpos().x, mdpInfo::opponent_goalpos().y); // ridi03:todo // return Move_Factory::get_Hold_Ball(1); //LOG_ERR(0,"WBALL03: should hold ball and look; not yet implemented"); //LOG_DAN(BASELEVEL,"WBALL03: should hold ball and look; not yet implemented"); intention.set_holdturn(ANGLE(target_dir), WSinfo::ws->time); return true; } else { // have to turn body. LOG_DAN(0, " have to turn body, but don't do it"); last_time_look_to_goal = -1; return false; /* mdpInfo::set_my_neck_intention(NECK_INTENTION_LOOKINDIRECTION, target_dir); return Move_Factory::get_Hold_Ball(target_dir,1); */ } } } else if (result == 3) { //risky because opponent could intercept } else if (result == 4) { //risky because goal could be missed saved_velocity = velocity; saved_direction = direction; saved_target = target; saved_multi_step = multi_step; risky_goalshot_possible = 1; } else if ((result == 5) || (result == 6)) { //opponent goalie not alive or goalie number not known or other strange problem if ((mdpInfo::opponent_goalpos() - WSinfo::me->pos).norm() > 25.0) { LOG_DAN(0, " result 5 and too far"); return false; } LOG_DAN(0, << "opponent goalie not alive, number not known or other strange problem, look to goal with hold ball"); Value target_dir = (mdpInfo::opponent_goalpos()-WSinfo::me->pos).arg(); if (last_time_look_to_goal != WSinfo::ws->time - 1) { nr_of_looks_to_goal = 1; } else { ++nr_of_looks_to_goal; } last_time_look_to_goal = WSinfo::ws->time; target_dir = (mdpInfo::opponent_goalpos()-WSinfo::me->pos).arg(); /* if (nr_of_looks_to_goal == 1) target_dir = (mdpInfo::opponent_goalpos()-WSinfo::me->pos).arg(); else if (nr_of_looks_to_goal == 2) target_dir = (ServerOptions::their_left_goal_corner-WSinfo::me->pos).arg(); else if (nr_of_looks_to_goal == 3) target_dir = (ServerOptions::their_right_goal_corner-WSinfo::me->pos).arg(); else if (nr_of_looks_to_goal == 4) {*/ if (nr_of_looks_to_goal >= 3) { if (result == 6) { Vector goal = Vector(ServerOptions::pitch_length/2.0, 0.0); ANGLE angle = (goal-WSinfo::ball->pos).ARG(); Value one_step_vel, multi_step_vel; //Move_1or2_Step_Kick::get_vel_in_dir(3.0, angle, one_step_vel, multi_step_vel); oneortwo->kick_in_dir_with_max_vel(ANGLE(angle)); oneortwo->get_vel(one_step_vel, multi_step_vel); if (one_step_vel > ServerOptions::ball_speed_max) one_step_vel = ServerOptions::ball_speed_max; if (multi_step_vel > ServerOptions::ball_speed_max) multi_step_vel = ServerOptions::ball_speed_max; LOG_DAN(0, << "I looked to goal, didn't see goalie AND opponents and I'm close to goal, shoot"); LOG_DAN(0, << "shoot with neuro_kick2! velocity = " << multi_step_vel << " target.x = " << goal.x << " target.y = " << goal.y); mdpInfo::set_my_neck_intention(NECK_INTENTION_LOOKINDIRECTION, (goal-WSinfo::me->pos).arg()); //return Move_Factory::get_Neuro_Kick2(5, velocity, target.x, target.y); intention.set_score(goal, multi_step_vel, WSinfo::ws->time); //set_aaction_score(aaction, target, velocity); return true; } if (multi_step) { LOG_DAN(0, << "I looked to goal, didn't see goalie and I'm close to goal, shoot"); LOG_DAN(0, << "shoot with neuro_kick2! velocity = " << velocity << " target.x = " << target.x << " target.y = " << target.y); mdpInfo::set_my_neck_intention(NECK_INTENTION_LOOKINDIRECTION, (target-WSinfo::me->pos).arg()); //return Move_Factory::get_Neuro_Kick2(5, velocity, target.x, target.y); intention.set_score(target, velocity, WSinfo::ws->time); //set_aaction_score(aaction, target, velocity); return true; //return Move_Factory::get_1or2_Step_Kick(velocity, target); } else { LOG_DAN(0, << "shoot with one step kick! velocity = " << velocity << " dir = " << direction); intention.set_score(target, velocity, WSinfo::ws->time); //set_aaction_score(aaction, target, velocity); return true; //return Move_Factory::get_1Step_Kick(velocity, direction); } } mdpInfo::set_my_neck_intention(NECK_INTENTION_LOOKINDIRECTION, target_dir); if(mdpInfo::could_see_in_direction(target_dir) == true) { // I can see in direction by turning neck without turning body mdpInfo::set_my_neck_intention(NECK_INTENTION_LOOKINDIRECTION, target_dir); mdpInfo::set_my_intention(DECISION_TYPE_LOOKFORGOALIE, mdpInfo::opponent_goalpos().x, mdpInfo::opponent_goalpos().y); // ridi03:todo // return Move_Factory::get_Hold_Ball(1); LOG_ERR(0,"WBALL03: should hold ball and look; not yet implemented"); LOG_DAN(0,"WBALL03: should hold ball and look; not yet implemented"); intention.set_holdturn(ANGLE(target_dir), WSinfo::ws->time); return true; } else { // have to turn body. LOG_DAN(0, " have to turn body, but don't do it"); last_time_look_to_goal = -1; return false; } } LOG_DAN(0, " shoot 2 goal - unsuccessful result "<<result); return false;}int Score::get_goalshot_chance(int &multi_step, Value &velocity, Value &direction, Vector &target, int &best_index) { if (WSinfo::me->pos.x < 15.0) return 0; if ( (Tools::my_abs_angle_to(Vector(FIELD_BORDER_X, 0.0)).get_value() > DEG2RAD(83)) && (Tools::my_abs_angle_to(Vector(FIELD_BORDER_X, 0.0)).get_value() < DEG2RAD(277)) && fabs(WSinfo::me->pos.y) > 8.0) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -