📄 auditorysystem.cpp
字号:
if (m == '/')
return 68;
if (m == '?')
return 69;
if (m == '<')
return 70;
if (m == '>')
return 71;
return 72;
}
void AuditoryProcess::encipher(char * buffer, int len){
int tmp, j = 0;
for(int i =0; i < len; i ++){
switch(i % 3){
case 0:
tmp = ciphertext(buffer[i]) * 4;
break;
case 1:
buffer[j ++] = map_into_printablechar(tmp + (ciphertext(buffer[i]) / 4));
tmp = (ciphertext(buffer[i]) % 4) * 16;
break;
case 2:
buffer[j ++] = map_into_printablechar(tmp + ciphertext(buffer[i]));
}
}
if(len % 3 != 0){
buffer[j ++] = map_into_printablechar(tmp);
}
buffer[j] = 0;
}
void AuditoryProcess::decipher(char * buffer, int len){
int* tmp = new int[len], j = 0;
for(int i = 0; i < len; i ++)
tmp[i] = demap(buffer[i]);
for(i =0; i < len; i ++){
switch(i % 2){
case 0:
buffer[j ++] = deciphertext(tmp[i] / 4);
break;
case 1:
buffer[j ++] = deciphertext((tmp[i-1] % 4) * 4 + tmp[i] / 16);
buffer[j ++] = deciphertext(tmp[i] % 16);
break;
}
}
buffer[j] = 0;
delete tmp;
}
int AuditoryProcess::encrypt(int data){
return int(rsa.Exponent(data, CP_encryption_key));
}
int AuditoryProcess::decrypt(int data){
return int(rsa.Exponent(data, CP_decryption_key));
}
/***************** Announce ***************************************/
void AuditoryProcess::AnnounceSelfPos(){
AddMsg(Msg_MyPlayerPos, MyNumber, 0, Self.pos.x, Self.pos.y);
}
void AuditoryProcess::AnnounceMyPlayerPos(UNum NO){
if (!IsUniformNo(NO)) return;
AddMsg(Msg_MyPlayerPos, NO, MyPlayer(NO).original_postime - situation.CurrentTime, MyPlayer(NO).pos.x, MyPlayer(NO).pos.y);
}
void AuditoryProcess::AnnounceTheirPlayerPos(UNum NO){
if (!IsUniformNo(NO)) return;
AddMsg(Msg_TheirPlayerPos, NO, TheirPlayer(NO).original_postime - situation.CurrentTime, TheirPlayer(NO).pos.x, TheirPlayer(NO).pos.y);
}
void AuditoryProcess::AnnounceBallPos(){
AddMsg(Msg_BallPos, ball.original_postime - situation.CurrentTime, ball.pos.x, ball.pos.y);
}
void AuditoryProcess::AnnounceBallVel(){
AddMsg(Msg_BallVel, ball.original_veltime - situation.CurrentTime, ball.global_vel.x, ball.global_vel.y);
}
void AuditoryProcess::AnnouncePass(){
AddMsg(Msg_Pass, 1);
}
void AuditoryProcess::AnnounceBallcontroller(){
int ballcontrollers[6];
int num, j = 0;
num = situation.num_their_ballcontrollers;
for(int i = 0; i < num; i ++){
if (situation.Their_Ballcontrollers[i] > 2 * SP_team_size
|| situation.Their_Ballcontrollers[i] <= 0) continue;
if (situation.Their_Ballcontrollers[i] <= SP_team_size){
ballcontrollers[j ++] = situation.Their_Ballcontrollers[i] + SP_team_size;
}
else{
ballcontrollers[j ++] = situation.Their_Ballcontrollers[i];
}
if (j >= 5) break;
}
num = situation.num_my_ballcontrollers;
for(i = 0; i < num; i ++){
ballcontrollers[j ++] = situation.My_Ballcontrollers[i];
if (j >= 5) break;
}
for (i = j; i < 6; i ++){
ballcontrollers[i] = -1;
}
AddMsg(Msg_Ballcontroller, ballcontrollers[0], ballcontrollers[1], ballcontrollers[2]
, ballcontrollers[3], ballcontrollers[4], ballcontrollers[5]);
}
/******************** Hear *******************************************/
void AuditoryProcess::HeardMyPlayerPos(UNum NO, Time time){
if (!IsUniformNo(NO)) return;
if (MyPlayer(NO).heard && time - TheirPlayer(NO).heardposinfo.time < 2){
//if more than one heard msg before one update it, compare the conf of msgs
if (MyPlayer(NO).heard_pos_conf > msgData[1] * Exp(MyPlayer(NO).conf_decay, float( MyPlayer(NO).heardposinfo.time - time)))
return;
}
MyPlayer(NO).heard = true;
MyPlayer(NO).heardposinfo = TimedData<Vector>(Vector(msgData[2], msgData[3]), time);
MyPlayer(NO).heard_org_postime = int(msgData[1]) + time;
DoRecord(LOG_HEAR, "Heard My %d time %d at (%.2f %.2f) at %d",NO, MyPlayer(NO).heard_org_postime, MyPlayer(NO).heardposinfo.data.x, MyPlayer(NO).heardposinfo.data.y, time);
}
void AuditoryProcess::HeardTheirPlayerPos(UNum NO, Time time){
if (!IsUniformNo(NO)) return;
if (TheirPlayer(NO).heard && time - TheirPlayer(NO).heardposinfo.time < 2){
//if more than one heard msg before one update it, compare the conf of msgs
if (TheirPlayer(NO).heard_pos_conf > msgData[1] * Exp(TheirPlayer(NO).conf_decay, float(TheirPlayer(NO).heardposinfo.time - time)))
return;
}
TheirPlayer(NO).heard = true;
TheirPlayer(NO).heardposinfo = TimedData<Vector>(Vector(msgData[2], msgData[3]), time);
TheirPlayer(NO).heard_org_postime = int(msgData[1]) + time;
DoRecord(LOG_HEAR, "Heard Their %d time %d at (%.2f %.2f) at %d", NO, TheirPlayer(NO).heard_org_postime, TheirPlayer(NO).heardposinfo.data.x, TheirPlayer(NO).heardposinfo.data.y, time);
}
void AuditoryProcess::HeardBallPos(Time time){
if (ball.heard && time - ball.heardposinfo.time < 2){
//if more than one heard msg before one update it, compare the conf of msgs
if (ball.heard_pos_conf > msgData[1] * Exp(ball.conf_decay, float(ball.heardposinfo.time - time)))
return;
}
ball.heard = true;
ball.heardposinfo = TimedData<Vector>(Vector(msgData[1], msgData[2]), time);
ball.heard_org_postime = int(msgData[0]) + time;
DoRecord(LOG_HEAR, "Heard Ball(Pos) time %d at (%.2f %.2f) at %d", ball.heard_org_postime, ball.heardposinfo.data.x, ball.heardposinfo.data.y, time);
}
void AuditoryProcess::HeardBallVel(Time time){
if (ball.heard && time - ball.heardvelinfo.time < 2){
//if more than one heard msg before one update it, compare the conf of msgs
if (ball.heard_vel_conf > msgData[1] * Exp(ball.conf_decay, float(ball.heardvelinfo.time - time)))
return;
}
ball.heardvelinfo = TimedData<Vector>(Vector(msgData[1], msgData[2]), time);
ball.heard_org_veltime = int(msgData[0]) + time;
DoRecord(LOG_HEAR, "Heard Ball(Vel) time %d at (%.2f %.2f) at %d", ball.heard_org_veltime, ball.heardvelinfo.data.x, ball.heardvelinfo.data.y, time);
}
void AuditoryProcess::HeardBallcontrollers(Time time){
int No;
for(No = 1; No <= SP_team_size; No ++){
MyPlayer(No).heard_iscontrolball = false;
TheirPlayer(No).heard_iscontrolball = false;
}
for(int i = 0; i < 6; i ++){
No = int(msgData[i]);
if (No == -1)
break;
if (No >= 0){
if (No <= SP_team_size){
MyPlayer(No).heard_iscontrolball = true;
DoRecord(LOG_HEAR, "Heard Ballctroller is %d", No);
}
else if(No <= 2 * SP_team_size){
TheirPlayer(No - SP_team_size).heard_iscontrolball = true;
DoRecord(LOG_HEAR, "Heard Ballctroller is %d", No);
}
}
}
}
void AuditoryProcess::HeardPass(Time time){
ball.heardpass = TimedData<bool>(true, time);
}
/*********** Strategy ****************/
bool AuditoryProcess::IsCaptain(UNum NO){
//goalie & a back and a midfielder and a forward is capitain of each line
if (MyPlayer(NO).Is_goalie)
return true;
if (MyPlayer(NO).IsMid()){
if (MyPlayer(NO).IsBack() && MyPlayer(NO).leftness >= 0.5f){
return false;
}
return true;
}
return false;
}
bool AuditoryProcess::CanSpeak(){
Time time = situation.CurrentTime;
if (situation.ClockStopped){
time = situation.ClockStoppedTime;
}
if (mediator.PassOut.time >= situation.CurrentTime -1 && mediator.PassOut.data){
//pass out the ball, say it
return true;
}
if ((ball.IsOtherKick()) && situation.BallFree && ball.distance < 20.0f){
int num = motion.Num_MyVisiblePlayers();
for(int i =0; i <num; i++){
if (ball.distance > motion.MyPlayer_Close2Ball(i).balldist){
break;
}
}
if (i <= 1)
return true;
else
return chance(2.0f / (i + 2));
}
if (IsCaptain(MyNumber) && time - LastSpeakingTime >= 3){
//if you are captain speak at four different channel
if (Self.Is_goalie)
return time % 4 == 0;
if (Self.IsBack())
return time % 4 == 1;
if (Self.IsMidFielder())
return time % 4 == 2;
if (Self.IsForward())
return time % 4 == 3;
}
if (ball.kickable())
return false;
return (ball.distance < 3.0f && CP_Number % 3 == time % 3) || (ball.distance < 10.0f && CP_Number % 6 == time % 6);
}
void AuditoryProcess::Communication(){
if (!CanSpeak()) return;
AnnounceSelfPos();
if (mediator.PassOut.time == situation.CurrentTime && mediator.PassOut.data){
Vector predict_vel = ball.global_vel + action.KickEffect(situation.CurrentTime);
Vector predict_pos = ball.pos;
AddMsg(Msg_BallPos, 0, predict_pos.x, predict_pos.y);
AddMsg(Msg_BallVel, 0, predict_vel.x, predict_vel.y);
AddMsg(Msg_Ballcontroller, -1);
AnnouncePass();
}else if (ball.pos_valid() && ball.Rs_valid()){
AnnounceBallPos();
AnnounceBallcontroller();
if (ball.speed_conf > 0.8f)
AnnounceBallVel();
}
for(int No = 1; No <= SP_team_size; No++){
if (MyPlayer(No).pos_valid() && MyPlayer(No).Rs_valid() ){
AnnounceMyPlayerPos(No);
}
if (TheirPlayer(No).pos_valid() && TheirPlayer(No).Rs_valid()){
AnnounceTheirPlayerPos(No);
}
}
encipher(auditorybuffer, p_auditorybuffer);
AddHeader();
SendMsg();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -