Beispiel #1
0
        public void DrawControlPoints(Rectangle screenRect)
        {
            BasicPrimitives primitive = new BasicPrimitives(DisplayManager.Instance.Game.GraphicsDevice);

            for (int i = 0; i < mCurves.Count; i++)
            {
                for (int j = 0; j < mCurves[i].Points.Length - 1; j++)
                {
                    primitive.CreateLine(translanteCoord(mCurves[i].Points[j], screenRect), translanteCoord(mCurves[i].Points[j + 1], screenRect));
                    primitive.Thickness = 2.0f;
                    primitive.Colour    = Color.Red;
                    primitive.RenderLinePrimitive(DisplayManager.Instance.SpriteBatch);
                }
            }

            for (int i = 0; i < mCurves.Count; i++)
            {
                for (int j = 0; j < mCurves[i].Points.Length; j++)
                {
                    if (j != 0 || i == 0)
                    {
                        primitive.Colour = Color.Green;
                        primitive.CreateCircle(10, 10);
                        primitive.Position = translanteCoord(new Vector2(mCurves[i].Points[j].X, mCurves[i].Points[j].Y), screenRect);
                        primitive.RenderRoundPrimitive(DisplayManager.Instance.SpriteBatch);
                    }
                }
            }
        }
Beispiel #2
0
        public void Draw(Rectangle screenRect)
        {
            BasicPrimitives primitive = new BasicPrimitives(DisplayManager.Instance.Game.GraphicsDevice);

            double t = 0.0;
            int    j = 0;

            for (double i = 0.00; (float)i < 1.0f; i += 0.001)
            {
                if ((float)(i + 0.001) <= 1.0f)
                {
                    primitive.CreateLine(translanteCoord(getPoint((float)i), screenRect), translanteCoord(getPoint((float)(i + 0.001)), screenRect));
                    primitive.Thickness = 2.0f;
                    primitive.RenderLinePrimitive(DisplayManager.Instance.SpriteBatch);
                }
            }
        }
