public Vector2D DetermineBestSupportingPosition() { //only update the spots every few frames if (!_regulator.IsReady /* && _bestSupportingSpot != null */) { return _bestSupportingSpot.m_vPos; } //reset the best supporting spot _bestSupportingSpot = null; double BestScoreSoFar = 0.0; for (int spotIndex = 0; spotIndex < _supportSpots.Count; spotIndex++) { //first remove any previous score. (the score is set to one so that //the viewer can see the positions of all the spots if he has the //aids turned on) _supportSpots[spotIndex].m_dScore = 1.0; //Test 1. is it possible to make a safe pass from the ball's position //to this position? if (_team.IsPassSafeFromAllOpponents(_team.ControllingPlayer.Position, _supportSpots[spotIndex].m_vPos, null, ParameterManager.Instance.MaxPassingForce)) { _supportSpots[spotIndex].m_dScore += ParameterManager.Instance.SpotPassSafeScore; } Vector2D shotTarget = new Vector2D(); //Test 2. Determine if a goal can be scored from this position. if (_team.CanShoot(_supportSpots[spotIndex].m_vPos, ParameterManager.Instance.MaxShootingForce, ref shotTarget)) { _supportSpots[spotIndex].m_dScore += ParameterManager.Instance.SpotCanScoreFromPositionScore; } //Test 3. calculate how far this spot is away from the controlling //player. The further away, the higher the score. Any distances further //away than OptimalDistance pixels do not receive a score. if (_team.SupportingPlayer != null) { const double OptimalDistance = 200.0; double dist = Vector2D.Vec2DDistance(_team.ControllingPlayer.Position, _supportSpots[spotIndex].m_vPos); double temp = Math.Abs(OptimalDistance - dist); if (temp < OptimalDistance) { //normalize the distance and add it to the score _supportSpots[spotIndex].m_dScore += ParameterManager.Instance.SpotDistFromControllingPlayerScore * (OptimalDistance - temp) / OptimalDistance; } } //check to see if this spot has the highest score so far if (_supportSpots[spotIndex].m_dScore > BestScoreSoFar) { BestScoreSoFar = _supportSpots[spotIndex].m_dScore; _bestSupportingSpot = _supportSpots[spotIndex]; } } return _bestSupportingSpot.m_vPos; }
public Vector2D DetermineBestSupportingPosition() { //only update the spots every few frames if (!_regulator.IsReady /* && _bestSupportingSpot != null */) { return(_bestSupportingSpot.m_vPos); } //reset the best supporting spot _bestSupportingSpot = null; double BestScoreSoFar = 0.0; for (int spotIndex = 0; spotIndex < _supportSpots.Count; spotIndex++) { //first remove any previous score. (the score is set to one so that //the viewer can see the positions of all the spots if he has the //aids turned on) _supportSpots[spotIndex].m_dScore = 1.0; //Test 1. is it possible to make a safe pass from the ball's position //to this position? if (_team.IsPassSafeFromAllOpponents(_team.ControllingPlayer.Position, _supportSpots[spotIndex].m_vPos, null, ParameterManager.Instance.MaxPassingForce)) { _supportSpots[spotIndex].m_dScore += ParameterManager.Instance.SpotPassSafeScore; } Vector2D shotTarget = new Vector2D(); //Test 2. Determine if a goal can be scored from this position. if (_team.CanShoot(_supportSpots[spotIndex].m_vPos, ParameterManager.Instance.MaxShootingForce, ref shotTarget)) { _supportSpots[spotIndex].m_dScore += ParameterManager.Instance.SpotCanScoreFromPositionScore; } //Test 3. calculate how far this spot is away from the controlling //player. The further away, the higher the score. Any distances further //away than OptimalDistance pixels do not receive a score. if (_team.SupportingPlayer != null) { const double OptimalDistance = 200.0; double dist = Vector2D.Vec2DDistance(_team.ControllingPlayer.Position, _supportSpots[spotIndex].m_vPos); double temp = Math.Abs(OptimalDistance - dist); if (temp < OptimalDistance) { //normalize the distance and add it to the score _supportSpots[spotIndex].m_dScore += ParameterManager.Instance.SpotDistFromControllingPlayerScore * (OptimalDistance - temp) / OptimalDistance; } } //check to see if this spot has the highest score so far if (_supportSpots[spotIndex].m_dScore > BestScoreSoFar) { BestScoreSoFar = _supportSpots[spotIndex].m_dScore; _bestSupportingSpot = _supportSpots[spotIndex]; } } return(_bestSupportingSpot.m_vPos); }