📄 uclass.pas
字号:
var i:integer;
begin
for i:=0 to 4 do
begin
{ apts^[i].no := i+1;
apts^[i].team := 1;
apts^[i].x := robots[2,i+1].x;
apts^[i].y := robots[2,i+1].y;
apts^[i].vx:= robots[2,i+1].vx;
apts^[i].vy:= robots[2,i+1].vy;}
apts^[i].no := i+1;
apts^[i].team := 2;
apts^[i].x := CFLDLEN - robots[2,i+1].x;
apts^[i].y := CFLDWIDTH - robots[2,i+1].y;
apts^[i].vx:= - robots[2,i+1].vx;
apts^[i].vy:= - robots[2,i+1].vy;
end;
end;
procedure TMatchField.InitMatch;
var i, j:integer;
ir :double;
begin
//////////////////////////////////////////////////////////////////////////////
/// 初始化各个队员的状态 ///
//////////////////////////////////////////////////////////////////////////////
for i:=1 to 2 do
for j:=1 to CROBOTNUM do
begin
robots[i,j] := TRobot.Create(self);
robots[i,j].team := i; {球队号码}
robots[i,j].no := j; {号码}
robots[i,j].x := RobotsPosition[j,1]; {绝对坐标}
robots[i,j].y := RobotsPosition[j,2]; {绝对坐标}
robots[i,j].preaction := 0;
robots[i,j].param0 := 0; //设预设动作为Nokick
robots[i,j].param1 := 0;
robots[i,j].param2 := 0;
end;
//////////////////////////////////////////////////////////////////////////////
/// 初始化球的状态 ///
//////////////////////////////////////////////////////////////////////////////
// ('init');
ball.x := CFLDLEN div 2;
ball.y := CFLDWIDTH div 2;
ball.vy := 10;
case lastGoalTeam of
0: begin
ir := random;
if ir-0.5<0 then
begin
ball.vx := 10;
crt := 2;
crn := 5;
end
else
begin
ball.vx := -10;
crt := 1;
crn := 5;
end;
end;
1: begin
ball.vx := 10;
crt := 2;
crn := 5;
end;
2: begin
ball.vx := -10;
crt := 1;
crn := 5;
end;
end;
////////////////////////////////////////////////
/// 改变比赛当前状态
////////////////////////////////////////////////
iTFG := 0;
iHMPETB := 0;
end;
{procedure TMatchField.playerEffectball;
var newvx, newvy : double;
maxfandistence : double;
dists : array [1..2, 1..CROBOTNUM] of double;
i,j : integer;
backteamid : integer;
backno : integer;
sumfandistenc: double; //二维数组的和,用于求取概率
irandseed : single;
label g1, g2;
begin
backteamid := 1;
backno :=1;
maxfandistence := -1;
for i:=1 to 2 do
for j:=1 to CROBOTNUM do
begin
dists[i,j] := sqrt(sqr(ball.posx - robots[i,j].absolutex) + sqr(ball.posy - robots[i,j].absolutey));
if dists[i,j] < CRADIUS then
begin
dists[i,j] := CRADIUS - dists[i,j];
if dists[i,j] > maxfandistence then
begin
maxfandistence := dists[i,j];
backno := j;
backteamid := i;
end;
end else
dists[i,j] := 0;
end;
///////////////////////////////////////////////////////////////////////////
// 如果maxfandistenc= -1 说明没有球和人之间没有小于半径的 //
///////////////////////////////////////////////////////////////////////////
if maxfandistence <> -1 then
begin
inc(iHMPETB);
sumfandistenc := 0;
for i:=1 to 2 do
for j:=1 to CROBOTNUM do
begin
sumfandistenc := sumfandistenc + dists[i,j];
end;
for i:=1 to 2 do
for j:=1 to CROBOTNUM do
begin
dists[i,j] := dists[i,j] / sumfandistenc;
end;
if ball.speedmo > CVCANNOTBALL then
begin
crt := backteamid;
crn := backno;
ballcrashplayer(robots[backteamid,backno].absolutex, robots[backteamid,backno].absolutey, ball.posx, ball.posy, ball.vx, ball.vy, newvx, newvy);
ball.vx := newvx;
ball.vy := newvy;
while (sqrt(sqr(robots[backteamid,backno].absolutex - ball.x) + sqr(robots[backteamid, backno].absolutey - ball.y )) < CRADIUS ) do
begin
ball.x := ball.posx + round(ball.vx);
ball.y := ball.posy + round(ball.vy);
end;
exit; //////////////////////////return/////////////////////
end
else
begin
if (dists[1,1] <> 0) and (ifinPZ(1,ball.x, ball.y))
then
begin
robots[1,1].doAction;
while (sqrt(sqr(robots[1,1].absolutex - ball.x) + sqr(robots[1,1].absolutey - ball.y )) < CRADIUS ) do
begin
ball.x := ball.posx + round(ball.vx);
ball.y := ball.posy + round(ball.vy);
end;
crt := 1;
crn := 1;
exit; ////////////////////////如果在A队禁区并且A队守门员控球
end;
if (dists[2,1] <> 0) and (ifinPZ(2,ball.x, ball.y))
then
begin
robots[2,1].doAction;
while (sqrt(sqr(robots[2,1].absolutex - ball.x) + sqr(robots[2,1].absolutey - ball.y )) < CRADIUS ) do
begin
ball.x := ball.posx + round(ball.vx);
ball.y := ball.posy + round(ball.vy);
end;
crt := 2;
crn := 1;
exit; ////////////////////////如果在B队禁区并且B队守门员控球
end;
if ball.speedmo > CVCANBALL then
begin
irandseed := random;
if irandseed < (ball.speedmo - CVCANBALL)/(CVCANNOTBALL - CVCANBALL) then
begin ///////////////橦到了球。
crt := backteamid;
crn := backno;
ballcrashplayer(robots[backteamid,backno].absolutex, robots[backteamid,backno].absolutey, ball.posx, ball.posy, ball.vx, ball.vy, newvx, newvy);
ball.vx := newvx;
ball.vy := newvy;
while (sqrt(sqr(robots[backteamid,backno].absolutex - ball.x) + sqr(robots[backteamid, backno].absolutey - ball.y )) < CRADIUS ) do
begin
ball.x := ball.posx + round(ball.vx);
ball.y := ball.posy + round(ball.vy);
end;
exit; //////////////////////////return/////////////////////
end
else
begin ///////////////控球
irandseed := random;
sumfandistenc := 0;
for i:=1 to 2 do
for j:=1 to CROBOTNUM do
begin
sumfandistenc := sumfandistenc + dists[i,j];
if irandseed < sumfandistenc then
begin
crt := i;
crn := j;
robots[i,j].doAction;
while (sqrt(sqr(robots[i,j].absolutex - ball.x) + sqr(robots[i,j].absolutey - ball.y )) < CRADIUS ) do
begin
ball.x := ball.posx + round(ball.vx);
ball.y := ball.posy + round(ball.vy);
end;
exit; //////////////////////////return/////////////////////
end;
end;
end;
end else begin ///////////////速度小于可以控球速度
irandseed := random;
sumfandistenc := 0;
for i:=1 to 2 do
for j:=1 to CROBOTNUM do
begin
sumfandistenc := sumfandistenc + dists[i,j];
if irandseed < sumfandistenc then
begin
crt := i;
crn := j;
robots[i,j].doAction;
while (sqrt(sqr(robots[backteamid,backno].absolutex - ball.x) + sqr(robots[backteamid, backno].absolutey - ball.y )) < CRADIUS ) do
begin
ball.x := ball.posx + round(ball.vx);
ball.y := ball.posy + round(ball.vy);
end;
exit; //////////////////////////return/////////////////////
end;
end;
end;
end;
end;
end;
}
procedure TMatchField.setfirstteamaction;
var myCMDS :TCMDS;
i :integer;
begin
for i:=0 to 4 do
begin
myCMDS[i].ifresetmovement := 0;
myCMDS[i].TargetX :=0;
myCMDS[i].TargetY :=0;
myCMDS[i].TargetV :=0;
myCMDS[i].Preactiontype := 0;
myCMDS[i].PreAparam0 := 0;
myCMDS[i].PreAparam1 := 0;
myCMDS[i].PreAparam2 := 0;
end;
uMain.setaction_first(@myCMDS);
for i:=0 to 4 do
begin
if myCMDs[i].PreAparam0 > CMAXBALLV then
myCMDs[i].PreAparam0 := CMAXBALLV;
if myCMDs[i].PreAparam0 < CMINBALLV then
myCMDs[i].PreAparam0 := CMINBALLV;
if myCMDs[i].TargetV > CMAXV then
myCMDs[i].TargetV := CMAXV;
if myCMDS[i].ifresetmovement = 1 then
begin
robots[1,i+1].move(myCMDS[i].TargetX, myCMDS[i].TargetY, round(myCMDS[i].TargetV));
end;
robots[1,i+1].SetPreAction(myCMDS[i].Preactiontype, myCMDS[i].PreAparam0, myCMDS[i].PreAparam1, myCMDS[i].PreAparam2);
end;
end;
procedure TMatchField.setsecondteamaction;
var myCMDS :TCMDS;
i :integer;
begin
for i:=0 to 4 do
begin
myCMDS[i].ifresetmovement := 0;
myCMDS[i].TargetX :=0;
myCMDS[i].TargetY :=0;
myCMDS[i].TargetV :=0;
myCMDS[i].Preactiontype := 0;
myCMDS[i].PreAparam0 := 0;
myCMDS[i].PreAparam1 := 0;
myCMDS[i].PreAparam2 := 0;
end;
uMain.setaction_second(@myCMDS);
// showmessage(format('(5) parm0=%d parm1=%d, parm2=%d'+#13+#10+'(2) parm0=%d parm1=%d, parm2=%d',[myCMDS[4].preAparam0, myCMDS[4].preAparam1, myCMDs[4].preAparam2,myCMDS[1].preAparam0, myCMDS[1].preAparam1, myCMDs[1].preAparam2]));
for i:=0 to 4 do
begin
if myCMDs[i].PreAparam0 > CMAXBALLV then
myCMDs[i].PreAparam0 := CMAXBALLV;
if myCMDs[i].PreAparam0 < CMINBALLV then
myCMDs[i].PreAparam0 := CMINBALLV;
if myCMDs[i].TargetV > CMAXV then
myCMDs[i].TargetV := CMAXV;
// showmessage(floattostr(myCMDs[i].PreAparam0));
myCMDS[i].TargetX := myCMDS[i].TargetX;
myCMDS[i].TargetY := myCMDS[i].TargetY;
case myCMDS[i].Preactiontype of
0:begin
myCMDS[i].PreAparam0 := 0;
myCMDS[i].PreAparam1 := 0;
myCMDS[i].PreAparam2 := 0;
end;
1:begin
myCMDS[i].PreAparam1 := CFLDLEN - myCMDS[i].PreAparam1;
myCMDS[i].PreAparam2 := CFLDWIDTH - myCMDS[i].PreAparam2;
end;
2:begin
myCMDS[i].PreAparam1 := - myCMDS[i].PreAparam1;
myCMDS[i].PreAparam2 := - myCMDS[i].PreAparam2;
end;
end;
if myCMDS[i].ifresetmovement = 1 then
begin
robots[2,i+1].move(myCMDS[i].TargetX, myCMDS[i].TargetY, round(myCMDS[i].TargetV));
end;
robots[2,i+1].SetPreAction(myCMDS[i].Preactiontype, myCMDS[i].PreAparam0, myCMDS[i].PreAparam1, myCMDS[i].PreAparam2);
end;
end;
procedure TMatchField.TimeTip;
var bGoal :boolean;
goalteam :integer;
i, j :integer;
begin
bGoal := false;
ball.doMove(bGoal, goalteam);
if bGoal then
begin
if (Self.Scores[1]=0) and (Self.Scores[2]=0) then
firstGoalTeam := goalteam;
inc(Self.scores[goalteam]);
lastGoalTeam := goalteam;
InitMatch;
UpdateScores;
end;
for i:=2 downto 1 do
for j:=1 to 5 do
begin
robots[i,j].doMove;
end;
playerEffectball;
end;
procedure TMatchField.SecondGetBallState(apbs: PBS);
begin
apbs^.x := CFLDLEN - ball.x;
apbs^.y := CFLDWIDTH - ball.y;
apbs^.vx := - ball.vx;
apbs^.vy := - ball.vy;
apbs^.crn:= crn;
apbs^.crt:= crt;
end;
procedure TMatchField.SecondGetTeamAState(apts: PTS);
var i:integer;
begin
for i:=0 to 4 do
begin
{ apts^[i].no := i+1;
apts^[i].team := 1;
apts^[i].x := robots[1,i+1].x;
apts^[i].y := robots[1,i+1].y;
apts^[i].vx:= robots[1,i+1].vx;
apts^[i].vy:= robots[1,i+1].vy;}
apts^[i].no := i+1;
apts^[i].team := 1;
apts^[i].x := CFLDLEN - robots[1,i+1].x;
apts^[i].y := CFLDWIDTH - robots[1,i+1].y;
apts^[i].vx:= - robots[1,i+1].vx;
apts^[i].vy:= - robots[1,i+1].vy;
end;
end;
procedure TMatchField.SecondGetTeamBState(apts: PTS);
var i:integer;
begin
for i:=0 to 4 do
begin
apts^[i].no := i+1;
apts^[i].team := 2;
apts^[i].x := robots[2,i+1].x;
apts^[i].y := robots[2,i+1].y;
apts^[i].vx:= robots[2,i+1].vx;
apts^[i].vy:= robots[2,i+1].vy;
{ apts^[i].no := i+1;
apts^[i].team := 2;
apts^[i].x := CFLDLEN - robots[2,i+1].x;
apts^[i].y := CFLDWIDTH - robots[2,i+1].y;
apts^[i].vx:= -robots[2,i+1].vx;
apts^[i].vy:= -robots[2,i+1].vy;}
end;
end;
procedure TMatchField.UpdateScores;
begin
uMain.Form1.Label1.Caption := inttostr(scores[1]);
uMain.Form1.Label2.Caption := inttostr(scores[2]);
uMain.Form1.Caption := format('%s %d -- %d %s',[uMain.Form1.Label3.Caption,scores[1],scores[2],uMain.Form1.Label4.Caption]);
end;
procedure TMatchField.playerEffectball;
var newvx, newvy : double;
dists : array [1..2, 1..CROBOTNUM] of double;
mindist : double;
i, j : integer;
backteamid : integer;
backplayerid : integer;
bThereIsPlayerCanEffectBall : boolean;
iRandSeed : double;
fansumdist : double;
curfansum : double;
temp : double;
label g1;
begin
mindist := 100000;
backteamid := 1;
backplayerid := 1;
fansumdist := 0;
bThereIsPlayerCanEffectBall := false;
for i:=1 to 2 do
for j:=1 to CROBOTNUM do
begin
// if Robots[i,j].absolutey>2500 then
// showmessage('!');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -