refactor orientation

This commit is contained in:
quenousimporte 2025-04-23 12:13:27 +01:00
parent 750136ab17
commit 105fdcfd82
1 changed files with 4 additions and 32 deletions

36
w/w.c
View File

@ -34,8 +34,8 @@
#define NORTH 0 #define NORTH 0
#define EAST 1 #define EAST 1
#define WEST 2 #define SOUTH 2
#define SOUTH 3 #define WEST 3
#define TILE_WALL 0 #define TILE_WALL 0
#define TILE_FREE 1 #define TILE_FREE 1
@ -408,40 +408,12 @@ void forward()
void right() void right()
{ {
switch (state.position.orientation) state.position.orientation = (state.position.orientation + 1) % 4;
{
case NORTH:
state.position.orientation = EAST;
break;
case SOUTH:
state.position.orientation = WEST;
break;
case EAST:
state.position.orientation = SOUTH;
break;
case WEST:
state.position.orientation = NORTH;
break;
}
} }
void left() void left()
{ {
switch (state.position.orientation) state.position.orientation = (state.position.orientation + 3) % 4;
{
case NORTH:
state.position.orientation = WEST;
break;
case SOUTH:
state.position.orientation = EAST;
break;
case EAST:
state.position.orientation = NORTH;
break;
case WEST:
state.position.orientation = SOUTH;
break;
}
} }
void dumpstate() void dumpstate()