📄 myteam.cpp~
字号:
/*************************************************************************** * Copyright (C) 2006 by root * * root@linux * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of 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 of * * MERCHANTABILITY or FITNESS FOR A paramTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/#ifdef HAVE_CONFIG_H#include <config.h>#endif#include <string>#include <sstream>#include <sys/types.h>#include <stdio.h>#include <unistd.h>#include <iostream>#include <fstream>#include <cstdlib>#include <time.h>#include <math.h>#include "param.h"#include "geometry.h"#include "file.h"#include "worldmodel.h"#include "connect.h"#include "command.h"#include "skills.h"#include "connect.h"using namespace std;using namespace MSpace;Connect net;Skills skills;Param param;Geometry geometry;Command command;File file;Worldmodel world;int main(int argc, char *argv[]){ file.ReadFormationIntoArray(); int SenceCount=0; Vec v,v2; bool done=false; double timetemp,time=0; Vec tempP,interupt; MoveState state; int rely=0; bool kickover=true; if(argc>1)param.TeamName=argv[1]; while(true) { if(!net.GetInput())break; //cout<<net.GetMsg()<<endl; if(param.CycleSent<70) { param.GetCycle(net.GetMsg()); param.GetInit(net.GetMsg(),net.MessageLength); } else if(SenceCount>0) param.prase(net.GetMsg(),net.MessageLength); char st=net.GetMsg()[0]; if(st=='D') net.PutOutputs("I"); else if(st == 'S' || st == 'T') { if(SenceCount == 0) net.PutOutputs("A(create)"); else if(SenceCount == 1) { command.Create(param.TeamName,0); } else { if(st=='S')world.Updata(); if(param.PlayMode=="BeforeKickOff") { v.Vx=file.FT_initial[param.PlayerNumber-1][0]; v.Vy=file.FT_initial[param.PlayerNumber-1][1]; command.Beam(v); } else { world.SetFormation(2); world.UpBallState(); if(st=='T')world.ForeseeMyState(); Vec position=world.GetMeV(); Vec ballp=world.GetBallV(); Pol pol=world.GetBallP(); if(st=='S') { world.UpMystate(); // if(param.CycleSent!=param.BallCycle)skills.FindBall(); for(int cycle=STEP;cycle<20;cycle=cycle+STEP) { command.Notify(param.CycleReceive+cycle); } } state=world.GetMyState(); MoveState state_ball; state_ball=world.GetBallState(); if(world.IsUsKickOff()&¶m.PlayerNumber==9) { v=Vec(50,0,0); command.PutDrive(v); } else if(param.PlayerNumber!=13) { if(world.IsMeClosestToBall()) { Vec v=state_ball.PositionV-state.PositionV; v.Vz=0; double Intercept_time; Vec V=world.InterceptBall(Intercept_time,rely); V.Vz=0; if(v.GetMod()>0.5&&kickover) { Vec correction; skills.DashTo(V,correction); } else { kickover=false; Vec arm1=Vec(0,0,0); skills.KickToAir(arm1,4.0,kickover); //Angel a(35); //command.PutKick(a,100); } //agent.Say("gogogo"); } else { Vec posV=world.GetMyStrategy(); Vec correction; skills.DashTo(posV,correction); } } else if(param.PlayerNumber==13) { if(world.IsMeClosestToBall()) { Vec v=state_ball.PositionV-state.PositionV; v.Vz=0; double Intercept_time; Vec V=world.InterceptBall(Intercept_time,rely); V.Vz=0; if(v.GetMod()>2.0) { Vec correction; skills.DashTo(V,correction); } else { //Vec arm1=Vec(0,0,0); //skills.KickToGround(arm1,4.0,over); Angel ang(-45); skills.DribbleTo(ang,2); //Angel a(35); //command.PutKick(a,100); } //agent.Say("gogogo"); } else { Vec posV=world.GetMyStrategy(); Vec correction; skills.DashTo(posV,correction); } } // cout<<"Cycle:"<<param.CycleReceive<<" speed:"<<state_ball.speed<<" MOD:"<<state_ball.speed.GetMod()<<"position:"<<state_ball.PositionV<<endl; //cout<<"Cycle:"<<param.CycleReceive<<" MYspeed:"<<state.speed<<" MOD:"<<state.speed.GetMod()<<" MYposition:"<<state.PositionV<<endl; } command.SentCommand(); } command.Done(); ++SenceCount; }}/* Vec Vspeed; Vec position(0,0,0); Vec BallPositionV(6,-1,0.111); Vec dist=position-BallPositionV; dist.Vz=0.0; double s=dist.GetMod(); double v0=10; Vspeed=dist; Vspeed.SetMod(v0); Vspeed.Vz=v0*0.57735; Vec ball_speed(0,0,0); Vspeed=Vspeed-ball_speed; Vec MyPositionV(10,-1,0.222); Vec temp1=BallPositionV-MyPositionV; temp1.Vz=0.0;// if(temp1.GetMod()<0.3)return; cout<<" temp1:"<<temp1<<" Vspeed:"<<Vspeed<<endl; cout<<" temp1.GetXYAngel():"<<temp1.GetXYAngel()<<" Vspeed.GetXYAngel():"<<Vspeed.GetXYAngel()<<endl; Angel angel1(temp1.GetXYAngel()); Angel angel2(Vspeed.GetXYAngel()); cout<<" angel1: "<<angel1.angel<<" angel2: "<<angel2.angel<<endl; double KickAble=param.AgentRadius+param.BallRadius+0.3; Vec Force=temp1; Force.SetMod(10); double direction=fabs((angel1-angel2).angel); cout<<direction<<endl; /* for(angel=0.0;angel<50.0;angel++) { cout<<" angel="<<angel; v0_XY=cos(angel/180.0*PAI)*v0; cout<<" v0_XY="<<v0_XY; v0_Z=sin(angel/180.0*PAI)*v0; cout<<" v0_Z="<<v0_Z; t=world.Get_t_Z(v0_Z,s); t_XY=t; cout<<" t="<<t_XY; s_XY=world.Get_s_XY(v0_XY,t_XY,k); cout<<" s_XY="<<s_XY; v_t_XY=world.Get_Vt_XY( v0_XY, t_XY,k); cout<<" v_t_XY="<<v_t_XY<<endl; }*/ // cout<<world.Get_V0_XY_st( 1.98302,0.15,k); return EXIT_SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -