public override double TransitionProbability(Action a, State sTag) { MazeAction ma = (MazeAction)a; if (m_mdMaze.IsTargetSqaure(this) && ma.Name == "Forward") { if (m_mdMaze.IsGoalState(sTag)) { return(1.0); } return(0.0); } double dProb = 0.0; if (sTag.Equals(this)) { dProb += 1 - ActionSuccessProbability; } MazeState s = Apply(ma, true); if (s.Equals(sTag)) { dProb += ActionSuccessProbability; } return(dProb); }
internal MazeViewer(MazeDomain maze) { InitializeComponent(); m_mdMaze = maze; Size = new Size(m_mdMaze.Width * SCALE + 50, 100 + (m_mdMaze.Height + 3) * SCALE); MazePictureBox.Size = new Size(m_mdMaze.Width * SCALE, (m_mdMaze.Height + 3) * SCALE); RefreshForm = new RefreshDelegate(RefreshFormMethod); HideForm = new HideDelegate(HideFormMethod); CurrentState = null; SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint, true); Active = false; m_bThreadRunning = false; CurretnUpdateState = null; }
public MazeObservation GetWallConfiguration(MazeState s) { MazeState.Direction d = s.CurrentDirection; int iObservation = 0; int iDirection = 0; for (iDirection = 0; iDirection < 4; iDirection++) { iObservation *= 2; if (WallInDirection(s.X, s.Y, d)) { iObservation++; } d = s.TurnRight(d); } return(new MazeObservation(iObservation)); }
public override IEnumerable <State> Successors(Action a) { MazeAction ma = (MazeAction)a; if (m_mdMaze.IsTargetSqaure(this) && ma.Name == "Forward") { yield return(new MazeState(-1, -1, Direction.North, m_mdMaze)); } else { yield return(this); MazeState sTag = Apply(ma, true); if (sTag != this) { yield return(sTag); } } }
public override bool IsGoalState(State s) { MazeState ms = (MazeState)s; return(ms.X == -1 && ms.Y == -1); }
public bool IsTargetSqaure(MazeState ms) { return(ms.X == m_iGoalSquareX && ms.Y == m_iGoalSquareY); }
public override bool Equals(object obj) { MazeState s = (MazeState)obj; return(s.X == X && s.Y == Y && s.CurrentDirection == CurrentDirection); }
private void DrawTrial(Graphics g) { Pen pThin = new Pen(Color.Black, 2); Pen pThick = new Pen(Color.Black, 5); int iX = 0, iY = 0; int iStartX = 0, iStartY = 0; int iEndX = iStartX, iEndY = iStartY; //g.FillRegion(Brushes.Gray, MazePictureBox.Region); for (iX = 0; iX < m_mdMaze.Width; iX++) { for (iY = 0; iY < m_mdMaze.Height; iY++) { if (!m_mdMaze.BlockedSquare(iX, iY)) { if (m_mdMaze.IsTargetSqaure(iX, iY)) { g.FillRectangle(Brushes.Green, iX * SCALE, iY * SCALE, SCALE, SCALE); } else { g.FillRectangle(Brushes.White, iX * SCALE, iY * SCALE, SCALE, SCALE); } g.DrawRectangle(pThin, iX * SCALE, iY * SCALE, SCALE, SCALE); } } } g.FillEllipse(Brushes.Yellow, CurrentState.X * SCALE + 2, CurrentState.Y * SCALE + 2, SCALE - 4, SCALE - 4); foreach (KeyValuePair <State, double> pair in CurrentBelief.Beliefs(0.01)) { MazeState ms = (MazeState)pair.Key; Pen p1 = new Pen(Color.Blue, (float)Math.Max(1, 20 * pair.Value)); iStartX = (int)((ms.X + 0.5) * SCALE); iStartY = (int)((ms.Y + 0.5) * SCALE); iEndX = iStartX; iEndY = iStartY; if (ms.CurrentDirection == MazeState.Direction.North) { iEndY -= SCALE / 2; } if (ms.CurrentDirection == MazeState.Direction.South) { iEndY += SCALE / 2; } if (ms.CurrentDirection == MazeState.Direction.East) { iEndX += SCALE / 2; } if (ms.CurrentDirection == MazeState.Direction.West) { iEndX -= SCALE / 2; } g.DrawLine(p1, iStartX, iStartY, iEndX, iEndY); } if (CurrentState != null) { iStartX = (int)((CurrentState.X + 0.5) * SCALE); iStartY = (int)((CurrentState.Y + 0.5) * SCALE); iEndX = iStartX; iEndY = iStartY; if (CurrentState.CurrentDirection == MazeState.Direction.North) { iEndY -= SCALE / 2; } if (CurrentState.CurrentDirection == MazeState.Direction.South) { iEndY += SCALE / 2; } if (CurrentState.CurrentDirection == MazeState.Direction.East) { iEndX += SCALE / 2; } if (CurrentState.CurrentDirection == MazeState.Direction.West) { iEndX -= SCALE / 2; } g.DrawLine(pThick, iStartX, iStartY, iEndX, iEndY); } Text = CurrentState.ToString(); if (CurrentObservation.FrontWall) { iStartX = 0; iStartY = (m_mdMaze.Height + 1) * SCALE; iEndX = SCALE; iEndY = iStartY; g.DrawLine(pThick, iStartX, iStartY, iEndX, iEndY); } if (CurrentObservation.RightWall) { iStartX = SCALE; iStartY = (m_mdMaze.Height + 1) * SCALE; iEndX = iStartX; iEndY = iStartY + SCALE; g.DrawLine(pThick, iStartX, iStartY, iEndX, iEndY); } if (CurrentObservation.BackWall) { iStartX = 0; iStartY = (m_mdMaze.Height + 2) * SCALE; iEndX = SCALE; iEndY = iStartY; g.DrawLine(pThick, iStartX, iStartY, iEndX, iEndY); } if (CurrentObservation.LeftWall) { iStartX = 0; iStartY = (m_mdMaze.Height + 1) * SCALE; iEndX = 0; iEndY = iStartY + SCALE; g.DrawLine(pThick, iStartX, iStartY, iEndX, iEndY); } }