collab/mm20
git clone https://git.julia.blue/collab/mm20
321d415
pcb
1#include <stdio.h> 2#include <stdlib.h> 3#include <string.h> 4 5#define BUFFER_SIZE 32 6 7int get_int (char * command ) { 8printf ("%s\n" ,command ); 9fflush (stdout ); 10char response [BUFFER_SIZE ]; 11fgets (response ,BUFFER_SIZE ,stdin ); 12int value = atoi (response ); 13return value ; 14} 15 16int get_bool (char * command ) { 17printf ("%s\n" ,command ); 18fflush (stdout ); 19char response [BUFFER_SIZE ]; 20fgets (response ,BUFFER_SIZE ,stdin ); 21int value = (strcmp (response ,"true\n" )== 0 ); 22return value ; 23} 24 25int get_ack (char * command ) { 26printf ("%s\n" ,command ); 27fflush (stdout ); 28char response [BUFFER_SIZE ]; 29fgets (response ,BUFFER_SIZE ,stdin ); 30int success = (strcmp (response ,"ack\n" )== 0 ); 31return success ; 32} 33 34int API_maze_width () { 35return get_int ("mazeWidth" ); 36} 37 38int API_maze_height () { 39return get_int ("mazeHeight" ); 40} 41 42int API_wall_front () { 43return get_bool ("wallFront" ); 44} 45 46int API_wall_right () { 47return get_bool ("wallRight" ); 48} 49 50int API_wall_left () { 51return get_bool ("wallLeft" ); 52} 53 54int API_move_forward () { 55return get_ack ("moveForward" ); 56} 57 58void API_turn_right () { 59get_ack ("turnRight" ); 60} 61 62void API_turn_left () { 63get_ack ("turnLeft" ); 64} 65 66void API_set_wall (int x ,int y ,char direction ) { 67printf ("setWall %d %d %c\n" ,x ,y ,direction ); 68fflush (stdout ); 69} 70 71void API_clear_wall (int x ,int y ,char direction ) { 72printf ("clearWall %d %d %c\n" ,x ,y ,direction ); 73fflush (stdout ); 74} 75 76void API_set_color (int x ,int y ,char color ) { 77printf ("setColor %d %d %c\n" ,x ,y ,color ); 78fflush (stdout ); 79} 80 81void API_clear_color (int x ,int y ) { 82printf ("clearColor %d %d\n" ,x ,y ); 83fflush (stdout ); 84} 85 86void API_clear_all_color () { 87printf ("clearAllColor\n" ); 88fflush (stdout ); 89} 90 91void API_set_text (int x ,int y ,char * text ) { 92printf ("setText %d %d %s\n" ,x ,y ,text ); 93fflush (stdout ); 94} 95 96void API_clear_text (int x ,int y ) { 97printf ("clearText %d %d\n" ,x ,y ); 98fflush (stdout ); 99} 100 101void API_clear_all_text () { 102printf ("clearAllText\n" ); 103fflush (stdout ); 104} 105 106int API_was_reset () { 107return get_bool ("wasReset" ); 108} 109 110void API_ack_reset () { 111get_ack ("ackReset" ); 112}