Beispiel #1
0
 public void DrawRace(Policy p, RaceViewer form)
 {
     form.StateValues = null;
     form.Start();
     //form.ShowDialog();
     while (form.Active)
     {
         Thread.Sleep(100);
         RaceCarState   s = (RaceCarState)StartState;
         VelocityAction a = null;
         while (form.Active && !IsGoalState(s))
         {
             a = (VelocityAction)p.GetAction(s);
             if (a == null)
             {
                 break;
             }
             form.CarState = s;
             //form.Invoke(form.RefreshForm);
             //form.SetCarState(s);
             Thread.Sleep(100);
             RaceCarState sTag = (RaceCarState)s.Apply(a);
             s = sTag;
         }
     }
 }
Beispiel #2
0
        public override State Apply(Action a)
        {
            RaceCarState sTag = new RaceCarState(this);

            sTag.Apply((VelocityAction)a, RandomGenerator.NextDouble() < RaceTrack.ACTION_SUCCESS_PROBABILITY);
            return(sTag);
        }
Beispiel #3
0
        public override IEnumerable <State> Successors(Action a)
        {
            RaceCarState sTagNoApply = new RaceCarState(this);
            RaceCarState sTagApply   = new RaceCarState(this);

            sTagApply.Apply((VelocityAction)a, true);
            sTagNoApply.Apply((VelocityAction)a, false);
            yield return(sTagApply);

            yield return(sTagNoApply);
        }
 public bool Equals(RaceCarState s)
 {
     if (s.X != X)
         return false;
     if (s.Y != Y)
         return false;
     if (s.m_iXVelocity != m_iXVelocity)
         return false;
     if (s.m_iYVelocity != m_iYVelocity)
         return false;
     return true;
 }
 internal RaceViewer(RaceTrack rt)
 {
     InitializeComponent();
     m_rtTrack = rt;
     Size = new Size(m_rtTrack.Width * SCALE + 50, 100 + m_rtTrack.Height * SCALE);
     TrackPictureBox.Size = new Size(m_rtTrack.Width * SCALE, m_rtTrack.Height * SCALE);
     RefreshForm = new RefreshDelegate(RefreshFormMethod);
     HideForm = new HideDelegate(HideFormMethod);
     CarState = null;
     StateValues = null;
     SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint, true);
     Active = false;
     m_bThreadRunning = false;
     CurretnUpdateState = null;
 }
Beispiel #6
0
 internal RaceViewer(RaceTrack rt)
 {
     InitializeComponent();
     m_rtTrack            = rt;
     Size                 = new Size(m_rtTrack.Width * SCALE + 50, 100 + m_rtTrack.Height * SCALE);
     TrackPictureBox.Size = new Size(m_rtTrack.Width * SCALE, m_rtTrack.Height * SCALE);
     RefreshForm          = new RefreshDelegate(RefreshFormMethod);
     HideForm             = new HideDelegate(HideFormMethod);
     CarState             = null;
     StateValues          = null;
     SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint, true);
     Active             = false;
     m_bThreadRunning   = false;
     CurretnUpdateState = null;
 }
Beispiel #7
0
        public override double TransitionProbability(Action a, State sTag)
        {
            RaceCarState sTagApply = new RaceCarState(this);

            sTagApply.Apply((VelocityAction)a, true);
            if (sTag.Equals(sTagApply))
            {
                return(RaceTrack.ACTION_SUCCESS_PROBABILITY);
            }
            RaceCarState sTagNoApply = new RaceCarState(this);

            sTagNoApply.Apply((VelocityAction)a, false);
            if (sTag.Equals(sTagNoApply))
            {
                return(1 - RaceTrack.ACTION_SUCCESS_PROBABILITY);
            }
            return(0.0);
        }
Beispiel #8
0
 public bool Equals(RaceCarState s)
 {
     if (s.X != X)
     {
         return(false);
     }
     if (s.Y != Y)
     {
         return(false);
     }
     if (s.m_iXVelocity != m_iXVelocity)
     {
         return(false);
     }
     if (s.m_iYVelocity != m_iYVelocity)
     {
         return(false);
     }
     return(true);
 }
Beispiel #9
0
        public override double Reward(Action a)
        {
            if (m_rtTrack.IsRaceEnd(this))
            {
                return(m_rtTrack.MaxReward);
            }
            if (m_rtTrack.IsGoalState(this))
            {
                return(0.0);
            }
            RaceCarState sTagApply    = new RaceCarState(this);
            bool         bNoCollision = sTagApply.Apply((VelocityAction)a, true);

            if (bNoCollision)
            {
                return(-0.01);
            }
            else
            {
                return(-sTagApply.Velocity);
            }
        }
 public bool IsGoalState(RaceCarState s)
 {
     return s.X == -1 && s.Y == -1;
 }
 public override State Apply(Action a)
 {
     RaceCarState sTag = new RaceCarState(this);
     sTag.Apply((VelocityAction)a, RandomGenerator.NextDouble() < RaceTrack.ACTION_SUCCESS_PROBABILITY);
     return sTag;
 }
 public RaceCarState(RaceCarState s)
     : this(s.X, s.Y, s.m_iXVelocity, s.m_iYVelocity, s.m_rtTrack)
 {
 }
 public override double TransitionProbability(Action a, State sTag)
 {
     RaceCarState sTagApply = new RaceCarState(this);
     sTagApply.Apply((VelocityAction)a, true);
     if (sTag.Equals(sTagApply))
         return RaceTrack.ACTION_SUCCESS_PROBABILITY;
     RaceCarState sTagNoApply = new RaceCarState(this);
     sTagNoApply.Apply((VelocityAction)a, false);
     if (sTag.Equals(sTagNoApply))
         return 1 - RaceTrack.ACTION_SUCCESS_PROBABILITY;
     return 0.0;
 }
 public bool IsRaceStart(RaceCarState s)
 {
     return s.X == m_iStartX && s.Y == m_iStartY;
 }
Beispiel #15
0
 public bool IsGoalState(RaceCarState s)
 {
     return(s.X == -1 && s.Y == -1);
 }
Beispiel #16
0
 public bool IsRaceEnd(RaceCarState s)
 {
     return(s.X == m_iEndX && s.Y == m_iEndY);
 }
Beispiel #17
0
 public bool IsRaceStart(RaceCarState s)
 {
     return(s.X == m_iStartX && s.Y == m_iStartY);
 }
Beispiel #18
0
 public RaceCarState(RaceCarState s)
     : this(s.X, s.Y, s.m_iXVelocity, s.m_iYVelocity, s.m_rtTrack)
 {
 }
 public override double Reward(Action a)
 {
     if (m_rtTrack.IsRaceEnd(this))
         return m_rtTrack.MaxReward;
     if (m_rtTrack.IsGoalState(this))
         return 0.0;
     RaceCarState sTagApply = new RaceCarState(this);
     bool bNoCollision = sTagApply.Apply((VelocityAction)a, true);
     if (bNoCollision)
         return -0.01;
     else
         return -sTagApply.Velocity;
 }
 public override IEnumerable<State> Successors(Action a)
 {
     RaceCarState sTagNoApply = new RaceCarState(this);
     RaceCarState sTagApply = new RaceCarState(this);
     sTagApply.Apply((VelocityAction)a, true);
     sTagNoApply.Apply((VelocityAction)a, false);
     yield return sTagApply;
     yield return sTagNoApply;
 }
 public bool IsRaceEnd(RaceCarState s)
 {
     return s.X == m_iEndX && s.Y == m_iEndY;
 }