From 557ced61d1fc0efdb9f13ae6496e55d7f132b8e3 Mon Sep 17 00:00:00 2001
From: Francesco Bariatti <francesco.bariatti@insa-rennes.fr>
Date: Mon, 16 May 2016 14:03:40 +0200
Subject: [PATCH] New version of Makefile: changed name of the output, added
 comments and improved rules

---
 Makefile                           | 46 +++++++++++++++++++-----------
 gui/src/controller/Controller.java |  2 +-
 src/main/main.cpp                  | 17 +----------
 3 files changed, 31 insertions(+), 34 deletions(-)

diff --git a/Makefile b/Makefile
index 069562b..dd2fa52 100644
--- a/Makefile
+++ b/Makefile
@@ -1,30 +1,42 @@
+# Compiler
 CC=g++
+# Output directory
 BIN=bin
-INCLUDE=-I src/game -I src/util -I src/monte_carlo -I src/mcts -I src/minmax -I src/json
-CFLAGS=-g -O3 -ffast-math -fopenmp -c -Wall -std=c++11 $(INCLUDE)
+# Name of the executable
+EXECUTABLE=$(BIN)/penguin
+# Directories with .h files
+INCLUDE=-I src/game -I src/util -I src/monte_carlo -I src/mcts -I src/json
+# Directories in which make will search for files
+vpath %.cpp src/game src/main src/util src/monte_carlo src/mcts src/gdl
+# Flags passed to the compiler
+CFLAGS=-g -O3 -ffast-math -fopenmp -Wall -std=c++11
+# Flags passed to the linker
 LDFLAGS=-fopenmp -std=c++11 #-lprofiler -Wl,-no_pie
-SOURCES=omp_util.cpp fast_log.cpp display_node.cpp penguin.cpp connect4.cpp morpion.cpp test_two_players_game.cpp test_connect4.cpp monte_carlo.cpp test_monte_carlo.cpp test_fast_log.cpp\
-statistics.cpp node.cpp allocator.cpp test_allocator.cpp openings.cpp mcts_two_players.cpp test_mcts_two_players.cpp test_minmax.cpp\
-bits.cpp test_bits.cpp main.cpp
+# Cpp source files
+SOURCES=omp_util.cpp fast_log.cpp display_node.cpp penguin.cpp test_two_players_game.cpp monte_carlo.cpp \
+	test_fast_log.cpp statistics.cpp node.cpp allocator.cpp test_allocator.cpp openings.cpp mcts_two_players.cpp \
+	test_mcts_two_players.cpp bits.cpp test_bits.cpp main.cpp
+# Generating .o files' names
 OBJECTS=$(addprefix $(BIN)/, $(SOURCES:.cpp=.o))
-EXECUTABLE=$(BIN)/theturk
-vpath %.cpp src/game:src/main:src/util:src/monte_carlo:src/mcts:src/gdl:src/minmax
 
-all: $(EXECUTABLE)
+# ========= RULES ============
+
+# Creates the output directory and the executable
+all: bindir $(EXECUTABLE)
+
+# Creates the output directory if it doesn't exist
+bindir:
+	mkdir -p $(BIN)
 
 $(EXECUTABLE): $(OBJECTS)
 	$(CC) $(LDFLAGS) $(OBJECTS) -o $@
 
--include $(BIN)/$(OBJECTS:.o=.d)
-
+# Creates .o files with automatic generation of dependencies (.d) files
 $(BIN)/%.o: %.cpp
-	$(CC) -c $(CFLAGS) $< -o $(BIN)/$*.o
-	$(CC) -MM $(CFLAGS) $< > $(BIN)/$*.d
-	@mv -f $(BIN)/$*.d $(BIN)/$*.d.tmp
-	@sed -e 's|.*:|$(BIN)/$*.o:|' < $(BIN)/$*.d.tmp > $(BIN)/$*.d
-	@sed -e 's/.*://' -e 's/\\$$//' < $(BIN)/$*.d.tmp | fmt -1 | \
-	sed -e 's/^ *//' -e 's/$$/:/' >> $(BIN)/$*.d
-	@rm -f $(BIN)/$*.d.tmp
+	$(CC) -c $(CFLAGS) $(INCLUDE) -MD -MP $< -o $@
+# Include the dependency files into the makefile
+-include $(OBJECTS:.o=.d)
 
+# Deletes .o, .d and the executable
 clean:
 	rm -f $(BIN)/*.o $(BIN)/*.d $(EXECUTABLE)
diff --git a/gui/src/controller/Controller.java b/gui/src/controller/Controller.java
index 2739604..872cead 100644
--- a/gui/src/controller/Controller.java
+++ b/gui/src/controller/Controller.java
@@ -30,7 +30,7 @@ import java.util.ResourceBundle;
 
 public class Controller implements Initializable
 {
-	private static final String iaProgramPath = "../bin/theturk";
+	private static final String iaProgramPath = "../bin/penguin";
 	private static final String introMusicFile = "./resource/pingu_theme.wav";
 	private static final String clickSoundFile = "./resource/clic.wav";
 	private static final int max1Fish = 30, max2Fish = 20, max3Fish = 10;
diff --git a/src/main/main.cpp b/src/main/main.cpp
index 181e630..2e43008 100644
--- a/src/main/main.cpp
+++ b/src/main/main.cpp
@@ -1,13 +1,8 @@
-#include "test_connect4.hpp"
-#include "connect4.hpp"
-#include "morpion.hpp"
 #include "penguin.hpp"
 #include "test_two_players_game.hpp"
-#include "test_monte_carlo.hpp"
 #include "test_fast_log.hpp"
 #include "test_allocator.hpp"
 #include "test_mcts_two_players.hpp"
-#include "test_minmax.hpp"
 #include "test_bits.hpp"
 #include "learning.hpp"
 
@@ -17,23 +12,13 @@ using namespace std;
 
 int main(int argc, char *argv[])
 {
-	// game::test_connect4();
 	// util::test_fast_log(100000000);
 	// mcts::test_allocator(10, 2);
 	// omp_set_num_threads(8);
-	//  game::run_test_two_players_game(game::connect4());
-	//mcts::run_test_mcts_two_players(game::connect4());
-	
-	//game::run_test_two_players_game(game::morpion());
-	//mcts::run_test_mcts_two_players(game::morpion());
-	
+
 	//game::run_test_two_players_game(game::penguin());
 	mcts::run_test_mcts_two_players(game::penguin());
 
-
-	// minmax::test_minmax();
 	//util::test_bits(200000000);
-	//game::connect4 c4;
-	//  util::learning::display_file(c4, "learning_examples.txt");
 	return 0;
 }
-- 
GitLab