示例#1
0
        public override double Search(bool quiet = false)
        {
            bool draw = false;

            this.p = new BlocksWorldProblem(this.sasProblem);
            return(p.simulate(draw));
        }
示例#2
0
 public BlocksWorldVisualizer(BlocksWorldProblem p = null)
 {
     InitializeComponent();
     this.screen = pictureBox1;
     this.drawer = new BlocksWorldDrawer();
     if (p != null)
     {
         draw(p);
     }
 }
示例#3
0
        protected List <Tower> createTowers(BlocksWorldProblem problem)
        {
            List <Tower> result = new List <Tower>();

            foreach (var item in problem.blocksByIDs.Values.Where(b => b.isOnTable()))
            {
                Tower t          = new Tower(item);
                var   blockAbove = item.currentBlockAbove;
                while (blockAbove != null)
                {
                    t.blocksInTower.Add(blockAbove);
                    blockAbove = blockAbove.currentBlockAbove;
                }
                result.Add(t);
            }
            maxTowers = maxTowers < result.Count ? result.Count : maxTowers;
            return(result);
        }
示例#4
0
        public void draw(PictureBox screen, BlocksWorldProblem problem)
        {
            blockTowers  = createTowers(problem);
            blockSize    = Math.Min(screen.Width / (maxTowers * 2), screen.Height / blockTowers.Max(t => t.blocksInTower.Count));
            screen.Image = new Bitmap(screen.Width, screen.Height);
            g            = Graphics.FromImage(screen.Image);
            g.Clear(Color.WhiteSmoke);

            for (int i = 0; i < blockTowers.Count; i++)
            {
                for (int j = 0; j < blockTowers[i].blocksInTower.Count; j++)
                {
                    Block  b = blockTowers[i].blocksInTower[j];
                    string targetBlockBelow = b.targetBlockBelow != null?b.targetBlockBelow.ID.ToString() : "-1";

                    Brush     brush = b.isCorrect() ? correctBlockBrush : incorrectClockBrush;
                    Rectangle r     = new Rectangle(i * blockSize * 2, j * blockSize, blockSize, blockSize);
                    g.FillRectangle(brush, r);
                    g.DrawRectangle(Pens.Black, r);
                    g.DrawString(b.originalName + "(" + b.ID + ")" + "\n[" + targetBlockBelow + "]", blockDescriptionFont, Brushes.Black, r);
                }
            }
            screen.Refresh();
        }
示例#5
0
 protected override void init()
 {
     this.p = new BlocksWorldProblem(this.sasProblem);
 }
示例#6
0
 public void draw(BlocksWorldProblem p)
 {
     drawer.draw(screen, p);
 }