/// <summary> /// We draw the current situation and the desire /// </summary> /// <param name="agent">The agent whose situation and environment we draw</param> private void Draw(BlocksworldAgent agent) { // create bmp image var bmp = new Bitmap(375, 400); // draw on bmp image using (var graphics = Graphics.FromImage(bmp)) { graphics.Clear(Color.White); DrawStacks(agent.Environment.Table.GetStacks(), graphics); if (agent.InArm != null) { var myBrush = new SolidBrush(agent.InArm.Color); var rectangle = new Rectangle(162, 0, 50, 50); graphics.FillRectangle(myBrush, rectangle); } } _pictureBox1.Image = bmp; // create bmp image var bmp2 = new Bitmap(375, 400); // draw on bmp image using (var graphics = Graphics.FromImage(bmp2)) { graphics.Clear(Color.White); if (agent.CurrentIntentions != null) { var cBDesire = (ConfigureBlocksDesire)agent.CurrentIntentions.First().Desire; DrawStacks(cBDesire.Target.GetStacks(), graphics); } } _pictureBox2.Image = bmp2; }
/// <summary> /// We initialize the agent and draw every second the situation /// </summary> private void Start() { //we create an environment and add an agent to that environment var environment = new BlocksworldEnvironment(); var agent = new BlocksworldAgent(environment, CommitmentType.Blind); //we create an achievable desire (a new configuration of the blocks) and initialize the agent with this desire var target = new Table(); var yellow = new Block(Color.Yellow, target); var green = new Block(Color.Green, yellow); var red = new Block(Color.Red, green); new Block(Color.Black, red); var configureDesire1 = new ConfigureBlocksDesire(target, 1); agent.Init(new List <Desire <BlocksworldAction, BlocksworldAgent, BlocksworldEnvironment> > { configureDesire1 }, null); Draw(agent); while (true) { Thread.Sleep(1000); Draw(agent); } }