diff options
-rw-r--r-- | Makefile | 6 | ||||
-rwxr-xr-x | compile_ai.sh | 16 | ||||
-rw-r--r-- | main.cpp | 12 |
3 files changed, 32 insertions, 2 deletions
@@ -3,6 +3,10 @@ CXXFLAGS = -Wall -Wextra -O3 -std=c++17 -fwrapv -flto TARGET = main +ifneq ($(value AI),) + CXXFLAGS += "-DAI_CHOICE=$(value AI)" +endif + .PHONY: all clean all: $(TARGET) @@ -12,7 +16,7 @@ clean: main: $(patsubst %.cpp,%.o,$(wildcard *.cpp)) - $(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS) + $(CXX) $(CXXFLAGS) $^ -o $@ %.o: %.cpp $(wildcard *.h) $(CXX) $(CXXFLAGS) -c -o $@ $< diff --git a/compile_ai.sh b/compile_ai.sh new file mode 100755 index 0000000..a24cd3f --- /dev/null +++ b/compile_ai.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -eo pipefail + +cd "$(dirname "$0")" + +if [[ -f main ]]; then + have_main=1 + mv main .compile_ai_main_bak +fi + +make AI="$1" -W main.cpp +mv main "$1" + +if [[ $have_main -eq 1 ]]; then + mv .compile_ai_main_bak main +fi @@ -8,6 +8,14 @@ using namespace std; +#ifndef AI_CHOICE +#define AI_CHOICE MC +#endif + +#define STR_(x) #x +#define STR(x) STR_(x) +#define AI_CHOICE_STR STR(AI_CHOICE) + static void skipLine(istream &stream) { while (stream.get() != '\n'); @@ -15,7 +23,7 @@ static void skipLine(istream &stream) { static Move findMove(const Board &bd, int player) { clock_t start = clock(); - Move mv = AI::MC::findMove(bd, player); + Move mv = AI:: AI_CHOICE ::findMove(bd, player); clock_t diff = clock() - start; cerr << "Time taken: " << (double)diff / CLOCKS_PER_SEC << " seconds" << endl; return mv; @@ -26,6 +34,8 @@ int main() { gettimeofday(&tv, nullptr); srand(tv.tv_sec * 1000000UL + tv.tv_usec); + cerr << "Using AI: " << AI_CHOICE_STR << endl; + Board bd = Board::makeInitial(); // cerr << bd << endl; |