📄 client.cpp
字号:
if(logwait && sensory.LastSightTime != sensory.LatestTime){
logwaitfails ++;
DoLog(LOG_STOPWATCH, "wait fail (%d %d)",sensory.LastSightTime, sensory.LatestTime);
}
ResetEvent(newcycle_event);
ResetEvent(newsenseinfo_event);
watch.UpdateStart();
DoLog(LOG_NONE, "******** Cycle %.0f **********", (float)sensory.LatestTime);
sensory.Update();
LeaveCriticalSection(&parse_update_mutex);
watch.AIstart();
int IsFinished = behave();
watch.AIexit();
if(!IsFinished)
DoLog(LOG_STOPWATCH, "AI exit at %.2f",watch.GetAIEndTime());
else{
}
DoLog(LOG_STOPWATCH, "Time elapsed on notification %f", watch.GetRecvWakeTime());
DoLog(LOG_STOPWATCH, "Time between notification and wake %f", watch.GetWakeTime_AfterNotification());
DoLog(LOG_STOPWATCH, "Sight Wake Time %.2f", watch.GetSightWakeTime());
DoLog(LOG_STOPWATCH, "Predict sight time %.2f(%d %d)", predictsightime, logwaitfails, logwaitcounts);
DoLog(LOG_STOPWATCH, "Update start %.2f",watch.GetUpdateStartTime());
DoLog(LOG_STOPWATCH, "AI start %.2f",watch.GetAIStartTime());
DoLog(LOG_STOPWATCH, "AI use %.2f", watch.GetAIUseTime());
DoLog(LOG_STOPWATCH, "AI finished at%.2f",watch.GetAIEndTime());
}
}
void CALLBACK CheckServer(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime){
if (NoResponseFromServer){
ServerAlive = 0;
PostMessage(hwnd, WM_DESTROY, 0, 0);
}
NoResponseFromServer = 1;
}
void destruction(){
int Maxwaitcounts = 100;
int count = 0;
DoLog(0, "Exit at %.0f",(float)sensory.LatestTime );
if (siginf != NULL){
TerminateThread(siginf,0);
CloseHandle(siginf);
}
if (sigctrl != NULL){
TerminateThread(sigctrl,0);
CloseHandle(sigctrl);
}
DeleteCriticalSection(&parse_update_mutex);
if(newcycle_event != NULL) CloseHandle(newcycle_event);
if(newsightinfo_event != NULL) CloseHandle(newsightinfo_event);
if(newsenseinfo_event != NULL) CloseHandle(newsenseinfo_event);
if(WaitServerTimer != NULL) KillTimer(hWND, WaitServerTimer);
close_connection(sock);
delete sock;
}
void InitializeObjs(){
/* If I am on the right half of the court, all the coordinates shall be rotated */
bool rotate = false;
if (situation.MySide == 'l'){
rotate = false;
}
else if (situation.MySide == 'r'){
rotate = true;
}
else{
my_error("Which side do i take?");
}
/**************************Initialize Markers *************************************/
int i=0;
Markers[i].set_pos(-SP_pitch_length/2.0f, 0.0f ,rotate); i++; /* Goal_L */
Markers[i].set_pos(SP_pitch_length/2.0f, 0.0f ,rotate); i++; /* Goal_R */
Markers[i].set_pos(0.0f, 0.0f , rotate); i++; /* Flag_C */
Markers[i].set_pos(0.0f, -SP_pitch_width/2.0f, rotate); i++; /* Flag_CT */
Markers[i].set_pos(0.0f, SP_pitch_width/2.0f, rotate); i++; /* Flag_CB */
Markers[i].set_pos(-SP_pitch_length/2.0f, -SP_pitch_width/2.0f, rotate); i++; /* Flag_LT */
Markers[i].set_pos(-SP_pitch_length/2.0f, SP_pitch_width/2.0f, rotate); i++; /* Flag_LB */
Markers[i].set_pos(SP_pitch_length/2.0f, -SP_pitch_width/2.0f, rotate); i++; /* Flag_RT */
Markers[i].set_pos(SP_pitch_length/2.0f, SP_pitch_width/2.0f, rotate); i++; /* Flag_RB */
Markers[i].set_pos(-SP_pitch_length/2.0f+SP_penalty_area_length,
-SP_penalty_area_width/2.0f, rotate); i++; /* Flag_PLT */
Markers[i].set_pos(-SP_pitch_length/2.0f+SP_penalty_area_length, 0, rotate); i++; /* Flag_PLC */
Markers[i].set_pos(-SP_pitch_length/2.0f+SP_penalty_area_length,
SP_penalty_area_width/2.0f, rotate); i++; /* Flag_PLB */
Markers[i].set_pos(SP_pitch_length/2.0f-SP_penalty_area_length,
-SP_penalty_area_width/2.0f , rotate); i++; /* Flag_PRT */
Markers[i].set_pos(SP_pitch_length/2.0f-SP_penalty_area_length, 0, rotate); i++; /* Flag_PRC */
Markers[i].set_pos(SP_pitch_length/2.0f-SP_penalty_area_length,
SP_penalty_area_width/2.0f, rotate); i++; /* Flag_PRB */
Markers[i].set_pos(-SP_pitch_length/2.0f, -SP_goal_width/2.0f, rotate); i++; /* Flag_GLT */
Markers[i].set_pos(-SP_pitch_length/2.0f, SP_goal_width/2.0f, rotate); i++; /* Flag_GLB */
Markers[i].set_pos(SP_pitch_length/2.0f, -SP_goal_width/2.0f, rotate); i++; /* Flag_GRT */
Markers[i].set_pos(SP_pitch_length/2.0f, SP_goal_width/2.0f, rotate); i++; /* Flag_GRB */
Markers[i].set_pos(-50.0f, -SP_pitch_width/2.0f-SP_pitch_margin, rotate); i++; /* Flag_TL50 */
Markers[i].set_pos(-40.0f, -SP_pitch_width/2.0f-SP_pitch_margin, rotate); i++; /* Flag_TL40 */
Markers[i].set_pos(-30.0f, -SP_pitch_width/2.0f-SP_pitch_margin, rotate); i++; /* Flag_TL30 */
Markers[i].set_pos(-20.0f, -SP_pitch_width/2.0f-SP_pitch_margin, rotate); i++; /* Flag_TL20 */
Markers[i].set_pos(-10.0f, -SP_pitch_width/2.0f-SP_pitch_margin, rotate); i++; /* Flag_TL10 */
Markers[i].set_pos(0.0f, -SP_pitch_width/2.0f-SP_pitch_margin, rotate); i++; /* Flag_T0 */
Markers[i].set_pos(10.0f, -SP_pitch_width/2.0f-SP_pitch_margin, rotate); i++; /* Flag_TR10 */
Markers[i].set_pos(20.0f, -SP_pitch_width/2.0f-SP_pitch_margin, rotate); i++; /* Flag_TR20 */
Markers[i].set_pos(30.0f, -SP_pitch_width/2.0f-SP_pitch_margin, rotate); i++; /* Flag_TR30 */
Markers[i].set_pos(40.0f, -SP_pitch_width/2.0f-SP_pitch_margin, rotate); i++; /* Flag_TR40 */
Markers[i].set_pos(50.0f, -SP_pitch_width/2.0f-SP_pitch_margin, rotate); i++; /* Flag_TR50 */
Markers[i].set_pos(-50.0f, SP_pitch_width/2.0f+SP_pitch_margin, rotate); i++; /* Flag_BL50 */
Markers[i].set_pos(-40.0f, SP_pitch_width/2.0f+SP_pitch_margin, rotate); i++; /* Flag_BL40 */
Markers[i].set_pos(-30.0f, SP_pitch_width/2.0f+SP_pitch_margin, rotate); i++; /* Flag_BL30 */
Markers[i].set_pos(-20.0f, SP_pitch_width/2.0f+SP_pitch_margin, rotate); i++; /* Flag_BL20 */
Markers[i].set_pos(-10.0f, SP_pitch_width/2.0f+SP_pitch_margin, rotate); i++; /* Flag_BL10 */
Markers[i].set_pos(0.0f, SP_pitch_width/2.0f+SP_pitch_margin, rotate); i++; /* Flag_B0 */
Markers[i].set_pos(10.0f, SP_pitch_width/2.0f+SP_pitch_margin, rotate); i++; /* Flag_BR10 */
Markers[i].set_pos(20.0f, SP_pitch_width/2.0f+SP_pitch_margin, rotate); i++; /* Flag_BR20 */
Markers[i].set_pos(30.0f, SP_pitch_width/2.0f+SP_pitch_margin, rotate); i++; /* Flag_BR30 */
Markers[i].set_pos(40.0f, SP_pitch_width/2.0f+SP_pitch_margin, rotate); i++; /* Flag_BR40 */
Markers[i].set_pos(50.0f, SP_pitch_width/2.0f+SP_pitch_margin, rotate); i++; /* Flag_BR50 */
Markers[i].set_pos(-SP_pitch_length/2.0f-SP_pitch_margin, -30, rotate); i++; /* Flag_LT30 */
Markers[i].set_pos(-SP_pitch_length/2.0f-SP_pitch_margin, -20, rotate); i++; /* Flag_LT20 */
Markers[i].set_pos(-SP_pitch_length/2.0f-SP_pitch_margin, -10, rotate); i++; /* Flag_LT10 */
Markers[i].set_pos(-SP_pitch_length/2.0f-SP_pitch_margin, 0, rotate); i++; /* Flag_L0 */
Markers[i].set_pos(-SP_pitch_length/2.0f-SP_pitch_margin, 10, rotate); i++; /* Flag_LB10 */
Markers[i].set_pos(-SP_pitch_length/2.0f-SP_pitch_margin, 20, rotate); i++; /* Flag_LB20 */
Markers[i].set_pos(-SP_pitch_length/2.0f-SP_pitch_margin, 30, rotate); i++; /* Flag_LB30 */
Markers[i].set_pos(SP_pitch_length/2.0f+SP_pitch_margin, -30, rotate); i++; /* Flag_RT30 */
Markers[i].set_pos(SP_pitch_length/2.0f+SP_pitch_margin, -20, rotate); i++; /* Flag_RT20 */
Markers[i].set_pos(SP_pitch_length/2.0f+SP_pitch_margin, -10, rotate); i++; /* Flag_RT10 */
Markers[i].set_pos(SP_pitch_length/2.0f+SP_pitch_margin, 0, rotate); i++; /* Flag_R0 */
Markers[i].set_pos(SP_pitch_length/2.0f+SP_pitch_margin, 10, rotate); i++; /* Flag_RB10 */
Markers[i].set_pos(SP_pitch_length/2.0f+SP_pitch_margin, 20, rotate); i++; /* Flag_RB20 */
Markers[i].set_pos(SP_pitch_length/2.0f+SP_pitch_margin, 30, rotate); /* Flag_RB30 */
for(i = 0; i < SP_num_markers + 1; i ++)
Markers[i].set_objtype(OBJ_Marker);
/*********** Initialize Side Lines *********************************/
Lines[SL_Left].set_global_angle(270,rotate);
Lines[SL_Right].set_global_angle(90,rotate);
Lines[SL_Top].set_global_angle(0,rotate);
Lines[SL_Bottom].set_global_angle(180,rotate);
for(i = 0; i < SP_num_lines + 1; i ++)
Lines[i].set_objtype(OBJ_Line);
/********** Intialize Players ****************************************/
for(i=0; i < SP_team_size; i++){
MyTeam[i].set_speed_param(SP_player_speed_max, SP_player_decay);
MyTeam[i].set_conf_param(CP_conf_max, CP_conf_decay, CP_min_valid_conf);
MyTeam[i].set_objtype(OBJ_Player);
MyTeam[i].set_side(true);
MyTeam[i].set_inside_no(i+1);
MyTeam[i].SetRole(FP_attackness[i], FP_leftness[i], FP_aggressiveness[i], FP_creativeness[i]);
TheirTeam[i].set_speed_param(SP_player_speed_max, SP_player_decay);
TheirTeam[i].set_conf_param(CP_conf_max, CP_conf_decay, CP_min_valid_conf);
TheirTeam[i].set_objtype(OBJ_Player);
TheirTeam[i].set_inside_no(i+1+SP_team_size);
TheirTeam[i].set_side(false);
UnknownMyPlayers[i].set_speed_param(SP_player_speed_max, SP_player_decay);
UnknownMyPlayers[i].set_conf_param(CP_conf_max, CP_conf_decay, CP_min_valid_conf);
UnknownMyPlayers[i].set_objtype(OBJ_Player);
UnknownMyPlayers[i].set_side(true);
UnknownTheirPlayers[i].set_speed_param(SP_player_speed_max, SP_player_decay);
UnknownTheirPlayers[i].set_conf_param(CP_conf_max, CP_conf_decay, CP_min_valid_conf);
UnknownTheirPlayers[i].set_objtype(OBJ_Player);
UnknownTheirPlayers[i].set_side(false);
TeamlessPlayers[i].set_speed_param(SP_player_speed_max, SP_player_decay);
TeamlessPlayers[i].set_conf_param(CP_conf_max, CP_conf_decay, CP_min_valid_conf);
TeamlessPlayers[i].set_objtype(OBJ_Player);
TeamlessPlayers[i+SP_team_size].set_speed_param(SP_player_speed_max, SP_player_decay);
TeamlessPlayers[i+SP_team_size].set_conf_param(CP_conf_max, CP_conf_decay, CP_min_valid_conf);
TeamlessPlayers[i+SP_team_size].set_objtype(OBJ_Player);
}
unknownmyplayerlist.set_side(Side_My);
unknowntheirplayerlist.set_side(Side_Opp);
teamlessplayerlist.set_side(Side_Unknown);
Self.set_speed_param(SP_player_speed_max, SP_player_decay);
Self.set_conf_param(CP_conf_max, CP_conf_decay, CP_min_valid_conf);
Self.Is_goalie = CP_goalie;
/********** Intialize ball ****************************************/
ball.set_speed_param(SP_ball_speed_max,SP_ball_decay);
ball.set_conf_param(CP_conf_max,CP_conf_decay,CP_min_valid_conf);
ball.set_objtype(OBJ_Ball);
strcpy(MyTeamName, CP_TeamName);
MyTeamNameLen = strlen(MyTeamName);
/********** Initialize BP Networks **********************************/
motion.IT_Net.RestoreNet(CP_IT_weightfile);
motion.IT_ref_Net.RestoreNet(CP_IT_ref_weigthfile);
motion.IT_time_Net.RestoreNet(CP_IT_time_weightfile);
motion.ControlBallNet.RestoreNet(CP_CB_weightfile);
motion.PassNet.RestoreNet(CP_PASS_weightfile);
fm.FMOffenseNet.RestoreNet(CP_FM_offense_weightfile);
fm.FMDefenseNet.RestoreNet(CP_FM_defense_weightfile);
fieldinfo.OffSensitivityNet.RestoreNet(CP_Off_sen_weightfile);
fieldinfo.DF_SensitivityNet.RestoreNet(CP_DF_Sensitivity_weightfile);
motion.Mark_Net.RestoreNet(CP_Mark_priority_weightfile);
motion.Block_Net.RestoreNet(CP_Block_priority_weightfile);
motion.FM_Priority_Net.RestoreNet(CP_DF_formation_priority_file);
motion.Press_Net.RestoreNet(CP_DF_press_priority_file);
kick.KickOA1_5.Initvpos(CP_KickOA_weightfile_A);
kick.KickOA2_0.Initvpos(CP_KickOA_weightfile_B);
kick.KickOA2_5.Initvpos(CP_KickOA_weightfile_C);
kick.KickOAlast.Initvpos(CP_KickOA_weightfile_D);
/********** Initialize My Role **********************************/
Self.SetRole(CP_attackness, CP_leftness, CP_aggressiveness, CP_creativeness);
/********** Initialize My RSA **********************************/
motion.rsa.setkey(CP_encryption_matrix);
CP_decryption_key = (int)motion.rsa.GenerateKey(CP_encryption_key);
/********* Set Formations *********************************/
/********* set field information ************************************/
fieldinfo.Initialize();
if(fieldinfo.IsValidmygoalie())
MyPlayer(fieldinfo.mygoalie).Is_goalie = true;
if(fieldinfo.IsValidtheirgoalie())
TheirPlayer(fieldinfo.theirgoalie).Is_goalie = true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -