Beispiel #1
0
        private void button11_Click(object sender, EventArgs e)
        {
            MonteCarlo monteCarlo = new MonteCarlo();

            board.Grains = monteCarlo.InitializeBoard(pictureBox1.Size.Width, pictureBox1.Size.Height, Int32.Parse(textBox7.Text));
            DrawGrains();
        }
Beispiel #2
0
        private void button12_Click(object sender, EventArgs e)
        {
            MonteCarlo monteCarlo = new MonteCarlo();

            while (board.IsNotFull())
            {
                monteCarlo.GrowGrains(width, height, Int32.Parse(textBox8.Text));
                DrawGrains();
            }
        }
Beispiel #3
0
        private void button17_Click(object sender, EventArgs e)
        {
            Random       random     = new Random();
            MonteCarlo   monteCarlo = new MonteCarlo();
            List <Grain> tempGrains = new List <Grain>();

            foreach (Grain grain in board.GrainsInPreviousStep)
            {
                tempGrains.Add(grain);
            }

            for (int i = 0; i < Int32.Parse(textBox14.Text); i++)
            {
                int randIndex = random.Next(board.Grains.Count - 1);
                int x         = board.Grains[randIndex].Position.X;
                int y         = board.Grains[randIndex].Position.Y;

                List <Grain> recrystallizedGrains = Recrystallization.FindRecrystallizedGrains(board, pictureBox1.Size.Width, pictureBox1.Size.Height, x, y);

                while (tempGrains.Count > 0)
                {
                    if (recrystallizedGrains.Count > 0)
                    {
                        int    recrystalizedIndex = random.Next(0, recrystallizedGrains.Count);
                        int    firstEnergy        = monteCarlo.CheckEnergy(tempGrains[randIndex].Position.X, tempGrains[randIndex].Position.Y, pictureBox1.Size.Width, pictureBox1.Size.Height) + tempGrains[randIndex].H;
                        int    secondEnergy       = monteCarlo.CheckEnergy(recrystallizedGrains[recrystalizedIndex].Position.X, recrystallizedGrains[recrystalizedIndex].Position.Y, pictureBox1.Size.Width, pictureBox1.Size.Height);
                        double delta = double.Parse(textBox8.Text) * secondEnergy - firstEnergy;
                        if (delta <= 0)
                        {
                            board.GrainsInPreviousStep[x, y].SetRecrystallized();
                            board.GrainsInPreviousStep[x, y].PenColor = recrystallizedGrains[x].PenColor;
                            board.GrainsInPreviousStep[x, y].H        = 0;
                        }
                    }

                    tempGrains.Remove(tempGrains[randIndex]);
                }

                pictureBox1.Image = board.DrawGrains();
            }
        }