Commit 20ee97a3 authored by Jan Pokorný's avatar Jan Pokorný 💬
Browse files

PNS and DFPN search for Qubic, base

parent 30bb3bcd
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
# project compilation folders
build
exe
#!/bin/python3
import os
import re
import subprocess
import time
import sys
SOLVER_NAME = sys.argv[1]
UPDATE_COUNTS = sys.argv[2].lower() in ("yes", "true", "t", "1")
SOLVER_PATH = "./exe/{}Solver".format(SOLVER_NAME)
TOTAL_RUN_TIME = 0
def read_file(filename):
result = None
if(os.path.isfile(filename)):
with open(filename) as file:
result = file.read()
return result
def write_file(filename, contents):
with open(filename, "w") as reference:
reference.write(contents)
def run_program(position_name):
print("=================================================")
print(position_name)
input_game = open(position_name + ".pos")
reference_output = read_file(position_name + ".ref")
reference_no_nodes = read_file(position_name + ".meta")
reference_no_nodes = int(reference_no_nodes) if reference_no_nodes!= None else None
start = time.time()
p = subprocess.Popen([SOLVER_PATH], stdin=input_game, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
program_output = [x.decode('UTF-8') for x in p.communicate()]
end = time.time()
global TOTAL_RUN_TIME
TOTAL_RUN_TIME += end - start
print("time: {}".format(end - start))
assert reference_output == program_output[0] or reference_output == None, "Program outputed {}, but in reference was {}".format(program_output[0], reference_output)
print("result: {}".format(program_output[0]))
print("reference: {} \t current: {}".format(reference_no_nodes, int(program_output[1])))
if(reference_output == None or reference_no_nodes == None):
write_file(position_name + ".ref", program_output[0])
write_file(position_name + ".meta", program_output[1])
print("Writing results")
elif(int(reference_no_nodes) > int(program_output[1]) and UPDATE_COUNTS):
write_file(position_name + ".meta", program_output[1])
print("Updating results")
def run_on_all_positions():
game = 'qubic' # todo read as argument
prefix = './positions/{}/'.format(game)
entries = os.listdir(prefix)
for game_type in ["easy", "medium", "hard"]:
regex = re.compile("{}..\\.pos".format(game_type))
positions = list(filter(regex.search, entries))
positions.sort()
for position in positions:
run_program(prefix + position[:-4])
run_on_all_positions()
print("Total runtime: {}".format(TOTAL_RUN_TIME))
\ No newline at end of file
# Supreme Makefile by Václav Blažej
CC = g++
CXXFLAGS = --std=c++17 -Wall -Wextra -pedantic -g -O3 -ffast-math -march=native
DEPFLAGS = -MT $@ -MMD -MP -MF ./build/$*.d
MAIN_FILES = $(shell grep -lr 'int main' './src/' | grep 'cpp$$')
OTHER_FILES = $(shell grep -Lr 'int main' './src/' | grep 'cpp$$')
SOURCE_FILES = $(OTHER_FILES) $(MAIN_FILES)
EXE_FILES = $(MAIN_FILES:./src/%.cpp=./exe/%)
TEST_EXE_FLS = $(filter %test, $(EXE_FILES))
OBJECT_FILES = $(OTHER_FILES:./src/%.cpp=./build/%.o)
HEADER_FILES = $(OTHER_FILES:.cpp=.hpp)
DEPENDENCIES = $(SOURCE_FILES:./src/%.cpp=./build/%.d)
compile: $(EXE_FILES)
./build/%.o: ./src/%.cpp ./build/%.d
@mkdir -p `dirname $@`
$(CC) $(CXXFLAGS) $(DEPFLAGS) -c -o $@ $<
$(EXE_FILES): ./exe/%: ./src/%.cpp $(OBJECT_FILES)
@mkdir -p `dirname $@`
$(CC) $(CXXFLAGS) -o $@ $< $(OBJECT_FILES)
test: $(TEST_EXE_FLS)
@./test.sh
.PHONY: clean
clean:
@echo "don't change this rule, as it may be dangerous if small bugs are introduced"
rm -rf build/ exe/
count:
wc -l src/*.?pp src/*/*.?pp
$(DEPENDENCIES):
include $(wildcard $(DEPENDENCIES))
xxx-
ooo-
----
----
----
----
----
----
----
----
----
----
----
----
----
----
oxxx
oxxx
oxxx
-ooo
oxxx
oxxx
oxxx
-ooo
oxxx
oxxx
oxxx
-ooo
-ooo
-ooo
-ooo
----
\ No newline at end of file
x---
----
--o-
---x
----
----
--x-
--o-
ooox
-oo-
--o-
oxxx
x---
----
x---
x--o
ooxo
o-x-
xx--
o---
----
----
--x-
----
----
----
o-x-
----
----
----
o-x-
----
ooxx
xxoo
ooxx
ooxx
ooxx
xxoo
ooxx
xoxx
o---
---o
----
----
----
----
----
----
Second player wins or draws
x--o
----
oo--
x--x
---x
----
-o--
o---
----
----
ox--
x---
o--x
--x-
xoxo
x--o
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment