-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAgentInfo.cpp
More file actions
executable file
·171 lines (132 loc) · 4.15 KB
/
AgentInfo.cpp
File metadata and controls
executable file
·171 lines (132 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include "AgentInfo.h"
#define AgentInfoLog gLog<< "[A_Info] "
AgentInfo::AgentInfo( WorldModel *wm )
{
mWorldModel = wm;
mOppMaxSpeed = 0.0f;
mOurMaxSpeed = 0.0f;
mBallSpeed = 0.0f;
mBallAveragePos.x = 0.0f;
mBallAveragePos.y = 0.0f;
mBallAveragePos.z = 0.0f;
}
AgentInfo::~AgentInfo()
{
}
void AgentInfo::Update()
{
const float ourMaxSpeedLimit = 0.7f;
const float oppMaxSpeedLimit = 1.0f;
static float countCycle = 1.0f;
for( unsigned int i = HistoryNum - 1; i > 0; i -- )
{
for( unsigned int j = 0; j < PlayerOnField; j ++ )
{
mOppPlayerPos[j][i] = mOppPlayerPos[j][i-1];
mOurPlayerPos[j][i] = mOurPlayerPos[j][i-1];
}
mBallPos[i] = mBallPos[i-1];
}
for( unsigned int i = 0; i < mWorldModel->mOppPlayerNumOnField; i ++ )
{
mOppPlayerPos[i][0] = mWorldModel->mOppTeamPlayer[i].mPos;
}
for( unsigned int i = 0; i < mWorldModel->mOurPlayerNumOnField; i ++ )
{
mOurPlayerPos[i][0] = mWorldModel->mOurTeamPlayer[i].mPos;
}
mBallPos[0] = mWorldModel->mBall.mPos;
for( unsigned int i = mWorldModel->mOppPlayerNumOnField; i < PlayerOnField; i ++ )
{
Vector3f zeroVector(0.0f, 0.0f, 0.0f);
mOppPlayerPos[i][0] = zeroVector;
}
for( unsigned int i = mWorldModel->mOurPlayerNumOnField; i < PlayerOnField; i ++ )
{
Vector3f zeroVector(0.0f, 0.0f, 0.0f);
mOurPlayerPos[i][0] = zeroVector;
}
//cout<< mWorldModel->mOppTeamPlayer[0].mPos.x << endl;
float tempOppMaxSpeed;
float tempOurMaxSpeed;
float averOppSpeed = 0.0f;
float averOurSpeed = 0.0f;
for( unsigned int i = 0; i < PlayerOnField; i ++ )
{
tempOppMaxSpeed = mOppPlayerPos[i][0].distXY2( mOppPlayerPos[i][HistoryNum - 1] ) / ( SimStepTime * HistoryNum );
tempOurMaxSpeed = mOurPlayerPos[i][0].distXY2( mOurPlayerPos[i][HistoryNum - 1] ) / ( SimStepTime * HistoryNum );
//cout<< mOppPlayerPos[i][0].distXY2( mOppPlayerPos[i][1] ) << endl;
//if( tempOppMaxSpeed > mOppMaxSpeed && tempOppMaxSpeed < oppMaxSpeedLimit )
//{
// mOppMaxSpeed = tempOppMaxSpeed;
//}
if( tempOppMaxSpeed > averOppSpeed )
{
averOppSpeed = tempOppMaxSpeed;
}
if( tempOurMaxSpeed > averOurSpeed )
{
averOurSpeed = tempOurMaxSpeed;
}
//if( tempOurMaxSpeed > mOurMaxSpeed && tempOurMaxSpeed < ourMaxSpeedLimit )
//{
// mOurMaxSpeed = tempOurMaxSpeed;
//}
}
mOppMaxSpeed = averOppSpeed;
mOurMaxSpeed = averOurSpeed;
// 球的速度(平均速度)
mBallSpeed = mBallPos[0].distXY2( mBallPos[HistoryNum - 1] ) / ( SimStepTime * HistoryNum );
// 球的运动方向
//mBallMoveTo = ( mBallPos[0] - mBallPos[HistoryNum - 1] ) / HistoryNum;
mBallMoveTo = mBallPos[0] - mBallPos[1];
mBallAveragePos = mBallAveragePos * (countCycle - 1.0f)/(countCycle) + mWorldModel->mBall.mPos / (countCycle);
float fieldLength = mWorldModel->mFieldLength;
if( mBallAveragePos.x >= fieldLength / 10.0f )
{
mWorldModel->mOppStrength = OS_Weak;
}
else if( mBallAveragePos.x <= -fieldLength / 10.0f )
{
mWorldModel->mOppStrength = OS_Strong;
}
else
{
mWorldModel->mOppStrength = OS_Normal;
}
if( mWorldModel->mOurScore < mWorldModel->mOppScore )
{
mWorldModel->mOppStrength = OS_Strong;
}
//AgentInfoLog << "OppMaxSpeed: " << GetOppMaxSpeed()
// << " OurMaxSpeed: " << GetOurMaxSpeed()
// << " Ball Speed: " << GetBallSpeed()
// << " Ball Moving To: " << GetBallMoveToPos().x << " " << GetBallMoveToPos().y
// << endl;
//AgentInfoLog << "BallAveragePos: " << mBallAveragePos.x << " " << mBallAveragePos.y
// << endl;
//AgentInfoLog << "OurPlayerNumOnField: " << mWorldModel->mOppPlayerNumOnField << " "
// << "OppPlayerNumOnField: " << mWorldModel->mOppPlayerNumOnField << " "
// << endl;
countCycle += 1.0f;
}
float AgentInfo::GetOppMaxSpeed()
{
return mOppMaxSpeed + 0.01f; // 防止除数为0
}
float AgentInfo::GetOurMaxSpeed()
{
return mOurMaxSpeed + 0.01f; // 防止除数为0
}
Vector3f AgentInfo::GetBallMoveToPos()
{
return mBallMoveTo;
}
float AgentInfo::GetBallSpeed()
{
return mBallSpeed + 0.01f; // 防止除数为0
}
float AgentInfo::GetBallAveragePosX()
{
return mBallAveragePos.x;
}