Exemple #1
0
 /// <summary>
 /// This method calls nextGeneration method and
 /// updates the GUI and the count of our alive cells
 /// </summary>
 private void step()
 {
     matrix = nextGeneration(matrix);
     updateTextGeneration();
     countOnes();
     PBAutomataSimulator.Invalidate();
 }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            int    pos = 0;
            Random ra  = new Random();

            for (int x = 0; x < matrix.GetLength(0); x++)
            {
                for (int y = 0; y < matrix.GetLength(1); y++)
                {
                    //Probability of put an ant
                    int    integer_rand = ra.Next(0, 99);
                    double rand         = (ra.NextDouble()) + integer_rand;
                    if (rand < float.Parse(numericOnes.Text))
                    {
                        ANT ant_obj = new ANT(x, y, Helper.generateOrientation(),
                                              Helper.generateType((int)NumericQueen.Value,
                                                                  (int)NumericMale.Value),
                                              (int)NumericTTL.Value);
                        ant_obj.setColor(colors.randomColor());
                        ants.Add(ant_obj);
                    }
                    else
                    {
                        matrix[x, y] = DEAD;
                    }
                }
            }
            PBAutomataSimulator.Invalidate();
        }
Exemple #3
0
 private void CBDead_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (CBDead.Text == colors[0])
     {
         dead = Brushes.White;
     }
     else if (CBDead.Text == colors[1])
     {
         dead = Brushes.Black;
     }
     else if (CBDead.Text == colors[2])
     {
         dead = Brushes.Red;
     }
     else if (CBDead.Text == colors[3])
     {
         dead = Brushes.Blue;
     }
     else if (CBDead.Text == colors[4])
     {
         dead = Brushes.Green;
     }
     else if (CBDead.Text == colors[5])
     {
         dead = Brushes.Yellow;
     }
     else if (CBDead.Text == colors[6])
     {
         dead = Brushes.Violet;
     }
     PBAutomataSimulator.Invalidate();
 }
Exemple #4
0
        private void PBAutomataSimulator_MouseMove(object sender, MouseEventArgs e)
        {
            try
            {
                if (move && index_pattern != 0)
                {
                    int x = e.X / cellArea;
                    int y = e.Y / cellArea;

                    uint[,] draw_figure = figure[index_pattern];
                    int x_size = (draw_figure).GetLength(1);
                    int y_size = (draw_figure).GetLength(0);
                    initMosaics();
                    for (int x_c = 0; x_c < x_size; x_c++)
                    {
                        for (int y_c = 0; y_c < y_size; y_c++)
                        {
                            matrix[x_c + x, y_c + y] = draw_figure[y_c, x_c];
                        }
                    }
                    PBAutomataSimulator.Invalidate();
                    move          = false;
                    index_pattern = 0;
                }
            }
            catch (Exception) {
            }
        }
Exemple #5
0
        private void PBAutomataSimulator_MouseDown(object sender, MouseEventArgs e)
        {
            int x = e.X / cellArea;
            int y = e.Y / cellArea;

            matrix[x, y] = !matrix[x, y];
            PBAutomataSimulator.Invalidate();
        }
Exemple #6
0
 private void BTNZoomM_Click(object sender, EventArgs e)
 {
     if (cellArea > 1)
     {
         cellArea--;
         PBAutomataSimulator.Invalidate();
         scrollBox();
     }
 }
Exemple #7
0
        private void button2_Click_1(object sender, EventArgs e)
        {
            Color color = getColor();

            alive = new SolidBrush(color);
            ALIVE = ColorHandler.fromColorToInt(color);
            initMosaics();
            PBAutomataSimulator.Invalidate();
        }
Exemple #8
0
 private void BTNClear_Click(object sender, EventArgs e)
 {
     for (int x = 0; x < matrix.GetLength(0); x++)
     {
         for (int y = 0; y < matrix.GetLength(1); y++)
         {
             matrix[x, y] = false;
         }
     }
     PBAutomataSimulator.Invalidate();
 }
Exemple #9
0
 private void BTNClear_Click(object sender, EventArgs e)
 {
     CHHistogram.Series["#Ones"].Points.Clear();
     for (int x = 0; x < matrix.GetLength(0); x++)
     {
         for (int y = 0; y < matrix.GetLength(1); y++)
         {
             matrix[x, y] = false;
         }
     }
     PBAutomataSimulator.Invalidate();
     acumOnes = generation = 0;
 }
Exemple #10
0
 /// <summary>
 /// This method calls nextGeneration method and
 /// updates the GUI and the count of our alive cells
 /// </summary>
 private void step()
 {
     matrix = nextGeneration(matrix);
     updateTextGeneration();
     countOnes();
     if (Helper.getSpaceType(comboSpace.Text) == Helper.NORMAL)
     {
         PBAutomataSimulator.Invalidate();
     }
     else
     {
         PBAutomataSimulator.Invalidate();
     }
 }
