Exemplo n.º 1
0
        public void FindOptimalPolePositions()
        {
            Bmp = new Bitmap((int)TableLength, (int)TableWidth);
            m_Graphics = Graphics.FromImage(Bmp);

            RenderPitch();

            List<PolePosition> polePositions = new List<PolePosition>();
            Random r = new Random();

            for (int i = 0; i < 100; i++)
            {
                PolePosition pp = new PolePosition();
                pp.PosAttack += (float)(r.NextDouble() * 210) + 36;
                pp.PosMidfield += (float)(r.NextDouble() * 120) + 36;
                pp.PosDefence += (float)(r.NextDouble() * 240) + 36;
                pp.PosGoalie += (float)(r.NextDouble() * 250);

                polePositions.Add(pp);
                pp.Score = ScorePath(pp, false);
            }

            PolePosition bestPos = polePositions.OrderBy(x => x.Score).First();
            m_Score = ScorePath(bestPos, true);

            RenderPlayers();
        }
Exemplo n.º 2
0
        public int ScorePath(PolePosition pp, bool draw)
        {
            float startX = 220f;
            float endX = TableLength;
            float yStepSize = 2f;

            int score = 0;
            int[] shotScores = new int[400];

            if (draw)
                yStepSize = 1f;

            ResetPlayers();

            for (int i = 0; i < 3; i++)
                pYs[i] += pp.PosAttack;
            for (int i = 3; i < 8; i++)
                pYs[i] += pp.PosMidfield;
            for (int i = 8; i < 10; i++)
                pYs[i] += pp.PosDefence;
            pYs[10] += pp.PosGoalie;

            for (float startY = 30; startY < TableWidth / 2f; startY += yStepSize)
            {
                for (float endY = ((TableWidth - GoalWidth) + BallGoInWidth) / 2f; endY < ((TableWidth + GoalWidth) - BallGoInWidth) / 2f; endY += yStepSize)
                {
                    bool pathClear = IsPathClear(startX, startY, endX, endY);
                    if (pathClear)
                    {
                        if (draw)
                            m_Graphics.DrawLine(new Pen(yellowBrush), startX, startY, endX - 8, endY);
                        score++;
                        shotScores[(int)startY]++;
                    }
                }
            }

            //return shotScores.Max();
            return score;
        }