diff --git a/doble.exe b/doble.exe new file mode 100644 index 0000000..7508ef3 Binary files /dev/null and b/doble.exe differ diff --git a/highscore.o b/highscore.o new file mode 100644 index 0000000..93116d5 Binary files /dev/null and b/highscore.o differ diff --git a/highscores.txt b/highscores.txt index 67b8a3c..e42f425 100644 --- a/highscores.txt +++ b/highscores.txt @@ -1,3 +1,5 @@ Silvana;9944 hannes;9910 +silvana;9865 +player2;4983 player1;3999 diff --git a/main.o b/main.o new file mode 100644 index 0000000..7c81b6e Binary files /dev/null and b/main.o differ diff --git a/makefile b/makefile index 887c59f..925a2d9 100644 --- a/makefile +++ b/makefile @@ -1,62 +1,62 @@ CC = gcc -FLAGS = -g -Wall -I$(unityfolder) -ifeq ($(OS),Windows_NT) - include makefile_windows.variables -else - UNAME = $(shell uname) - ifeq ($(UNAME),Linux) - include makefile_linux.variables - else - include makefile_mac.variables - endif -endif - raylibfolder = ./raylib unityfolder = ./unity -# -------------------------- -# Initiales Programm -# -------------------------- -doble_initial: - $(CC) -o doble_initial $(BINARIES)/libdoble_complete.a + +FLAGS = -g -Wall -I$(unityfolder) + + +ifeq ($(OS),Windows_NT) +include makefile_windows.variables +else +UNAME := $(shell uname) +ifeq ($(UNAME),Linux) +include makefile_linux.variables +else +include makefile_mac.variables +endif +endif # -------------------------- # Objektdateien # -------------------------- -program_obj_files = stack.o bintree.o numbers.o timer.o highscore.o +program_obj_files := stack.o bintree.o numbers.o timer.o highscore.o + -# Generische Regel für alle .o-Dateien %.o: %.c $(CC) $(FLAGS) -c $< -o $@ -# -------------------------- -# Hauptprogramm -# -------------------------- + doble: main.o $(program_obj_files) $(CC) $(FLAGS) $^ -o doble + +doble_initial: + $(CC) -o doble_initial $(BINARIES)/libdoble_complete.a + # -------------------------- # Unit Tests # -------------------------- + unitTests: @echo "needs to be implemented" -# Bintree Tests -binTreeTests: stack.o bintree.o binTreeTests.c $(unityfolder)/unity.c - $(CC) $(FLAGS) -o runbintreeTests binTreeTests.c bintree.o stack.o $(unityfolder)/unity.c -# Numbers Tests +binTreeTest: stack.o bintree.o binTreeTest.c $(unityfolder)/unity.c + $(CC) $(FLAGS) -o runbinTreeTest binTreeTest.c bintree.o stack.o $(unityfolder)/unity.c + + test_numbers: numbers_no_tree.o bintree.o stack.o test_numbers.c $(unityfolder)/unity.c $(CC) $(FLAGS) -o run_numbersTests test_numbers.c numbers_no_tree.o bintree.o stack.o $(unityfolder)/unity.c -# Stack Tests + test_stack: stack.o test_stack.c $(unityfolder)/unity.c $(CC) $(FLAGS) -o runstackTests test_stack.c stack.o $(unityfolder)/unity.c # -------------------------- -# Clean +# Cleaning # -------------------------- clean: ifeq ($(OS),Windows_NT) diff --git a/numbers.c b/numbers.c index da32793..f9dfaee 100644 --- a/numbers.c +++ b/numbers.c @@ -17,85 +17,88 @@ // Returns len random numbers between 1 and 2*len in random order, // all different, except for exactly one duplicate (two entries the same). // Uses your binary search tree implementation to check for duplicates while generating numbers. -unsigned int *createNumbers(unsigned int len) -{ - if (len < 2) - return NULL; +#include +#include +#include +#include "numbers.h" +#include "bintree.h" - srand(time(NULL)); - - - unsigned int *numbers = malloc(len * sizeof(unsigned int)); - if (!numbers) - return NULL; - - TreeNode *root = NULL; // Baum anfänglich leer - unsigned int count = 0; - - // Zufallszahlen generieren, bis das Array voll ist - while (count < len) { - unsigned int random = (rand() % (2 * len)) + 1; - - int duplicate = 0; // Anfangswert für Duplikat-Check - root = addToTree(root, &random, sizeof(random), compareFct, &duplicate); - - if (root == NULL) { - free(numbers); - return NULL; - } - - if (!duplicate) { // Zahl war neu → ins Array einfügen - numbers[count++] = random; - } - // duplicate == 1 → Zahl existiert schon, neue Zahl generieren +int compareFct(const void *a, const void *b) + { + return (*(int *)a > *(int *)b) - (*(int *)a < *(int *)b); // a und b werden in int konvertiert und deren Werte miteinander verglichen + // returns 1 for a>b or -1 for a0) + if (!numbers || len < 2) + return 0; + + for (unsigned int i = 0; i < len; i++) { - unsigned int duplicate = 0; - for(unsigned int i=0;i