Exemple #11
0
        private void PBAutomataSimulator_Click(object sender, EventArgs e)
        {
            MouseEventArgs me = (MouseEventArgs)e;
            int            x  = (me.X / cellArea);
            int            y  = (me.Y / cellArea);

            if (me.Button == System.Windows.Forms.MouseButtons.Right)
            {
                foreach (ANT ant_obj in ants)
                {
                    if (ant_obj.getX() == x && ant_obj.getY() == y)
                    {
                        ant_obj.setColor(getColor());
                        break;
                    }
                }
            }
            else
            {
                bool   can_put_ant = true;
                int    i = 0, j = 0;
                Random rnd = new Random();
                for (i = 0; i < ants.Count; i++)
                {
                    ANT ant_obj = ants[i];
                    if (ant_obj.getX() == x && ant_obj.getY() == y)
                    {
                        can_put_ant = false;
                        j           = i;
                        break;
                    }
                }

                //Add a new ant
                if (can_put_ant)
                {
                    ants.Add(new ANT(x, y, Helper.getOrientationValue(ComboOrientation.Text),
                                     Helper.getTypeValue(ComboType.Text), (int)NumericTTL.Value));
                }
                else
                {
                    ants.RemoveAt(j);
                }
            }
            PBAutomataSimulator.Invalidate();
        }
Exemple #12
0
        private void BTNClear_Click(object sender, EventArgs e)
        {
            CHHistogram.Series["#Ones"].Points.Clear();
            for (int x = 0; x < matrix.GetLength(0); x++)
            {
                for (int y = 0; y < matrix.GetLength(1); y++)
                {
                    matrix[x, y]       = DEAD;
                    second_space[x, y] = DEAD;
                }
            }
            TAO = (int)NumericGenMem.Value;
            PBAutomataSimulator.Invalidate();

            acumOnes = generation = 0;
            for (int i = 0; i < patterns.Count; i++)
            {
                patterns[i].Clear();
            }
        }
Exemple #13
0
        private void button1_Click(object sender, EventArgs e)
        {
            Random r = new Random();

            for (int x = 0; x < matrix.GetLength(0); x++)
            {
                for (int y = 0; y < matrix.GetLength(1); y++)
                {
                    float rand = r.Next(0, 100);
                    if (rand < int.Parse(numericOnes.Text))
                    {
                        matrix[x, y] = true;
                    }
                    else
                    {
                        matrix[x, y] = false;
                    }
                }
            }
            PBAutomataSimulator.Invalidate();
        }
Exemple #14
0
        /// <summary>
        /// This method calls nextGeneration method and
        /// updates the GUI and the count of our alive cells
        /// </summary>
        private void step()
        {
            List <ANT> aux = new List <ANT>(ants);

            for (int i = 0; i < ants.Count; i++)
            {
                ANT ant_obj = ants[i];
                if (ant_obj.getType() == Helper.QUEEN)
                {
                    aux = QueenActions(i);
                }
                matrix = ant_obj.nextGeneration(matrix, CBToroid.Checked);
                PBAutomataSimulator.Invalidate();
            }
            ants = new List <ANT>(aux);
            updateTextGeneration();
            countOnes();
            if (ants.Count == 0)
            {
                PBAutomataSimulator.Invalidate();
            }
        }
Exemple #15
0
 private void BTNColorDead_Click(object sender, EventArgs e)
 {
     dead = new SolidBrush(getColor());
     PBAutomataSimulator.Invalidate();
 }
Exemple #16
0
 private void BTNDeadCells_Click(object sender, EventArgs e)
 {
     dead = new SolidBrush(getColor());
     initMosaics();
     PBAutomataSimulator.Invalidate();
 }
Exemple #17
0
        /*****************************************************
        *                      Events                       *
        *****************************************************/

        private void BTNStep_Click(object sender, EventArgs e)
        {
            PBAutomataSimulator.Invalidate();
            step();
        }
Exemple #18
0
 private void BTNColorGrid_Click(object sender, EventArgs e)
 {
     grid = new Pen(getColor());
     PBAutomataSimulator.Invalidate();
 }
Exemple #19
0
        private void button2_Click(object sender, EventArgs e)
        {
            int    min_lines = 0;
            int    min_chara = 0;
            String fileName  = null;

            try
            {
                using (OpenFileDialog openFileDialog = new OpenFileDialog())
                {
                    openFileDialog.InitialDirectory = "c\\";
                    openFileDialog.Filter           = "txt files (*.txt)|*.txt";
                    openFileDialog.FilterIndex      = 2;
                    if (openFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        fileName = openFileDialog.FileName;
                    }
                }

                if (fileName != null)
                {
                    Console.WriteLine(fileName);
                    StreamReader objectReader = new StreamReader(fileName);
                    //Reading the file, line per line
                    String    line      = "";
                    ArrayList arrayText = new ArrayList();
                    while (line != null)
                    {
                        line = objectReader.ReadLine();
                        if (line != null)
                        {
                            arrayText.Add(line);
                        }
                    }
                    objectReader.Close();
                    //Iterate into the ArrayList and send the information to the GUI
                    min_lines = arrayText.Count;
                    min_chara = arrayText[0].ToString().Length;

                    Console.WriteLine(min_chara);
                    Console.WriteLine(min_lines);
                    if (min_chara > matrix.GetLength(1) && min_lines > matrix.GetLength(0))
                    {
                        createMatrix(min_chara, min_lines);
                    }
                    for (int i = 0; i < min_lines; i++)
                    {
                        string strlne = arrayText[i].ToString().Trim();
                        int    j      = 0;

                        foreach (char c in strlne)
                        {
                            matrix[j++, i] = (c == '1');
                        }
                    }
                    Console.ReadLine();
                }
            }
            catch (Exception ex) {
                Console.WriteLine(ex);
            }
            PBAutomataSimulator.Invalidate();
        }
Exemple #20
0
 private void BTNColorQueen_Click(object sender, EventArgs e)
 {
     ant_queen = new SolidBrush(getColor());
     PBAutomataSimulator.Invalidate();
 }