Makefile for Windows + Unix; and some new function for LinkedList
This commit is contained in:
18
Makefile
18
Makefile
@@ -7,16 +7,26 @@ TARGET = main
|
|||||||
SOURCES = $(wildcard $(SRCDIR)/*.c)
|
SOURCES = $(wildcard $(SRCDIR)/*.c)
|
||||||
OBJECTS = $(patsubst $(SRCDIR)/%.c, $(BUILDDIR)/%.o, $(SOURCES))
|
OBJECTS = $(patsubst $(SRCDIR)/%.c, $(BUILDDIR)/%.o, $(SOURCES))
|
||||||
|
|
||||||
all: $(BUILDDIR)/$(TARGET)
|
ifeq ($(OS),Windows_NT)
|
||||||
|
EXECUTABLE = $(BUILDDIR)/$(TARGET).exe
|
||||||
|
RM = del /Q
|
||||||
|
MKDIR = mkdir
|
||||||
|
else
|
||||||
|
EXECUTABLE = $(BUILDDIR)/$(TARGET)
|
||||||
|
RM = rm -f
|
||||||
|
MKDIR = mkdir -p
|
||||||
|
endif
|
||||||
|
|
||||||
$(BUILDDIR)/$(TARGET): $(OBJECTS)
|
all: $(EXECUTABLE)
|
||||||
|
|
||||||
|
$(EXECUTABLE): $(OBJECTS)
|
||||||
$(CC) $(CFLAGS) -o $@ $^
|
$(CC) $(CFLAGS) -o $@ $^
|
||||||
|
|
||||||
$(BUILDDIR)/%.o: $(SRCDIR)/%.c
|
$(BUILDDIR)/%.o: $(SRCDIR)/%.c
|
||||||
@mkdir -p $(BUILDDIR)
|
$(MKDIR) $(BUILDDIR)
|
||||||
$(CC) $(CFLAGS) -c -o $@ $<
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(BUILDDIR)/*
|
$(RM) $(BUILDDIR)/*
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
|
|||||||
29
src/common.c
29
src/common.c
@@ -92,8 +92,33 @@ bool linkedList_removeAt(LinkedList **head, const uint index) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void linkedList_print(LinkedList *head, void (*callback)(void *)) {
|
uint linkedList_length(const LinkedList *head) {
|
||||||
LinkedList *current_node = head;
|
uint current_index = 0;
|
||||||
|
const LinkedList *current_node = head;
|
||||||
|
while (current_node != NULL) {
|
||||||
|
current_node = current_node->next;
|
||||||
|
current_index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return current_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool linkedList_removeAll(LinkedList *head) {
|
||||||
|
uint length = linkedList_length(head);
|
||||||
|
LinkedList *lastNode = linkedList_getAt(head, length - 1);
|
||||||
|
if (lastNode == NULL)
|
||||||
|
return false;
|
||||||
|
while (lastNode->prev != NULL) {
|
||||||
|
lastNode = lastNode->prev;
|
||||||
|
free(lastNode->next);
|
||||||
|
}
|
||||||
|
free(lastNode);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void linkedList_print(const LinkedList *head, void (*callback)(void *)) {
|
||||||
|
const LinkedList *current_node = head;
|
||||||
while (current_node != NULL) {
|
while (current_node != NULL) {
|
||||||
callback(current_node->value);
|
callback(current_node->value);
|
||||||
printf("->");
|
printf("->");
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ LinkedList *linkedList_getAt(LinkedList *head, const uint index);
|
|||||||
bool linkedList_insertAt(LinkedList *head, void *value, const uint index);
|
bool linkedList_insertAt(LinkedList *head, void *value, const uint index);
|
||||||
bool linkedList_removeAt(LinkedList **head, const uint index);
|
bool linkedList_removeAt(LinkedList **head, const uint index);
|
||||||
bool linkedList_append(LinkedList *head, void *value);
|
bool linkedList_append(LinkedList *head, void *value);
|
||||||
void linkedList_print(LinkedList *head, void (*callback)(void *));
|
uint linkedList_length(const LinkedList *head);
|
||||||
|
bool linkedList_removeAll(LinkedList *head);
|
||||||
|
void linkedList_print(const LinkedList *head, void (*callback)(void *));
|
||||||
|
|
||||||
#endif // !__COMMON_HEADER
|
#endif // !__COMMON_HEADER
|
||||||
|
|||||||
8
src/engine.h
Normal file
8
src/engine.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef __ENGINE_HEADER
|
||||||
|
#define __ENGINE_HEADER
|
||||||
|
|
||||||
|
#include "board.h"
|
||||||
|
#include "common.h"
|
||||||
|
#include "fen.h"
|
||||||
|
|
||||||
|
#endif // !__ENGINE_HEADER
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
#include "board.h"
|
#include "engine.h"
|
||||||
#include "common.h"
|
|
||||||
#include "fen.h"
|
|
||||||
|
|
||||||
void printFEN(void *value) { printf("%s", (char *)value); }
|
void printFEN(void *value) { printf("%s", (char *)value); }
|
||||||
void printString(void *value) { printf("%s", *(char **)value); }
|
void printString(void *value) { printf("%s", *(char **)value); }
|
||||||
@@ -12,9 +10,12 @@ int main() {
|
|||||||
board.history = linkedList_init(&fen);
|
board.history = linkedList_init(&fen);
|
||||||
Coordinates *coords =
|
Coordinates *coords =
|
||||||
piece_getMoves(board.squares[3].piece, board.squares[3].coords);
|
piece_getMoves(board.squares[3].piece, board.squares[3].coords);
|
||||||
|
char a[] = "hello";
|
||||||
|
linkedList_append(board.history, &a);
|
||||||
|
printf("%d\n", linkedList_length(board.history));
|
||||||
linkedList_print(board.history, printFEN);
|
linkedList_print(board.history, printFEN);
|
||||||
free(coords);
|
free(coords);
|
||||||
free(board.history);
|
linkedList_removeAll(board.history);
|
||||||
// char *a = "hello";
|
// char *a = "hello";
|
||||||
// LinkedList *head = linkedList_init(&a);
|
// LinkedList *head = linkedList_init(&a);
|
||||||
// char *b = "world";
|
// char *b = "world";
|
||||||
|
|||||||
Reference in New Issue
Block a user