Ejemplo n.º 1
0
        private void GenerateImage()
        {
            animationTimer.Stop();
            pictureBox.Image = null;
            if ((pictureBox.Width > 0) && (pictureBox.Height > 0))
            {
                if (Content != null)
                {
                    var nodeStack = new Stack <SymbolicExpressionTreeNode>();
                    int rows      = Content.World.Rows;
                    int columns   = Content.World.Columns;
                    SymbolicExpressionTree expression = Content.SymbolicExpressionTree;

                    DrawWorld();
                    using (Graphics graphics = Graphics.FromImage(pictureBox.Image)) {
                        float cellHeight = pictureBox.Height / (float)rows;
                        float cellWidth  = pictureBox.Width / (float)columns;

                        AntInterpreter interpreter = new AntInterpreter();
                        interpreter.MaxTimeSteps = Content.MaxTimeSteps.Value;
                        interpreter.Expression   = Content.SymbolicExpressionTree;
                        interpreter.World        = Content.World;
                        int currentAntLocationColumn;
                        int currentAntLocationRow;
                        // draw initial ant
                        interpreter.AntLocation(out currentAntLocationRow, out currentAntLocationColumn);
                        DrawAnt(graphics, currentAntLocationRow, currentAntLocationColumn, interpreter.AntDirection, cellWidth, cellHeight);
                        // interpret ant code and draw trail
                        while (interpreter.ElapsedTime < interpreter.MaxTimeSteps)
                        {
                            interpreter.Step();
                            interpreter.AntLocation(out currentAntLocationRow, out currentAntLocationColumn);
                            DrawAnt(graphics, currentAntLocationRow, currentAntLocationColumn, interpreter.AntDirection, cellWidth, cellHeight);
                        }
                    }
                    pictureBox.Refresh();
                }
            }
        }
Ejemplo n.º 2
0
 private void animationTimer_Tick(object sender, EventArgs e)
 {
     using (Graphics graphics = Graphics.FromImage(pictureBox.Image)) {
         float cellHeight = pictureBox.Height / (float)Content.World.Rows;
         float cellWidth  = pictureBox.Width / (float)Content.World.Columns;
         int   currentAntLocationColumn;
         int   currentAntLocationRow;
         // interpret ant code and draw trail
         animationInterpreter.Step();
         animationInterpreter.AntLocation(out currentAntLocationRow, out currentAntLocationColumn);
         DrawAnt(graphics, currentAntLocationRow, currentAntLocationColumn, animationInterpreter.AntDirection, cellWidth, cellHeight);
         pictureBox.Refresh();
         if (animationInterpreter.ElapsedTime < animationInterpreter.MaxTimeSteps)
         {
             animationTimer.Start();
         }
         else
         {
             animationTimer.Stop();
             playButton.Enabled = true;
         }
     }
 }
Ejemplo n.º 3
0
    private void GenerateImage() {
      animationTimer.Stop();
      pictureBox.Image = null;
      if ((pictureBox.Width > 0) && (pictureBox.Height > 0)) {
        if (Content != null) {
          var nodeStack = new Stack<SymbolicExpressionTreeNode>();
          int rows = Content.World.Rows;
          int columns = Content.World.Columns;
          SymbolicExpressionTree expression = Content.SymbolicExpressionTree;

          DrawWorld();
          using (Graphics graphics = Graphics.FromImage(pictureBox.Image)) {
            float cellHeight = pictureBox.Height / (float)rows;
            float cellWidth = pictureBox.Width / (float)columns;

            AntInterpreter interpreter = new AntInterpreter();
            interpreter.MaxTimeSteps = Content.MaxTimeSteps.Value;
            interpreter.Expression = Content.SymbolicExpressionTree;
            interpreter.World = Content.World;
            int currentAntLocationColumn;
            int currentAntLocationRow;
            // draw initial ant
            interpreter.AntLocation(out currentAntLocationRow, out currentAntLocationColumn);
            DrawAnt(graphics, currentAntLocationRow, currentAntLocationColumn, interpreter.AntDirection, cellWidth, cellHeight);
            // interpret ant code and draw trail
            while (interpreter.ElapsedTime < interpreter.MaxTimeSteps) {
              interpreter.Step();
              interpreter.AntLocation(out currentAntLocationRow, out currentAntLocationColumn);
              DrawAnt(graphics, currentAntLocationRow, currentAntLocationColumn, interpreter.AntDirection, cellWidth, cellHeight);
            }
          }
          pictureBox.Refresh();
        }
      }
    }