From 8b0ade7763c6373d82c2ac7bec7b54ed48fb321c Mon Sep 17 00:00:00 2001 From: Ozeliurs Date: Fri, 16 Feb 2024 15:42:26 +0100 Subject: [PATCH 1/4] feat: add python solver handle --- gui/eternitylib/board.py | 1 - gui/eternitylib/generation.py | 5 ----- gui/main.py | 6 ++++++ gui/solverlib/execution.py | 6 ++++++ gui/solverlib/solver.py | 11 +++++++++-- 5 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 gui/solverlib/execution.py diff --git a/gui/eternitylib/board.py b/gui/eternitylib/board.py index 0635e21..475e4df 100644 --- a/gui/eternitylib/board.py +++ b/gui/eternitylib/board.py @@ -70,7 +70,6 @@ def read_csv(self, csv: str): set(pattern for line in csv.split("\n") if line.strip() for pattern in line.split(",")) ) - for i, line in enumerate(csv.split("\n")): if line.strip() == "": continue diff --git a/gui/eternitylib/generation.py b/gui/eternitylib/generation.py index 577ca9f..5f0fb51 100644 --- a/gui/eternitylib/generation.py +++ b/gui/eternitylib/generation.py @@ -50,8 +50,3 @@ def shuffle_board(board): piece.append(piece.pop(0)) np.random.shuffle(board) return board - - -board = create_board(size, number_of_symbols) -print(print_board(board)) -print(format_board(shuffle_board(board))) diff --git a/gui/main.py b/gui/main.py index d31be58..dea7135 100644 --- a/gui/main.py +++ b/gui/main.py @@ -53,4 +53,10 @@ def generate_board(size: int, pattern_count: int) -> (str, Path, Path): if __name__ == "__main__": solver = Solver() solver.link_solver() + + board = Board() + board.generate(10, 22) + + print(solver.solve(board)) + # interface.launch(share=True) diff --git a/gui/solverlib/execution.py b/gui/solverlib/execution.py new file mode 100644 index 0000000..8e47129 --- /dev/null +++ b/gui/solverlib/execution.py @@ -0,0 +1,6 @@ +class Execution: + def __init__(self, logs: str): + self.logs = logs + + def parse_logs(self): + pass \ No newline at end of file diff --git a/gui/solverlib/solver.py b/gui/solverlib/solver.py index 3692b6e..bd670d5 100644 --- a/gui/solverlib/solver.py +++ b/gui/solverlib/solver.py @@ -9,8 +9,15 @@ def __init__(self): # exe is in the same dir as this file self.exe_path = Path(__file__).parent / "e2solver" - def link_solver(self, exe_path: Path = Path(__file__).parent.parent.parent / "cmake-build-debug/solver/Solver"): - subprocess.run(["ln", "-s", str(exe_path), str(self.exe_path)]) + def link_solver(self, path: Path = Path(__file__).parent.parent.parent / "cmake-build-debug/solver/Solver"): + # If file does not exist, raise an error + if not path.exists(): + raise FileNotFoundError(f"Solver executable not found at {path}") + + if self.exe_path.exists(): + self.exe_path.unlink() + + path.symlink_to(self.exe_path) def solve(self, board: Board, timeout: int = 60) -> str: # Write the board to a file From 53fc823b9fe124e909bab4af4b282911c5daffa2 Mon Sep 17 00:00:00 2001 From: neoteristis Date: Fri, 16 Feb 2024 15:41:36 +0100 Subject: [PATCH 2/4] move file --- get_true_pieces/main.py | 47 ------------------- .../eternitylib/get_true_pieces}/hint.json | 0 .../get_true_pieces}/parsed_data.json | 0 .../eternitylib/get_true_pieces}/source.txt | 0 4 files changed, 47 deletions(-) delete mode 100644 get_true_pieces/main.py rename {get_true_pieces => gui/eternitylib/get_true_pieces}/hint.json (100%) rename {get_true_pieces => gui/eternitylib/get_true_pieces}/parsed_data.json (100%) rename {get_true_pieces => gui/eternitylib/get_true_pieces}/source.txt (100%) diff --git a/get_true_pieces/main.py b/get_true_pieces/main.py deleted file mode 100644 index f2b64ce..0000000 --- a/get_true_pieces/main.py +++ /dev/null @@ -1,47 +0,0 @@ -import json -import re - - -def parse_source(): - file_path = 'source.txt' - parsed_data = {"corner": {}, "outer": {}, "normal": {}} - - with open(file_path, 'r') as file: - for line in file.readlines(): - if not line.startswith('piecesCorner') and \ - not line.startswith('piecesOuter') and \ - not line.startswith('piecesNormal'): - continue - piece_id = re.findall(r'\d+', line)[0] - piece_representation = re.findall(r'Piece\(\"([A-Z]{4})\"\)', line)[0] - if line.startswith('piecesCorner'): - parsed_data['corner'][piece_id] = piece_representation - elif line.startswith('piecesOuter'): - parsed_data['outer'][piece_id] = piece_representation - elif line.startswith('piecesNormal'): - parsed_data['normal'][piece_id] = piece_representation - - return parsed_data - - -if __name__ == '__main__': - output = {} - - piece_dict = parse_source() - output['pieces'] = piece_dict - - letter_list = [] - - for key in piece_dict: - for k, v in piece_dict[key].items(): - for letter in v: - if letter not in letter_list: - letter_list.append(letter) - - letter_list.sort() - - output['letters'] = letter_list - - # Save the parsed data to a json - with open('parsed_data.json', 'w') as file: - json.dump(output, file) diff --git a/get_true_pieces/hint.json b/gui/eternitylib/get_true_pieces/hint.json similarity index 100% rename from get_true_pieces/hint.json rename to gui/eternitylib/get_true_pieces/hint.json diff --git a/get_true_pieces/parsed_data.json b/gui/eternitylib/get_true_pieces/parsed_data.json similarity index 100% rename from get_true_pieces/parsed_data.json rename to gui/eternitylib/get_true_pieces/parsed_data.json diff --git a/get_true_pieces/source.txt b/gui/eternitylib/get_true_pieces/source.txt similarity index 100% rename from get_true_pieces/source.txt rename to gui/eternitylib/get_true_pieces/source.txt From 22e6126cdd498ed6200fc0f8bcfeafda996046df Mon Sep 17 00:00:00 2001 From: Ozeliurs Date: Fri, 16 Feb 2024 15:43:13 +0100 Subject: [PATCH 3/4] fix: ln --- gui/solverlib/solver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/solverlib/solver.py b/gui/solverlib/solver.py index bd670d5..24d26d4 100644 --- a/gui/solverlib/solver.py +++ b/gui/solverlib/solver.py @@ -17,7 +17,7 @@ def link_solver(self, path: Path = Path(__file__).parent.parent.parent / "cmake- if self.exe_path.exists(): self.exe_path.unlink() - path.symlink_to(self.exe_path) + self.exe_path.symlink_to(path) def solve(self, board: Board, timeout: int = 60) -> str: # Write the board to a file From 146140910d47005de16872a572cf6684137fe950 Mon Sep 17 00:00:00 2001 From: Ozeliurs Date: Fri, 16 Feb 2024 15:44:26 +0100 Subject: [PATCH 4/4] feat: move tmp board to tmp --- gui/solverlib/solver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/solverlib/solver.py b/gui/solverlib/solver.py index 24d26d4..aa22153 100644 --- a/gui/solverlib/solver.py +++ b/gui/solverlib/solver.py @@ -21,7 +21,7 @@ def link_solver(self, path: Path = Path(__file__).parent.parent.parent / "cmake- def solve(self, board: Board, timeout: int = 60) -> str: # Write the board to a file - board_path = Path(__file__).parent / f"board.{board.hash()}.txt" + board_path = Path(__file__).parent.parent / f"tmp/board.{board.hash()}.txt" board_path.write_text(board.to_csv()) # Run the solver