Bot that follows input commands for movement on an XY axis plane
Initially Bot have (0,0) axis and facing the NORTH direction. From the problem ,we can get , If Bot will move Left , it rotates its direction 90 clockwise, It means If previous direction is north and bot moving to left direction will change to EAST , similarly if direction is EAST and bot moves left , direction will change to SOUTH clock wise..similarly for other direction....
For right it moves anticlockwise, if direction is EAST and right moves ... direction will change into North, if direction is North and left moves then as anticlockwise it changes direction to West.
For axis if right moves it will add from previous axis and for left move it will subtract.
- Set initial direction of bot to
NORTHwith axis(0,0) - Loop on given direction&movment
-
If
R(right) input is given withnmovement:- Update
xAxis as (x+n, y) , (where x, y are previous axis) - check direction of bot , If:
- direction is
NORTH... rotate bot intoEAST direction - direction is
EAST... rotate bot intoSOUTH direction - direction is
SOUTH... rotate bot intoWEST direction - direction is
WEST... rotate bot intoNORTH direction
- direction is
- Update
-
If
L(left) input is given withnmovement:- Update
xAxis as (x-n, y) , (where x, y are previous axis) - check direction of bot , If:
- direction is
NORTH... rotate bot intoWEST direction - direction is
WEST... rotate bot intoSOUTH direction - direction is
SOUTH... rotate bot intoEAST direction - direction is
EAST... rotate bot intoNORTH direction
- direction is
- Update
-
- Print rotated direction + current axis
Basic knowledge of Java Arrays , Hashmap and OOP is required for this task.
For java, There is PathBot.jar , which can be run using java -jar PathBot.jar RM15 LM10.
For Python, path-bot.py RM15 LM10
For running from source , javac PathBot.java && java PathBot RM15
Tested in : Java17 (for java), python 3.11 ( for python)