Beispiel #3
0
        public void Draw()
        {
            _fpsCount++;
            AI.AIObject aiobj  = AIGame.AIContainer.SelectedObject;
            AI.AITeam   aiteam = AIGame.AIContainer.SelectedTeam;

            // NOTE: migration to XNA 4.0 _spriteBatch.Begin(SpriteSpriteBlendMode.AlphaBlend);
            _spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);

            // NOTE: migration to XNA 4.0 _spriteBatch.GraphicsDevice.RenderState.FillMode = FillMode.Solid;

            #region DRAW GRAPH
            if (Settings.DRAW_GRAPH)
            {
                float h = AIGame.device.Viewport.Height;
                float w = AIGame.device.Viewport.Width;

                _graphAvg.ClearVectors();
                _graphMax.ClearVectors();

                _graphAvg.AddVector(new Vector2(0, h));
                _graphMax.AddVector(new Vector2(0, h));
                float index = 1;
                for (int i = 0; i < AIGame.AIContainer.FitnessListAvg.Count; i++)
                {
                    Vector2 pointAvg = new Vector2(
                        w / (AIGame.AIContainer.FitnessListAvg.Count / index),
                        h - (float)AIGame.AIContainer.FitnessListAvg[i] / (AI.AIParams.UPDATE_EVOLUTION_TIME_PERIOD_FRAMES * 2.0f) * h
                        );
                    Vector2 pointMax = new Vector2(
                        w / (AIGame.AIContainer.FitnessListMax.Count / index),
                        h - (float)AIGame.AIContainer.FitnessListMax[i] / (AI.AIParams.UPDATE_EVOLUTION_TIME_PERIOD_FRAMES * 2.0f) * h
                        );

                    _graphAvg.AddVector(pointAvg);
                    _graphMax.AddVector(pointMax);
                    index++;
                }
                _graphAvg.Colour    = Color.LightPink;
                _graphAvg.Thickness = 0.5f;
                _graphMax.Colour    = Color.LightSalmon;
                _graphMax.Thickness = 0.5f;

                _graphAvg.RenderLinePrimitive(_spriteBatch);
                _graphMax.RenderLinePrimitive(_spriteBatch);
            }
            #endregion

            #region RIGHT UP CORNER
            _spriteBatch.DrawString(_textFont, "FPS:" + _fps, new Vector2(AIGame.graphics.GraphicsDevice.Viewport.Width - 100, 5f), Color.Gold);
            if (AI.AIParams.FITNESS_INCREASE_WITH_TIME_ENABLE)
            {
                _spriteBatch.DrawString(_textFont, "FF's:" + AIGame.AIContainer.FramesCounterForFitness + "/" + AI.AIParams.FITNESS_INCREASE_WITH_TIME_PERIOD_FRAMES, new Vector2(AIGame.graphics.GraphicsDevice.Viewport.Width - 100, 20f), Color.Coral);
                _spriteBatch.DrawString(_textFont, "Still alive:" + AIGame.AIContainer.NumberAIObjStillAlive, new Vector2(AIGame.graphics.GraphicsDevice.Viewport.Width - 100, 35f), Color.Coral);
            }

            if (AI.AIParams.UPDATE_EVOLUTION_ENABLED)
            {
                _spriteBatch.DrawString(_textFont, "FE's:" + AIGame.AIContainer.FramesCounterForEvolution + "/" + AI.AIParams.UPDATE_EVOLUTION_TIME_PERIOD_FRAMES, new Vector2(AIGame.graphics.GraphicsDevice.Viewport.Width - 100, 50f), Color.Coral);
            }
            _spriteBatch.DrawString(_textFont, "Camera Mode: " + AIGame.camera.CurrentBehavior.ToString(), new Vector2(5f, 5f), Color.Gold);

            #endregion

            #region DUMP ANN INPUTS AND OUTPUTS
            if (aiobj != null && AI.AIParams.CONFIG_DUMP_ANN_VECTORS)
            {
                // dumpa ann information
                List <double> temp = new List <double>();
                temp.AddRange(aiobj.AINeuralBrain.Inputs);
                temp.AddRange(aiobj.AINeuralBrain.Outputs);

                if (Utilities.DoubleCache.Count == 0)
                {
                    Utilities.DoubleCache.Add(temp);
                }
                if (!AreListsEqual(Utilities.DoubleCache[Utilities.DoubleCache.Count - 1], temp))
                {
                    Utilities.DoubleCache.Add(temp);
                }

                if (Utilities.DoubleCache.Count > AI.AIParams.CONFIG_DUMP_ANN_VECTORS_NUM_PROBES)
                {
                    Utilities.WriteToFile(Utilities.DoubleCache, AI.AIParams.CONFIG_DUMP_ANN_VECTORS_FILE_PATH, true);
                    Utilities.DoubleCache.Clear();
                }

                // draw ann inputs and outputs
                StringBuilder text = new StringBuilder();
                text.AppendLine(aiobj.Identifier);
                text.AppendLine("           TDis     CDis    BDis     MDis    Lf        ShAt");// +
                //"                 A/B      TC       Med     W");
                string inputs_outputs = "Inputs:";
                foreach (double input in aiobj.AINeuralBrain.Inputs)
                {
                    inputs_outputs += " " + string.Format("{0:0.0000}", input);
                }
                inputs_outputs += " OutputsBefSig:";
                foreach (double outputBS in aiobj.AINeuralBrain.OutputsBeforeSig)
                {
                    inputs_outputs += " " + string.Format("{0:0.0000}", outputBS);
                }
                inputs_outputs += " Outputs:";
                foreach (double output in aiobj.AINeuralBrain.Outputs)
                {
                    inputs_outputs += " " + string.Format("{0:0.0000}", output);
                }

                text.AppendLine(inputs_outputs);

                int j = 0;
                foreach (string line in text.ToString().Split('\n'))
                {
                    _spriteBatch.DrawString(_textFont, line, new Vector2(5f, AIGame.Console.Height + j++ *15f), Color.PaleGreen);
                }

                _spriteBatch.DrawString(_textFont, "Probing ANN states:" + Utilities.DoubleCache.Count + "/" + AI.AIParams.CONFIG_DUMP_ANN_VECTORS_NUM_PROBES, new Vector2(5f, AIGame.graphics.GraphicsDevice.Viewport.Height - 245), Color.Coral);
            }
            #endregion

            #region AIOBJECTS LIST
            if (AI.AIParams.CONFIG_DUMP_ANN_VECTORS)
            {
                int k      = 0;
                int intend = 0;
                foreach (AI.AITeam ait in AIGame.AIContainer.Teams)
                {
                    foreach (AI.AIObject aio in ait.Values)
                    {
                        _spriteBatch.DrawString(_textFontSmall,
                                                aio.Identifier + " (" +
                                                aio.AIFitnessesListLife.Count + ", " +
                                                Math.Round(aio.AIFitnessLife, 1) + "-" +
                                                Math.Round(aio.AIFitnessPenaltyCounter, 1) + "+" +
                                                Math.Round(aio.AIFitnessExp, 1) + "+" +
                                                Math.Round(aio.AIFitnessCustom, 1) + "=" +
                                                Math.Round(aio.AIFitness, 1) + ", " +
                                                aio.ActualAction.ToString().Substring(0, 3) + ")"
                                                ,
                                                new Vector2(AIGame.graphics.GraphicsDevice.Viewport.Width - 850 + intend, 200f + k * 15f), Color.PaleGreen);
                        k++;
                    }
                    intend += 300;
                    k       = 0;
                }
            }
            #endregion

            #region LEFT BOTTOM CORNER
            int locationy = 230;
            _spriteBatch.DrawString(_textFont, "Fittest AIObject: " + AIGame.AIContainer.GenethicAlgorithm.FittestObject.Identifier, new Vector2(5f, AIGame.graphics.GraphicsDevice.Viewport.Height - locationy), Color.Coral);
            _spriteBatch.DrawString(_textFont, "Generation: " + AIGame.AIContainer.Generation, new Vector2(5f, AIGame.graphics.GraphicsDevice.Viewport.Height - locationy + 15), Color.Coral);
            _spriteBatch.DrawString(_textFont, "FitnessScaling: " + AI.AIParams.FitnessScalling.ToString(), new Vector2(5f, AIGame.graphics.GraphicsDevice.Viewport.Height - locationy + 30), Color.Coral);
            _spriteBatch.DrawString(_textFont, "Best fit : " + Math.Round(AIGame.AIContainer.GenethicAlgorithm.BestFitness, 2), new Vector2(5f, AIGame.graphics.GraphicsDevice.Viewport.Height - locationy + 45), Color.Coral);
            _spriteBatch.DrawString(_textFont, "Average fitness: " + Math.Round(AIGame.AIContainer.GenethicAlgorithm.AverageFitness, 2), new Vector2(5f, AIGame.graphics.GraphicsDevice.Viewport.Height - locationy + 60), Color.Coral);
            _spriteBatch.DrawString(_textFont, "Worst fitness: " + Math.Round(AIGame.AIContainer.GenethicAlgorithm.WorstFitness, 2), new Vector2(5f, AIGame.graphics.GraphicsDevice.Viewport.Height - locationy + 75), Color.Coral);

            if (AIGame.camera.CurrentBehavior == Camera.Behavior.FreeView)
            {
                _spriteBatch.DrawString(_textFont, "Mouse X: " + Mouse.GetState().X.ToString(), new Vector2(5f, AIGame.graphics.GraphicsDevice.Viewport.Height - 125), Color.Gold);
                _spriteBatch.DrawString(_textFont, "Mouse Y: " + Mouse.GetState().Y.ToString(), new Vector2(5f, AIGame.graphics.GraphicsDevice.Viewport.Height - 110), Color.Gold);

                _spriteBatch.DrawString(_textFont, "Cursor X: " + Math.Round(AIGame.terrain.groundCursorPosition.X, 5) + " (" + +Math.Round(AIGame.terrain.groundCursorPosition.X, 5) * Settings.TERRAIN_TEXTURE_SIZE + ")", new Vector2(5f, AIGame.graphics.GraphicsDevice.Viewport.Height - 95), Color.Gold);
                _spriteBatch.DrawString(_textFont, "Cursor Y: " + Math.Round(AIGame.terrain.groundCursorPosition.Y, 5) + " (" + +Math.Round(AIGame.terrain.groundCursorPosition.Y, 5) + ")", new Vector2(5f, AIGame.graphics.GraphicsDevice.Viewport.Height - 80), Color.Gold);
                _spriteBatch.DrawString(_textFont, "Cursor Z: " + Math.Round(AIGame.terrain.groundCursorPosition.Z, 5) + " (" + +Math.Round(AIGame.terrain.groundCursorPosition.Z, 5) * Settings.TERRAIN_TEXTURE_SIZE + ")", new Vector2(5f, AIGame.graphics.GraphicsDevice.Viewport.Height - 65), Color.Gold);
            }

            _spriteBatch.DrawString(_textFont, "Camera X: " + Math.Round(AIGame.camera.Position.X, 5), new Vector2(5f, AIGame.graphics.GraphicsDevice.Viewport.Height - 50), Color.Gold);
            _spriteBatch.DrawString(_textFont, "Camera Y: " + Math.Round(AIGame.camera.Position.Y, 5), new Vector2(5f, AIGame.graphics.GraphicsDevice.Viewport.Height - 35), Color.Gold);
            _spriteBatch.DrawString(_textFont, "Camera Z: " + Math.Round(AIGame.camera.Position.Z, 5), new Vector2(5f, AIGame.graphics.GraphicsDevice.Viewport.Height - 20), Color.Gold);

            #endregion

            #region CONSOLE INFO
            if (AIGame.AIContainer.SelectedTeam != null &&
                AIGame.AIContainer.SelectedObject != null &&
                _update &&
                AIGame.Console.State == Console.ConsoleState.Opened)
            {
                AIGame.Console.Clear();
                AIGame.Console.Add("Team: " + AIGame.AIContainer.SelectedTeam.TeamType +
                                   " Objective: " + AIGame.AIContainer.SelectedTeam.Objective +
                                   " OAAU: " + AIGame.AIContainer.SelectedTeam.OperateAsAUnit +
                                   " KF: " + AIGame.AIContainer.SelectedTeam.KeepFormation +
                                   " Formation: " + AIGame.AIContainer.SelectedTeam.Formation);

                AIGame.Console.Add("ID: <" + AIGame.AIContainer.SelectedObject.Identifier + ">" +
                                   " Leader: <" + AIGame.AIContainer.SelectedObject.IsLeader + ">" +
                                   " Role: <" + AIGame.AIContainer.SelectedObject.Role + ">" +
                                   " Sight range: <" + AIGame.AIContainer.SelectedObject.SightRange + ">" +
                                   " Status: <" + AIGame.AIContainer.SelectedObject.Status + "(" + AIGame.AIContainer.SelectedObject.MovementSpeed + ")" + ">" +
                                   " Life: <" + AIGame.AIContainer.SelectedObject.Life * 100 + "%" + ">" +
                                   " Experience: <" + AIGame.AIContainer.SelectedObject.Experience + " pt" + ">" +
                                   " HF: <" + AIGame.AIContainer.SelectedObject.HoldFire + ">" +
                                   " Target: <" + (AIGame.AIContainer.SelectedObject.Target == null ? "none" : AIGame.AIContainer.SelectedObject.Target.Identifier + " (" + (aiobj.Target.Position - aiobj.Position).Length() + ")") + ">" +
                                   (AIGame.AIContainer.SelectedObject.IsShooting == true ? " Shooting!" : "") +
                                   (AIGame.AIContainer.SelectedObject.InCover == true ? " In Cover!" : ""));

                string whos_seen = string.Empty;
                foreach (AI.AIObject.SeenAIObject seen_aiobj in AIGame.AIContainer.SelectedObject.SightList)
                {
                    whos_seen += seen_aiobj.aiobj.Identifier + " ";
                }

                AIGame.Console.Add("See list (" + AIGame.AIContainer.SelectedObject.SightList.Count + "): " + whos_seen);

                string net_text = AI.AIParams.NumInputs.ToString();
                foreach (AI.ANN.NeuronLayer layer in aiobj.AINeuralBrain.Layers)
                {
                    net_text += " " + layer.NumOfNeurons;
                }
                AIGame.Console.Add("ANN: " + net_text + " Fitness: " + Math.Round(aiobj.AIFitness, 1) +
                                   " Actions: a:" + aiobj.ActionCounter[AI.AIAction.Attack] +
                                   " pb:" + aiobj.ActionCounter[AI.AIAction.PUBonus] +
                                   " pm:" + aiobj.ActionCounter[AI.AIAction.PUMed] +
                                   " tc:" + aiobj.ActionCounter[AI.AIAction.TakeCover] +
                                   " w:" + aiobj.ActionCounter[AI.AIAction.Wander] +
                                   ", " +
                                   " ACTUAL ACTION: " + aiobj.ActualAction.ToString() +
                                   " (" + aiobj.IsOccupied.ToString() + ")"
                                   );

                _update = false;
            }
            #endregion

            _spriteBatch.End();
        }