From 105fdcfd8271aab5f367350668b62b3b053c2429 Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Wed, 23 Apr 2025 12:13:27 +0100 Subject: [PATCH] refactor orientation --- w/w.c | 36 ++++-------------------------------- 1 file changed, 4 insertions(+), 32 deletions(-) diff --git a/w/w.c b/w/w.c index 2e72c69..04e7970 100644 --- a/w/w.c +++ b/w/w.c @@ -34,8 +34,8 @@ #define NORTH 0 #define EAST 1 -#define WEST 2 -#define SOUTH 3 +#define SOUTH 2 +#define WEST 3 #define TILE_WALL 0 #define TILE_FREE 1 @@ -408,40 +408,12 @@ void forward() void right() { - switch (state.position.orientation) - { - 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; - } + state.position.orientation = (state.position.orientation + 1) % 4; } void left() { - switch (state.position.orientation) - { - 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; - } + state.position.orientation = (state.position.orientation + 3) % 4; } void dumpstate()