예제 #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();
        }
      }
    }
예제 #2
0
        private void playButton_Click(object sender, EventArgs e)
        {
            playButton.Enabled = false;
            int rows    = Content.World.Rows;
            int columns = Content.World.Columns;
            SymbolicExpressionTree expression = Content.SymbolicExpressionTree;
            var nodeStack = new Stack <SymbolicExpressionTreeNode>();

            animationInterpreter = new AntInterpreter();
            animationInterpreter.MaxTimeSteps = Content.MaxTimeSteps.Value;
            animationInterpreter.Expression   = Content.SymbolicExpressionTree;
            animationInterpreter.World        = Content.World;

            DrawWorld();
            using (Graphics graphics = Graphics.FromImage(pictureBox.Image)) {
                float cellHeight = pictureBox.Height / (float)Content.World.Rows;
                float cellWidth  = pictureBox.Width / (float)Content.World.Columns;
                // draw initial ant
                int currentAntLocationColumn;
                int currentAntLocationRow;
                animationInterpreter.AntLocation(out currentAntLocationRow, out currentAntLocationColumn);
                DrawAnt(graphics, currentAntLocationRow, currentAntLocationColumn, animationInterpreter.AntDirection, cellWidth, cellHeight);
                pictureBox.Refresh();
            }

            animationTimer.Start();
        }
예제 #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();
                }
            }
        }
예제 #4
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;
         }
     }
 }
예제 #5
0
    private void playButton_Click(object sender, EventArgs e) {
      playButton.Enabled = false;
      int rows = Content.World.Rows;
      int columns = Content.World.Columns;
      SymbolicExpressionTree expression = Content.SymbolicExpressionTree;
      var nodeStack = new Stack<SymbolicExpressionTreeNode>();

      animationInterpreter = new AntInterpreter();
      animationInterpreter.MaxTimeSteps = Content.MaxTimeSteps.Value;
      animationInterpreter.Expression = Content.SymbolicExpressionTree;
      animationInterpreter.World = Content.World;

      DrawWorld();
      using (Graphics graphics = Graphics.FromImage(pictureBox.Image)) {
        float cellHeight = pictureBox.Height / (float)Content.World.Rows;
        float cellWidth = pictureBox.Width / (float)Content.World.Columns;
        // draw initial ant
        int currentAntLocationColumn;
        int currentAntLocationRow;
        animationInterpreter.AntLocation(out currentAntLocationRow, out currentAntLocationColumn);
        DrawAnt(graphics, currentAntLocationRow, currentAntLocationColumn, animationInterpreter.AntDirection, cellWidth, cellHeight);
        pictureBox.Refresh();
      }

      animationTimer.Start();
    }