private bool Apply(VelocityAction a, bool bApply) { if (bApply) { m_iXVelocity += a.XIncrease; if (m_iXVelocity > RaceTrack.MAX_VELOCITY) { m_iXVelocity = RaceTrack.MAX_VELOCITY; } if (-m_iXVelocity > RaceTrack.MAX_VELOCITY) { m_iXVelocity = -RaceTrack.MAX_VELOCITY; } m_iYVelocity += a.YIncrease; if (m_iYVelocity > RaceTrack.MAX_VELOCITY) { m_iYVelocity = RaceTrack.MAX_VELOCITY; } if (-m_iYVelocity > RaceTrack.MAX_VELOCITY) { m_iYVelocity = -RaceTrack.MAX_VELOCITY; } } int iFinalX, iFinalY; bool bNoCollision = m_rtTrack.Move(X, Y, m_iXVelocity, m_iYVelocity, out iFinalX, out iFinalY); X = iFinalX; Y = iFinalY; return(bNoCollision); }
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; } } }
public override bool Equals(object obj) { if (obj is VelocityAction) { VelocityAction va = (VelocityAction)obj; return(va.XIncrease == XIncrease && va.YIncrease == YIncrease); } return(false); }
private bool Apply(VelocityAction a, bool bApply) { if (bApply) { m_iXVelocity += a.XIncrease; if (m_iXVelocity > RaceTrack.MAX_VELOCITY) m_iXVelocity = RaceTrack.MAX_VELOCITY; if (-m_iXVelocity > RaceTrack.MAX_VELOCITY) m_iXVelocity = -RaceTrack.MAX_VELOCITY; m_iYVelocity += a.YIncrease; if (m_iYVelocity > RaceTrack.MAX_VELOCITY) m_iYVelocity = RaceTrack.MAX_VELOCITY; if (-m_iYVelocity > RaceTrack.MAX_VELOCITY) m_iYVelocity = -RaceTrack.MAX_VELOCITY; } int iFinalX, iFinalY; bool bNoCollision = m_rtTrack.Move(X, Y, m_iXVelocity, m_iYVelocity, out iFinalX, out iFinalY); X = iFinalX; Y = iFinalY; return bNoCollision; }