//this method iterates through each possible spot and calculates its
        //score.
        public Vector DetermineBestSupportingPosition()
        {
            //reset the best supporting spot
            bestSupportingSpot = new SupportSpot();

            double bestScoreSoFar = 0.0;

            foreach (SupportSpot curSpot in spots)
            {
                //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)
                curSpot.score = 1.0;

                //Test 1. is it possible to make a safe pass from the ball's position
                //to this position?
                Vector vControllingPlayerPos = new Vector(team.controllingPlayer.position);
                if (team.IsPassSafeFromAllOpponents(vControllingPlayerPos, curSpot.spot, null, 30.0))
                {
                    curSpot.score += 2.0;
                }


                //Test 2. Determine if a goal can be scored from this position.
                if (team.CanShoot(curSpot.spot, 30.0))
                {
                    curSpot.score += 1.0;
                }

                //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 = 22.5;

                    double dist = Vector.VecDistance(new Vector(team.controllingPlayer.position), curSpot.spot);

                    double temp = Math.Abs(OptimalDistance - dist);

                    if (temp < OptimalDistance)
                    {
                        //normalize the distance and add it to the score
                        curSpot.score += 2.0 * (OptimalDistance - temp) / OptimalDistance;
                    }
                }

                //check to see if this spot has the highest score so far
                if (curSpot.score > bestScoreSoFar)
                {
                    bestScoreSoFar = curSpot.score;

                    bestSupportingSpot = curSpot;
                }
            }

            return(bestSupportingSpot.spot);
        }
 public SupportSpotCalculator(SoccerTeam _team)
 {
     soccerTeam = _team;
     MapUtil mapUtils = MapUtil.getInstance();
     foreach(Vector3 item in mapUtils.SupportSpots(soccerTeam.TeamType))
     {
         SupportSpot spot = new SupportSpot(item,1.0f);
         supportSpots.Add(spot);
     }
 }
Exemple #3
0
    public Vector2 determineBestSupportingPosition()
    {
        //reset the best supporting spot
        m_pBestSupportingSpot = null;

        float BestScoreSoFar = 0.0f;

        List <SupportSpot> squareList = new List <SupportSpot>();

        foreach (SupportSpot square in squareList)
        {
            //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)
            square.m_dScore = 1.0f;

            //Test 1. is it possible to make a safe pass from the ball's position to this position?
            if (BigAI.isPassSafeFromAllOpponents(BigAI.m_playerWithBallPosition, square.m_vPos))
            {
                square.m_dScore += Prm.Spot_PassSafeStrength;
            }

            //Test 2. Determine if a goal can be scored from this position.
            if (canShoot(square.m_vPos))
            {
                square.m_dScore += Prm.Spot_CanScoreStrength;
            }

            //Test 3. calculate how far this spot is away from the controlling
            //player. The farther away, the higher the score. Any distances farther
            //away than OptimalDistance pixels do not receive a score.
            float OptimalDistance = 200.0f;
            float dist            = Vector2.Distance(m_position, square.m_vPos);
            float temp            = Mathf.Abs(OptimalDistance - dist);
            if (temp < OptimalDistance)
            {
                //normalize the distance and add it to the score
                square.m_dScore += Prm.Spot_DistFromControllingPlayerStrength * (OptimalDistance - temp) / OptimalDistance;
            }

            //check to see if this spot has the highest score so far
            if (square.m_dScore > BestScoreSoFar)
            {
                BestScoreSoFar        = square.m_dScore;
                m_pBestSupportingSpot = square;
            }
        }

        return(m_pBestSupportingSpot.m_vPos);
    }
        //this will regulate how often the spots are calculated (default is
        //one update per second)
        //Regulator* m_pRegulator;


        public SupportSpotCalculator(int numX, int numY, Team team)
        {
            this.team = team;
            spots     = new List <SupportSpot>();
            Region PlayingField = this.team.pitch.playingArea;

            //calculate the positions of each sweet spot, create them and
            //store them in m_Spots
            double HeightOfSSRegion = PlayingField.Height() * 0.8;
            double WidthOfSSRegion  = PlayingField.Width() * 0.9;
            double SliceX           = WidthOfSSRegion / numX;
            double SliceY           = HeightOfSSRegion / numY;

            double left  = PlayingField.left + (PlayingField.Width() - WidthOfSSRegion) / 2.0 + SliceX / 2.0;
            double right = PlayingField.right - (PlayingField.Width() - WidthOfSSRegion) / 2.0 - SliceX / 2.0;
            double top   = PlayingField.top + (PlayingField.Height() - HeightOfSSRegion) / 2.0 + SliceY / 2.0;

            Vector      spot;
            SupportSpot supportSpot;

            for (int x = 0; x < (numX / 2) - 1; ++x)
            {
                for (int y = 0; y < numY; ++y)
                {
                    if (team.playingDirection == Team.DirectionType.LEFT)
                    {
                        spot        = new Vector(left + x * SliceX, top + y * SliceY);
                        supportSpot = new SupportSpot(spot, 0.0);
                        spots.Add(supportSpot);
                    }

                    else
                    {
                        spot        = new Vector(right - x * SliceX, top + y * SliceY);
                        supportSpot = new SupportSpot(spot, 0.0);
                        spots.Add(supportSpot);
                    }
                }
            }
        }
    public Vector3 DetermineBestSupportingPosition()
    {
        // do this every 5 frames
        if (timeSinceLastSupportSpotCalculated < 10 && bestSupportSpot != null)
        {
            return(bestSupportSpot.position);
        }
        // there will be many spots between goals
        ArrayList supportSpots = new ArrayList();

        for (float x = pitch.leftTop.x + 2.10f; x < pitch.leftTop.x + pitch.width; x = x + 0.3f)
        {
            for (float y = pitch.leftTop.y; y > pitch.leftTop.y - pitch.height; y = y - 0.3f)
            {
                SupportSpot sp = new SupportSpot();
                sp.position = new Vector3(x, y, 0);
                sp.score    = 0;
                supportSpots.Add(sp);
            }
        }
        bestSupportSpot = null;
        double bestScoreSoFar   = 0.0d;
        double maxPassingForce  = 10.0d;
        double maxShootingForce = 10.0d;

        //print(controllingPlayer.name);
        foreach (SupportSpot spot in supportSpots)
        {
            spot.score = 0;
            if (IsPassSafeFromAllOpponents(spot.position,
                                           spot.position, maxPassingForce))
            {
                spot.score += 1;
            }
            if (CanShoot(spot.position,
                         opponent.goal.center, maxShootingForce))
            {
                //print(string.Format("can shoot from {0}", spot.position));
                spot.score += 4;
            }
            if (controllingPlayer)
            {
                float optimalDistance  = 3.0f;
                float miniumumDistance = 1.0f;
                float distanceFromControllingPlayer =
                    (controllingPlayer.transform.position - spot.position).magnitude;
                float deltaWithOptimalDistance = Mathf.Abs(optimalDistance - distanceFromControllingPlayer);

                if (deltaWithOptimalDistance < optimalDistance && distanceFromControllingPlayer > miniumumDistance)
                {
                    float scoreFactor = distanceFromControllingPlayer / optimalDistance;
                    spot.score += 4 * scoreFactor;
                }
            }
            if (spot.score > bestScoreSoFar)
            {
                bestSupportSpot = spot;
                bestScoreSoFar  = spot.score;
            }
        }

        //print(string.Format("position: {0} score :{1}", bestSupportSpot.position, bestSupportSpot.score));
        return(bestSupportSpot.position);
    }