📄 parsevisual.cpp
字号:
#include "parsevisual.h"
#include "utils.h"
#include "worldmodel.h"
#include "perceptron.h"
#define NOCHNGINFO -500
#define NOFACEINFO -500
void VisualUnkPlayer::update(){
Vector rpos = Polar2Vector(seenpos.x, seenpos.y);
pos = rpos.Rotate(Self.Headfacing(t)) + Self.Pos(t);
}
/************************ Visual Information Process ***************************/
void VisualInfoProcess::UpdateUnkPlayers(Time t){
if(!rec_sight_info.ChkData(t)) return;
int i;
for(i = My_Unk_Players.Data(t).Num_datas()-1; i>=0; i--){
My_Unk_Players.Data(t).Data(i).update();
}
for(i = Their_Unk_Players.Data(t).Num_datas()-1; i>=0; i--){
Their_Unk_Players.Data(t).Data(i).update();
}
for(i = Teamless_Players.Data(t).Num_datas()-1; i>=0; i--){
Teamless_Players.Data(t).Data(i).update();
}
}
int VisualInfoProcess::MySightInterval(){
int interval = ServerParam::send_step;
if ( ViewWidth == VW_Narrow ) interval /= 2;
else if ( ViewWidth == VW_Wide ) interval *= 2;
if ( ViewQuality == VQ_Low ) interval /=2;
return interval;
}
int VisualInfoProcess::SightInterval(VIEWWIDTH view_width, VIEWQUALITY quality){
int interval = ServerParam::send_step;
if ( view_width == VW_Narrow ) interval /= 2;
else if ( view_width == VW_Wide ) interval *= 2;
if ( quality == VQ_Low ) interval /=2;
return interval;
}
void VisualInfoProcess::IdentifyMyGoalie(UNum No,bool IsGoalie){
MyPlayer(No).Is_goalie = IsGoalie;
if(IsGoalie) FieldInfo.mygoalie = No;
}
void VisualInfoProcess::IdentifyTheirGoalie(UNum No,bool IsGoalie){
TheirPlayer(No).Is_goalie = IsGoalie;
if(IsGoalie){
FieldInfo.theirgoalie = No;
}
}
MarkerType VisualInfoProcess::ClosestGoal(){
if (Self.pos.x < 0)
return MyGoal;
else
return TheirGoal;
}
MarkerType VisualInfoProcess::ClosestFlag(){
Vector gap = Self.pos - PitchInfo.Markers[LastClosestMarker].pos;
if (gap.mod() > 1)
return No_Marker;
else
return LastClosestMarker;
}
void VisualInfoProcess::Parse_Fullstate(Time time, char* SensoryInfo){
rec_sight_info.Setdata(true, time);
char* msg = SensoryInfo;
char* pmsg_ball = strstr(msg,"(ball ");
if(pmsg_ball == NULL) return;
float posx = get_float(&pmsg_ball);
float posy = get_float(&pmsg_ball);
float velx = get_float(&pmsg_ball);
float vely = get_float(&pmsg_ball);
FullSeeBall(time, posx, posy, velx, vely);
pmsg_ball ++;
char side;
int number;
float bodyangle,neckangle;
int stamina;
float effort,recovery;
while(*pmsg_ball && *pmsg_ball != ')'){
while(*pmsg_ball == ' ') pmsg_ball++;
if(*pmsg_ball == '('){
side = *(++pmsg_ball);
number = get_int(&pmsg_ball);
posx = get_float(&pmsg_ball);
posy = get_float(&pmsg_ball);
velx = get_float(&pmsg_ball);
vely = get_float(&pmsg_ball);
bodyangle = get_float(&pmsg_ball);
neckangle = get_float(&pmsg_ball);
stamina = get_int(&pmsg_ball);
effort = get_float(&pmsg_ball);
recovery = get_float(&pmsg_ball);
FullSeePlayer(time, side, number, posx, posy, velx, vely, bodyangle, neckangle, stamina, effort, recovery);
pmsg_ball ++;
}
}
}
void VisualInfoProcess::FullSeePlayer(Time time, char playerside, int No, float posx, float posy, float velx, float vely, float bodyangle, float neckangle, int stamina, float effort, float recovery){
if(situation.MySide == 'r'){
posx *= -1.0f;
posy *= -1.0f;
velx *= -1.0f;
vely *= -1.0f;
bodyangle = NormalizeAngle(bodyangle + 180.0f);
}
GetPlayer(playerside, No).FullSee(Vector(posx, posy), Vector(velx, vely), time);
GetPlayer(playerside, No).FullSeePlayer(bodyangle, neckangle, stamina, effort, recovery, time);
}
void VisualInfoProcess::FullSeeBall(Time time, float posx, float posy, float velx, float vely){
if(situation.MySide == 'r'){
posx *= -1.0f;
posy *= -1.0f;
velx *= -1.0f;
vely *= -1.0f;
}
ball.FullSee(Vector(posx, posy), Vector(velx, vely), time);
}
void VisualInfoProcess::SeeMarker(MarkerType marker,AngleDeg ang,Time time){
//there are so many marker, foget those without known distance
//this rem is non-trivial, because update assume all markers's distance is known
//Markers[marker].set_polar(ang,time);
//SeenMarkers.Data(time)[[num_seenmarkers.Data(time)++]] = marker;
}
void VisualInfoProcess::SeeMarker(MarkerType marker,float dist,AngleDeg ang,Time time){
PitchInfo.Markers[marker].set_polar(ang,dist,time);
SeenMarkers.Setdata(marker, num_seenmarkers.Data(time)++, time);
}
void VisualInfoProcess::SeeLine(SideLine line,AngleDeg ang,Time time){
PitchInfo.Lines[line].set_polar(ang,time);
SeenLines.Setdata(line, num_seenlines.Data(time)++, time);
}
void VisualInfoProcess::SeeLine(SideLine line ,float dist,AngleDeg ang,Time time){
PitchInfo.Lines[line].set_polar(ang,dist,time);
SeenLines.Setdata(line, num_seenlines.Data(time)++, time);
}
void VisualInfoProcess::SeeBall(AngleDeg ang,Time time){
ball.set_polar(ang,time);
}
void VisualInfoProcess::SeeBall(float dist,AngleDeg ang,Time time){
ball.set_polar(ang,dist,time);
}
void VisualInfoProcess::SeeBall(float dist,AngleDeg ang,float distChng,float dirChng,Time time){
ball.set_polar(ang,dist,time);
ball.set_chinfo(distChng,dirChng,time);
}
void VisualInfoProcess::SeePlayer(AngleDeg ang,Time time){
//距离不知时,暂时放弃
return;
}
void VisualInfoProcess::SeePlayer(float dist, AngleDeg ang,Time time){
VisualUnkPlayer p;
p.Is_side_known = false;
p.set_polar(dist, ang, time);
Teamless_Players.Data(time).Add(p);
}
void VisualInfoProcess::SeePlayer(char player_side, AngleDeg ang,Time time){
//距离不知时,暂时放弃
return;
}
void VisualInfoProcess::SeePlayer(char player_side,float dist,AngleDeg ang,Time time){
VisualUnkPlayer p;
p.set_polar(dist, ang, time);
if(player_side == situation.MySide){
My_Unk_Players.Data(time).Add(p);
}else{
Their_Unk_Players.Data(time).Add(p);
}
}
void VisualInfoProcess::SeePlayer(char player_side,UNum NO,AngleDeg ang,Time time,bool IsGoalie){
if(player_side == situation.MySide){
MyPlayer(NO).set_polar(ang,time);
IdentifyMyGoalie(NO, IsGoalie);
}
else{
TheirPlayer(NO).set_polar(ang,time);
IdentifyTheirGoalie(NO, IsGoalie);
}
}
void VisualInfoProcess::SeePlayer(char player_side,UNum NO,float dist,AngleDeg ang,Time time,bool IsGoalie){
if(player_side == situation.MySide){
MyPlayer(NO).set_polar(ang,dist,time);
IdentifyMyGoalie(NO, IsGoalie);
}
else{
TheirPlayer(NO).set_polar(ang,dist,time);
IdentifyTheirGoalie(NO, IsGoalie);
}
}
void VisualInfoProcess::SeePlayer(char player_side,UNum NO,float dist,AngleDeg ang,float distChng,
float dirChng,AngleDeg facedir,AngleDeg neckdir,Time time,bool IsGoalie){
if(player_side == situation.MySide){
MyPlayer(NO).set_polar(ang,dist,time);
MyPlayer(NO).set_chinfo(distChng,dirChng,time);
MyPlayer(NO).set_fcinfo(facedir, neckdir,time);
IdentifyMyGoalie(NO, IsGoalie);
}
else{
TheirPlayer(NO).set_polar(ang,dist,time);
TheirPlayer(NO).set_chinfo(distChng,dirChng,time);
TheirPlayer(NO).set_fcinfo(facedir, neckdir,time);
IdentifyTheirGoalie(NO, IsGoalie);
}
}
/***********************Parse Visual Version 7.0**************************************/
void ParseVisualV7::ParseData()
{
/************************************/
ang = get_float(&SightInfo);
if ( *SightInfo != ')' ) /* 'high' quality */
{
view_qual = VQ_High;
dist = ang;
ang = get_float(&SightInfo);
}
else /* 'low ' quality */
{
view_qual = VQ_Low;
}
if ( view_qual != ViewQuality ) my_error("View quality %d correct?",view_qual);
if ( *SightInfo != ')' )
{
distChng = get_float(&SightInfo);
dirChng = get_float(&SightInfo);
}
if ( *SightInfo != ')' )
{
if (object_type != OBJ_Player) my_error("Only players should have facedir");
facedir = get_float(&SightInfo);
neckdir = get_float(&SightInfo);
}
if ( *SightInfo != ')' ) my_error("Should be done with object info here");
SightInfo++; /* ")" */
}
void ParseVisualV7::ParseName()
{
get_word(&SightInfo); /* " ((" */
if ( *SightInfo=='g' ){
object_type = OBJ_Marker;/* it is a "goal " */
SightInfo += 2;
if ( *SightInfo=='r' ) marker = Goal_R;
else if ( *SightInfo=='l' ) marker = Goal_L;
else my_error("goal ?");
}
else if ( *SightInfo=='G' ){
object_type = OBJ_Marker_Behind;
marker = ClosestGoal();
}
else if ( *SightInfo=='f' ){
object_type = OBJ_Marker;
ParseFlagName( );
}
else if ( *SightInfo=='F' ){
object_type = OBJ_Marker_Behind;
marker = ClosestFlag(); // could be No_Marker
}
else if ( *SightInfo=='l' )
{
object_type = OBJ_Line;
SightInfo+=2; // "line "
if ( *SightInfo=='r' ) line = SL_Right;
else if ( *SightInfo=='l' )line = SL_Left;
else if ( *SightInfo=='t' )line = SL_Top;
else if ( *SightInfo=='b' )line = SL_Bottom;
else my_error("line ?");
}
else if ( *SightInfo=='p' || *SightInfo=='P' )
{
object_type = OBJ_Player;
ParsePlayerName();
}
else if ( *SightInfo=='b' || *SightInfo=='B' ) object_type = OBJ_Ball;
else my_error("unknown object");
advance_to(')',&SightInfo); // advance to end of object
}
void ParseVisualV7::Parse_Sight(Time ti, char *SI)
{
SightInfo = SI;
time = ti;
rec_sight_info.Setdata(true, time);
marker = No_Marker;
line = SL_No_Line;
closestMarker = No_Marker;
/* Reset some values */
num_seenlines.Setdata(0, time);
num_seenmarkers.Setdata(0, time);
LastClosestMarker = GetClosestMarker(sensory.PrevSightTime);
ClosestMarker.Setdata(No_Marker, time);
My_Unk_Players.Data(time).Reset();
Their_Unk_Players.Data(time).Reset();
Teamless_Players.Data(time).Reset();
while (*SightInfo != ')'){
dirChng = NOCHNGINFO;
facedir = NOFACEINFO;
neckdir = NOFACEINFO;
player_number = player_side = 0;
////////////////////
ParseName();
/////////////////////
ParseData();
/////////////////////
switch (object_type)
{
case OBJ_Marker:
case OBJ_Marker_Behind: OBJisMarker(); break;
case OBJ_Line: OBJisLine(); break;
case OBJ_Ball: OBJisBall(); break;
case OBJ_Player: OBJisPlayer();
}
}
}
void ParseVisualV7::ParsePlayerName()
{
SightInfo += 1; /* it is a "player" */
if ( *SightInfo == ' ' ) /* there's a team */
{
SightInfo += 2;
if ( !strncmp(SightInfo,MyTeamName,MyTeamNameLen) && *(SightInfo+MyTeamNameLen) == '"' )
player_side = situation.MySide;
else
{
if ( TheirTeamName[0] == 0 )
{
int a=0;
while ( *SightInfo != '"' ){
TheirTeamName[a++]=*SightInfo++;
}
TheirTeamNameLen = strlen(TheirTeamName);
}
player_side = situation.TheirSide;
}
while ( *SightInfo != ' ' && *SightInfo != ')' ) SightInfo++; /* advance past team name */
if ( *SightInfo== ' ' )/* there's a number */
{
player_number = get_int(&SightInfo);
if( *SightInfo== ' '){/*It's goalie*/
get_word(&SightInfo);
IsGoalie = true;
}else{
IsGoalie = false;
}
}
}
}
void ParseVisualV7::OBJisPlayer()
{
if ( !player_side ) /* Too far for team or num */
{
if ( view_qual == VQ_Low ) /* low quality */
SeePlayer(ang, time);
else if ( dirChng == NOCHNGINFO ) /* high quality */
SeePlayer(dist, ang, time);
else /* know direction*/
my_error("Shouldn't know dirChng when the player's far");
}
else
{
if ( !player_number ) /* Too far for number */
{
if ( view_qual == VQ_Low ) /* low quality */
SeePlayer(player_side, ang, time);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -