Interpose In Soccer

Ok, so I am doing a homework assignment where we need to setup an interpose with players in the wait state.

And this is the code I have come up with so far, but for some reason everytime I try to run this code, the program crashes after a few seconds . . . Any help would be greatly appreciated!

This is not the entire code, just the new portion that I have written.

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
//interpose behavior

  if (player->Pitch()->GameOn())

  {
	FieldPlayer*oppPlayer=NULL;
	double rad = Prm.GoalWidth;
	SoccerTeam*opposingTeam = player->Team()->Opponents();

if (opposingTeam->InControl())
{
std::vector<PlayerBase*>::const_iterator end=opposingTeam->Members().end();
std::vector<PlayerBase*>::const_iterator it=opposingTeam->Members().begin();

while (it != end)
{
//Get the iterator's player
FieldPlayer*p=(FieldPlayer*)(*it);

// if the iterators player is not the controlling player and falls within the radius
if (Vec2DDistanceSq(player->Pos(),p->Pos())<rad*rad&&!p->isControllingPlayer())
{
//if we found the first opposing player
if (oppPlayer == NULL || oppPlayer->DistToOppGoal()> p->DistToOppGoal())
{
oppPlayer= p;	
}
else
{
oppPlayer= p;

//update iterator
++it;}

{
if (oppPlayer!= NULL)
{
//Set up interpose Steering Behavior
double distance = sqrt(oppPlayer->DistSqToBall())/2;
debug_con << "Player" << player ->ID() << "interposing" << "";
player->Steering()->SetTarget(oppPlayer->Pos());
player->Steering()->InterposeOn(distance);
}
else
{
return;
}
}
}
}
}
}
Last edited on
Topic archived. No new replies allowed.