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(); } } }
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(); }
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(); } } }
public sealed override IOperation Apply() { SymbolicExpressionTree tree = GenotypeToPhenotypeMapperParameter.ActualValue.Map( RandomParameter.ActualValue, BoundsParameter.ActualValue, MaxExpressionLengthParameter.ActualValue.Value, SymbolicExpressionTreeGrammarParameter.ActualValue, IntegerVectorParameter.ActualValue ); SymbolicExpressionTreeParameter.ActualValue = tree; BoolMatrix world = WorldParameter.ActualValue; IntValue maxTimeSteps = MaxTimeStepsParameter.ActualValue; AntInterpreter interpreter = new AntInterpreter(); interpreter.MaxTimeSteps = maxTimeSteps.Value; interpreter.World = world; interpreter.Expression = tree; interpreter.Run(); QualityParameter.ActualValue = new DoubleValue(interpreter.FoodEaten); return(null); }
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(); }