From b0ae48bbc3761820021db07cfec8e06776f0b639 Mon Sep 17 00:00:00 2001 From: Preston Pan Date: Mon, 6 Feb 2023 15:15:06 -0800 Subject: obstacles work now --- Makefile | 1 + snake.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 2f8d956..9f95cfa 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ CFLAGS=-I. -pthread -Wall -Wextra -Wpedantic -std=c99 -march=native -O3 -lm CFLAGS+= -Wshadow -Wstrict-prototypes -Wundef -Wpointer-arith -Wcast-align -Wstrict-overflow=5 -Wswitch-default CFLAGS+= -Wunreachable-code -Wswitch-enum -Wformat=2 +CFLAGS+= -fsanitize=address PREFIX ?= /usr BINDIR ?= ${PREFIX}/bin MANDIR = ${PREFIX}/share/man/ diff --git a/snake.c b/snake.c index b130b75..f82642b 100644 --- a/snake.c +++ b/snake.c @@ -48,7 +48,7 @@ int main(int argc, char **argv) { return 0; } else if(strcmp("--help", argv[i]) == 0) { - printf("usage: snake3 [--version] [--help] [--size board_size] [--speed speed]\n"); + printf("usage: snake3 [--version] [--help] [--size board_size] [--speed speed] [--obstacles obstacles]\n"); return 0; } else if(strcmp("--size", argv[i]) == 0 || strcmp("--speed", argv[i]) == 0 || strcmp("--obstacles", argv[i]) == 0) { @@ -114,7 +114,7 @@ int main(int argc, char **argv) { snakePositions.vectors[4] = init_vector(3, 3); foodPos = init_vector(7, 9); lastMoveDir = init_vector(0, 1); - int opc = (obstacleSize ^ 2) * obstacles; + int opc = (int)pow(obstacleSize, 2) * obstacles; obstaclePositions = init_vectorp(malloc(opc * sizeof(vector_t)), opc); srand(time(NULL)); /* place the obstacles */ -- cgit v1.3.1