Exemplo n.º 1
0
        public void Divide()
        {
            Point p   = ComExec.PointFromDir(this, (Direction)ComExec.FindEmptyDir(this));
            Bot   bot = new Bot(p);

            bot.Genotype = this.Genotype;
            bot.Gptr     = (new Random()).Next(63);
            bot.RefreshImage();

            MainItems.botstoadd.Add(bot);
        }
Exemplo n.º 2
0
        private void CustomSpawnB_Click(object sender, EventArgs e)
        {
            int   x     = Convert.ToUInt16(textBox4.Text);
            int   y     = Convert.ToUInt16(textBox5.Text);
            Point point = new Point(x, y);
            Bot   bot   = new Bot(point);

            bot.RefreshImage();
            ComExec.CreateOriginator(ref bot);
            MainItems.bots.Add(bot);
            pictureBox1.Image = MainItems.MainPolygon;
        }
Exemplo n.º 3
0
        private void button2_Click(object sender, EventArgs e)
        {
            Random rand1 = new Random();
            Random rand2 = new Random();

            //  Point spawn = new Point(rand1.Next(Bot.size,MainItems.MainPolygon.Width-Bot.size), rand2.Next(Bot.size, MainItems.MainPolygon.Height - Bot.size));
            Point spawn = new Point((new Random()).Next() % MainItems.MainPolygon.Width, (new Random()).Next() % MainItems.MainPolygon.Height);
            ////   point.Y += Bot.size;
            ////   point.X += Bot.size;
            //   //Point spawn = new Point(300, 300);
            Bot bot = new Bot(spawn);

            bot.RefreshImage();
            ComExec.CreateOriginator(ref bot);
            MainItems.bots.Add(bot);
            pictureBox1.Image = MainItems.MainPolygon;
        }
Exemplo n.º 4
0
        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            Bot pickedbot = null;

            foreach (var bot in MainItems.bots)
            {
                int rxl = bot.Position.X - e.X;
                int rxr = e.X - bot.Position.X;
                int ryu = e.Y - bot.Position.Y;
                int ryd = bot.Position.Y - e.Y;
                if//(((rxl >= 0 && rxl < Bot.size+2) ||(rxr >= 0 && rxr < Bot.size + 2))       )//||
                (((ryu >= 0 && ryu < Bot.size + 2) || (ryd >= 0 && ryd < Bot.size + 2)))
                {
                    pickedbot = bot;
                    break;
                }
            }
            if (pickedbot != null)
            {
                Bot nearestBot = null;
                for (int i = 0; i < 8; i++)
                {
                    nearestBot = ComExec.IsBotOnDirection(pickedbot, (Direction)(i));
                    if (nearestBot != null)
                    {
                        break;
                    }
                }
                if (nearestBot != null)
                {
                    textBox2.Text = $"Position {pickedbot.Position.X}:{pickedbot.Position.Y}; ID:{pickedbot.ID};Nearest bot:{nearestBot.ID}";
                }
                else
                {
                    textBox2.Text = $"Position {pickedbot.Position.X}:{pickedbot.Position.Y}; ID:{pickedbot.ID};Energy:{pickedbot.Energy};Gptr:{pickedbot.Gptr}";
                }
            }
            else
            {
                textBox2.Text = "Pick the bot";
            }
            pickedbot = null;
        }
Exemplo n.º 5
0
 public void GiveFree()
 {
     for (int i = 0; i < 8; i++)
     {
         Bot tmp = ComExec.IsBotOnDirection(this, (Direction)i);
         if (tmp != null)
         {
             foreach (var bot in MainItems.bots)
             {
                 if (tmp.ID == bot.ID)
                 {
                     bot.Energy  += (this.Energy / 4);
                     this.Energy /= 4;
                     break;
                 }
             }
             break;
         }
     }
 }
Exemplo n.º 6
0
        public void Multi()
        {
            Bot prev = this.previous;
            Bot nxt  = this.next;

            if (ComExec.isMulti(prev) > 0 && ComExec.isMulti(nxt) > 0)
            {
                return;
            }
            this.Energy -= 150;
            if (this.Energy <= 0)
            {
                this.Die();
                return;
            }
            int n = ComExec.FindEmptyDir(this);

            if (n == -1)
            {
                this.Die();
                return;
            }
            Bot newbot = new Bot(ComExec.PointFromDir(this, (Direction)n));

            newbot.Genotype = this.genom;
            int imo = (new Random()).Next(0, 5);

            if (imo == 3)
            {
                newbot.Genotype[(new Random()).Next() % 63] = (new Random()).Next() % 64;
            }
            newbot.Energy   = this.Energy / 2;
            newbot.BotColor = this.color;
            this.next       = newbot;
            newbot.previous = this;
            MainItems.botstoadd.Add(newbot);
            newbot.Napruamok = (Direction)((new Random()).Next() % 8);
        }
Exemplo n.º 7
0
        public void DoubleBot()
        {
            this.Energy -= 150;
            if (this.Energy <= 0)
            {
                this.Die();
            }
            else
            {
                int   dirfromorigin = ComExec.FindEmptyDir(this);
                Point pos           = new Point();
                if (dirfromorigin != -1)
                {
                    switch (dirfromorigin)
                    {
                    case 0:
                    {
                        pos = ComExec.PointFromDir(this, Direction.Up);
                        break;
                    }

                    case 1:
                    {
                        pos = ComExec.PointFromDir(this, Direction.UpRight);
                        break;
                    }

                    case 2:
                    {
                        pos = ComExec.PointFromDir(this, Direction.Right);
                        break;
                    }

                    case 3:
                    {
                        pos = ComExec.PointFromDir(this, Direction.RightDown);
                        break;
                    }

                    case 4:
                    {
                        pos = ComExec.PointFromDir(this, Direction.Down);
                        break;
                    }

                    case 5:
                    {
                        pos = ComExec.PointFromDir(this, Direction.LeftDown);
                        break;
                    }

                    case 6:
                    {
                        pos = ComExec.PointFromDir(this, Direction.Left);
                        break;
                    }

                    case 7:
                    {
                        pos = ComExec.PointFromDir(this, Direction.LeftUp);
                        break;
                    }
                    }
                }
                else
                {
                    this.Die();
                    return;
                }
                Bot newbot = new Bot(pos);
                newbot.RefreshImage();;
                newbot.Genotype = this.genom;
                int imo = (new Random()).Next(0, 5);
                if (imo == 3)
                {
                    newbot.Genotype[(new Random()).Next() % 63] = (new Random()).Next() % 64;
                }
                newbot.Energy   = this.Energy / 2;
                newbot.BotColor = this.color;
                this.next       = newbot;
                newbot.previous = this;
                MainItems.botstoadd.Add(newbot);
            }
        }