/// <summary> /// /// </summary> /// <param name="state"></param> /// <returns></returns> public object onOutsie(CarState.Outside state) { CarState.Inside s = calcReturnPoint(state); if (s == null) { // all the usable RRs are completely removed. // that means this train is fully outside the world. // so it's OK to remain static. return(state); } return(new CarState.Outside( s.location - s.direction, s.direction.opposite, OUTSIDE_COUNTER_INITIAL_VALUE - state.timeLeft)); }
/// <summary> /// /// </summary> /// <param name="state"></param> /// <returns></returns> public object onOutsie(CarState.Outside state) { if (state.timeLeft != 0) { return(new CarState.Outside(state.location, state.direction, state.timeLeft - 1)); } // time to get back to the world. CarState s = calcReturnPoint(state); if (s != null) { return(s); } // there's no coming back. try again later return(new CarState.Outside(state.location, state.direction, 10)); }
/// <summary> /// Determines where the train should re-appear into the world. /// </summary> /// <param name="state"></param> /// <returns></returns> private static CarState.Inside calcReturnPoint(CarState.Outside state) { // where do we go back? // for now, go back to where it comes from. int idx = state.direction.isSharp ? 0 : 1; for (int i = 0; i < 5; i++) { // compute the location Location newLoc = state.location + returnPointMatrixes[idx, i] * ((Distance)state.direction); // see if there's rail road if (isConnected(newLoc, state.direction.opposite)) { // OK return(new CarState.Inside(newLoc, state.direction.opposite)); } } return(null); // non found }
public object onOutsie(CarState.Outside state) { return(false); }