generated from freudenreichan/info2Praktikum-DobleSpiel
Fertig
This commit is contained in:
BIN
Binary file not shown.
@@ -1,3 +1,5 @@
|
|||||||
Silvana;9944
|
Silvana;9944
|
||||||
hannes;9910
|
hannes;9910
|
||||||
|
silvana;9865
|
||||||
|
player2;4983
|
||||||
player1;3999
|
player1;3999
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
CC = gcc
|
CC = gcc
|
||||||
|
|
||||||
|
|
||||||
|
raylibfolder = ./raylib
|
||||||
|
unityfolder = ./unity
|
||||||
|
|
||||||
|
|
||||||
FLAGS = -g -Wall -I$(unityfolder)
|
FLAGS = -g -Wall -I$(unityfolder)
|
||||||
|
|
||||||
|
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
include makefile_windows.variables
|
include makefile_windows.variables
|
||||||
else
|
else
|
||||||
UNAME = $(shell uname)
|
UNAME := $(shell uname)
|
||||||
ifeq ($(UNAME),Linux)
|
ifeq ($(UNAME),Linux)
|
||||||
include makefile_linux.variables
|
include makefile_linux.variables
|
||||||
else
|
else
|
||||||
@@ -13,50 +19,44 @@ else
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
raylibfolder = ./raylib
|
# --------------------------
|
||||||
unityfolder = ./unity
|
# Objektdateien
|
||||||
|
# --------------------------
|
||||||
|
program_obj_files := stack.o bintree.o numbers.o timer.o highscore.o
|
||||||
|
|
||||||
|
|
||||||
|
%.o: %.c
|
||||||
|
$(CC) $(FLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
|
||||||
|
doble: main.o $(program_obj_files)
|
||||||
|
$(CC) $(FLAGS) $^ -o doble
|
||||||
|
|
||||||
|
|
||||||
# --------------------------
|
|
||||||
# Initiales Programm
|
|
||||||
# --------------------------
|
|
||||||
doble_initial:
|
doble_initial:
|
||||||
$(CC) -o doble_initial $(BINARIES)/libdoble_complete.a
|
$(CC) -o doble_initial $(BINARIES)/libdoble_complete.a
|
||||||
|
|
||||||
# --------------------------
|
|
||||||
# Objektdateien
|
|
||||||
# --------------------------
|
|
||||||
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
|
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Unit Tests
|
# Unit Tests
|
||||||
# --------------------------
|
# --------------------------
|
||||||
|
|
||||||
unitTests:
|
unitTests:
|
||||||
@echo "needs to be implemented"
|
@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
|
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
|
$(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
|
test_stack: stack.o test_stack.c $(unityfolder)/unity.c
|
||||||
$(CC) $(FLAGS) -o runstackTests test_stack.c stack.o $(unityfolder)/unity.c
|
$(CC) $(FLAGS) -o runstackTests test_stack.c stack.o $(unityfolder)/unity.c
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Clean
|
# Cleaning
|
||||||
# --------------------------
|
# --------------------------
|
||||||
clean:
|
clean:
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
|
|||||||
@@ -17,13 +17,28 @@
|
|||||||
// Returns len random numbers between 1 and 2*len in random order,
|
// Returns len random numbers between 1 and 2*len in random order,
|
||||||
// all different, except for exactly one duplicate (two entries the same).
|
// all different, except for exactly one duplicate (two entries the same).
|
||||||
// Uses your binary search tree implementation to check for duplicates while generating numbers.
|
// Uses your binary search tree implementation to check for duplicates while generating numbers.
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include "numbers.h"
|
||||||
|
#include "bintree.h"
|
||||||
|
|
||||||
|
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 a<b
|
||||||
|
// in bintree.c wird ueberprueft, ob compare eine positive oder eine negative Zahl zurueckgibt,
|
||||||
|
// wenn a groeßer b, positiv und dann wird links nach Teilbauemen gesucht
|
||||||
|
}
|
||||||
|
|
||||||
|
// Erzeugt len Zufallszahlen zwischen 1 und 2*len
|
||||||
|
// alle einzigartig, außer genau ein Duplikat
|
||||||
unsigned int *createNumbers(unsigned int len)
|
unsigned int *createNumbers(unsigned int len)
|
||||||
{
|
{
|
||||||
if (len < 2)
|
if (len < 2)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
srand(time(NULL));
|
srand((unsigned int)time(NULL));
|
||||||
|
|
||||||
|
|
||||||
unsigned int *numbers = malloc(len * sizeof(unsigned int));
|
unsigned int *numbers = malloc(len * sizeof(unsigned int));
|
||||||
if (!numbers)
|
if (!numbers)
|
||||||
@@ -33,27 +48,30 @@ unsigned int *createNumbers(unsigned int len)
|
|||||||
unsigned int count = 0;
|
unsigned int count = 0;
|
||||||
|
|
||||||
// Zufallszahlen generieren, bis das Array voll ist
|
// Zufallszahlen generieren, bis das Array voll ist
|
||||||
while (count < len) {
|
while (count < len)
|
||||||
|
{
|
||||||
unsigned int random = (rand() % (2 * len)) + 1;
|
unsigned int random = (rand() % (2 * len)) + 1;
|
||||||
|
|
||||||
int duplicate = 0; // Anfangswert für Duplikat-Check
|
int duplicate = 0; // Anfangswert für Duplikat-Check
|
||||||
|
|
||||||
root = addToTree(root, &random, sizeof(random), compareFct, &duplicate);
|
root = addToTree(root, &random, sizeof(random), compareFct, &duplicate);
|
||||||
|
|
||||||
if (root == NULL) {
|
if (root == NULL)
|
||||||
|
{
|
||||||
free(numbers);
|
free(numbers);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!duplicate) { // Zahl war neu → ins Array einfügen
|
if (!duplicate)
|
||||||
|
{
|
||||||
numbers[count++] = random;
|
numbers[count++] = random;
|
||||||
}
|
}
|
||||||
// duplicate == 1 → Zahl existiert schon, neue Zahl generieren
|
// duplicate == 1 → Zahl existiert schon, neue Zahl generieren
|
||||||
}
|
}
|
||||||
|
|
||||||
// Jetzt len eindeutige Zahlen erzeugt → ein Duplikat erzwingen
|
// genau ein Duplikat erzeugen
|
||||||
unsigned int idx1 = rand() % len;
|
unsigned int idx1 = rand() % len;
|
||||||
unsigned int idx2 = rand() % len;
|
unsigned int idx2 = rand() % len;
|
||||||
while (idx2 == idx1) // sicherstellen, dass es eine andere Position ist
|
while (idx2 == idx1)
|
||||||
idx2 = rand() % len;
|
idx2 = rand() % len;
|
||||||
|
|
||||||
numbers[idx2] = numbers[idx1];
|
numbers[idx2] = numbers[idx1];
|
||||||
@@ -64,38 +82,23 @@ unsigned int *createNumbers(unsigned int len)
|
|||||||
return numbers;
|
return numbers;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Jetzt len eindeutige Zahlen erzeugt ⇒ wir müssen ein Duplikat erzwingen
|
|
||||||
unsigned int idx1 = rand() % len;
|
|
||||||
unsigned int idx2 = rand() % len;
|
|
||||||
while (idx2 == idx1)
|
|
||||||
idx2 = rand() % len;
|
|
||||||
|
|
||||||
numbers[idx2] = numbers[idx1]; // zweites Exemplar
|
// findet die eine doppelte Zahl im Array
|
||||||
|
|
||||||
clearTree(root);
|
|
||||||
return numbers;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Returns only the only number in numbers which is present twice. Returns zero on errors.
|
|
||||||
unsigned int getDuplicate(const unsigned int numbers[], unsigned int len)
|
unsigned int getDuplicate(const unsigned int numbers[], unsigned int len)
|
||||||
{
|
{
|
||||||
if(len>0)
|
if (!numbers || len < 2)
|
||||||
{
|
return 0;
|
||||||
unsigned int duplicate = 0;
|
|
||||||
for (unsigned int i = 0; i < len; i++)
|
for (unsigned int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
unsigned int v1 = numbers[i];
|
|
||||||
for (unsigned int j = i + 1; j < len; j++)
|
for (unsigned int j = i + 1; j < len; j++)
|
||||||
{
|
{
|
||||||
unsigned int v2 = numbers[j];
|
if (numbers[i] == numbers[j])
|
||||||
if(v1==v2)
|
return numbers[i];
|
||||||
{
|
|
||||||
return v1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef NUMBERS_H
|
#ifndef NUMBERS_H
|
||||||
#define NUMBERS_H
|
#define NUMBERS_H
|
||||||
|
|
||||||
|
|
||||||
|
int compareFct(const void *a, const void *b);
|
||||||
// Returns len random numbers between 1 and 2x len in random order which are all different, except for two entries.
|
// Returns len random numbers between 1 and 2x len in random order which are all different, except for two entries.
|
||||||
// Returns NULL on errors. Use your implementation of the binary search tree to check for possible duplicates while
|
// Returns NULL on errors. Use your implementation of the binary search tree to check for possible duplicates while
|
||||||
// creating random numbers.
|
// creating random numbers.
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -4,6 +4,14 @@
|
|||||||
|
|
||||||
//Testfunkionen zu push, pull, top & clearStack schreiben
|
//Testfunkionen zu push, pull, top & clearStack schreiben
|
||||||
|
|
||||||
|
void setUp()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void tearDown()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void test(char *name, int condition) {
|
void test(char *name, int condition) {
|
||||||
if (condition) {
|
if (condition) {
|
||||||
printf("[OK] %s\n", name);
|
printf("[OK] %s\n", name);
|
||||||
Reference in New Issue
Block a user