Example #1
0
        static void Snake(Random r)
        {
            for (int i = 0; i < 50; ++i)
            {
                Pool p = new Pool(24, 4, r);
                p.Population = 500;
                SnakeAgent sa = new SnakeAgent(8, 8, r);
                sa.Execute = 5;

                sa.InputMode = 3; // 0 food bi, tale m
                                  // 1 food m, tale m
                                  // 2 food bi tale bi
                                  // 3 food m tale bi

                sa.Fit = (int score, int lifetime) =>
                {
                    double fit = 1;

                    if (score <= 20)
                    {
                        fit *= score * score * score;
                    }
                    else
                    {
                        fit = 8000;
                        for (int j = 0; j < score - 20; ++j)
                        {
                            fit *= 1.25;
                        }
                    }
                    return((long)(fit * 5));
                };
                Writer w = new Writer(new FileInfo(string.Format("D://NEAT/Snake88/RC125P3ScoreInput3/Data{0}.txt", i)));

                SnakeDataDictionary sdd = new SnakeDataDictionary();
                p.Agent          = sa;
                p.DeltaThreshold = 4;
                p.DeltaDisjoint  = 10;
                p.DeltaWeight    = 4;

                p.LinkMutationChance       = 0.75;
                p.ConnectionMutationChance = 0.5;
                p.NodeMutationChance       = 0.2;

                p.WritePlayData  = true;
                p.WriteSpecies   = true;
                p.Writer         = w;
                p.DataDictionary = sdd;
                w.Start(p, sa.Execute);
                p.Initialize();
                p.DisplayTop = int.MaxValue;


                for (int k = 0; k < 300; ++k)
                {
                    p.Evaluate();
                    //w.Sw.Flush();
                }
            }
        }
Example #2
0
 private void OnTriggerEnter(Collider other)
 {
     if (!activated)
     {
         activated = true;
         SnakeAgent.ReachedGoal();
     }
 }
Example #3
0
 private void OnTriggerEnter(Collider other)
 {
     if ((!activated) && (other.name == "Sphere (4)" || other.name == "Sphere"))
     {
         GetComponent <MeshRenderer>().sharedMaterial = cpAct;
         activated = true;
         SnakeAgent.ReachedCheckpoint();
     }
 }
Example #4
0
        static void SnakeM(Random r)
        {
            Console.Write("Index : ");
            int    index = int.Parse(Console.ReadLine());
            int    x     = index % 5;
            int    y     = index / 5 % 25;
            int    z     = index / 25;
            double l     = (x + 1) * 0.2;
            double c     = (y + 1) * 0.2;
            double n     = (z + 1) * 0.2;

            Console.Write("Max : ");
            int max = int.Parse(Console.ReadLine());

            Console.WriteLine("Current Location : ");
            int current = int.Parse(Console.ReadLine());

            for (int j = index; j < 125; ++j)
            {
                for (int i = current; i < max; ++i)
                {
                    Pool p = new Pool(24, 4, r);
                    p.Population = 500;
                    SnakeAgent sa = new SnakeAgent(16, 16, r);
                    sa.Execute = 5;
                    SnakeDataDictionary sdd = new SnakeDataDictionary();
                    p.Agent          = sa;
                    p.DeltaThreshold = 4;
                    p.DeltaDisjoint  = 10;
                    p.DeltaWeight    = 4;

                    p.LinkMutationChance       = l;
                    p.ConnectionMutationChance = c;
                    p.NodeMutationChance       = n;
                    Writer w = new Writer(new FileInfo(string.Format("D://NEAT/DATA{0}_{1}.txt", index, i)));

                    p.WritePlayData  = true;
                    p.WriteSpecies   = true;
                    p.Writer         = w;
                    p.DataDictionary = sdd;
                    w.Start(p, sa.Execute);
                    p.Initialize();
                    p.DisplayTop    = int.MaxValue;
                    p.WritePlayData = true;

                    for (int k = 0; k < 300; ++k)
                    {
                        p.Evaluate();
                        w.Sw.Flush();
                    }
                }
                current = 0;
            }
        }
Example #5
0
    /// <summary>
    /// Create stuff
    /// </summary>
    private void CreateSnake()
    {
        //snake_head = Instantiate(snake_head, new Vector3(0, 0, 1),
        //    Quaternion.identity, snake_dad);
        snake = snake_dad.GetComponent <SnakeAgent>();
        snake.CreateSnake();
        //snake.tail = new List<Transform>();
        //snake.set_manager(this);
        //Transform t1 = Instantiate(tail, new Vector3(0, -1 * block_scale, 1),
        //    Quaternion.identity, snake_dad);
        //Transform t2 = Instantiate(tail, new Vector3(0, -2 * block_scale, 1),
        //    Quaternion.identity, snake_dad);
        //snake.tail.Add(t1);
        //snake.tail.Add(t2);

        //Add snake elemtns to array
        field[height / 2 + 0, width / 2] = 2; //tail
        field[height / 2 + 1, width / 2] = 2; //tail
        field[height / 2 - 1, width / 2] = 3; //head

        head = new Vector2(height / 2 - 1, width / 2);
        last_tail.Enqueue(new Vector2(height / 2 + 1, width / 2));
        last_tail.Enqueue(new Vector2(height / 2 + 0, width / 2));
    }
Example #6
0
        private void UpdateGraphics(object sender, PaintEventArgs e)
        {
            Graphics canvas = e.Graphics;

            if (!isPlaying)
            {
                return;
            }

            LblScoreValue.Text = "" + agent.Score;

            if (agent is SnakeAgent)
            {
                SnakeAgent sa    = agent as SnakeAgent;
                Brush      color = Brushes.White;

                LblHungerValue.Text = "" + sa.Hunger;

                int x = sa.X;
                int y = sa.Y;
                int[,] cells = new int[y, x];
                cells[sa.Food.Y, sa.Food.X] = 1;
                foreach (Square s in sa.Snake)
                {
                    cells[s.Y, s.X] = -1;
                }
                for (int i = 0; i < y; ++i)
                {
                    for (int j = 0; j < x; ++j)
                    {
                        if (cells[i, j] == 0)
                        {
                            color = Brushes.White;
                        }
                        else if (cells[i, j] == -1)
                        {
                            color = Brushes.Black;
                        }
                        else if (cells[i, j] == 1)
                        {
                            color = Brushes.Red;
                        }
                        canvas.FillRectangle(color, new Rectangle(
                                                 j * GameBox.Width / x + 1, i * GameBox.Height / y + 1, GameBox.Width / x - 1, GameBox.Height / y - 1
                                                 ));
                    }
                }
            }
            else if (agent is Agent2048)
            {
                Agent2048 a2    = agent as Agent2048;
                Brush     color = Brushes.White;
                for (int i = 0; i < 16; ++i)
                {
                    if (a2.Cells[i] == 0)
                    {
                        color = Brushes.White;
                    }
                    else
                    {
                        color = new SolidBrush(Color.FromArgb(255, 255, 255 - (a2.Cells[i] * 16)));
                    }
                    canvas.FillRectangle(color, new Rectangle(
                                             (i % 4) * GameBox.Width / 4 + 1, (i / 4) * GameBox.Height / 4 + 1, GameBox.Width / 4 - 1, GameBox.Height / 4 - 1
                                             ));
                }
            }

            if (agent.Gameover)
            {
                isPlaying = false;
            }
        }