0
$\begingroup$

How can I translate this statement below into an algorithm. thanks.

  • If the car reaches the edge of the wall on the east OR on the West side

  • the car goes backwards a short distance

  • then, the car turns to a random direction AND go forward

  • If the car reaches the edge of the wall on the North OR on the south side

  • the car goes backwards a short distance, then

  • then,the car turns to a random direction AND go forward

  • 0
    it is already an algorithm2017-02-04

1 Answers 1

0

I don't know quite what you mean by algorithm, so here is some pseudo-code.

if (car reaches the edge of the wall on the east OR on the West side)

 move backward a short distance.
 turn random direction.
 go forward.

endif

if (car reaches the edge of the wall on the north OR on the south side)

 move backward a short distance.
 turn random direction.
 go forward.

endif

The above algorithm matches what you described, but the following algorithm is more compact, and I beleive it does the same thing.

if (car reaches the edge of the wall on ANY side)

 move backward a short distance.
 turn random direction.
 go forward.

endif

  • 0
    I am not sure but when it says algorithm, i think it's something like, let's suppose that x=car, y=width 0 as west to 10 as east, so if (x> 10y ll x < y), same as if (car reaches the edge of the wall on the east OR on the West side).2017-02-02