From 50dff95ac48a03c2bcac3e1af61259f3cc43b8a2 Mon Sep 17 00:00:00 2001 From: tobiglaser <76131623+tobiglaser@users.noreply.github.com> Date: Tue, 4 Apr 2023 23:26:08 +0200 Subject: [PATCH] board to svg display working --- .gitignore | 1 + Acht-Damen.py | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6131751 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.svg \ No newline at end of file diff --git a/Acht-Damen.py b/Acht-Damen.py index 2fa7084..844eabb 100644 --- a/Acht-Damen.py +++ b/Acht-Damen.py @@ -1,6 +1,9 @@ import numpy as np from copy import deepcopy - +import chess +import chess.svg +from IPython.display import Image +from IPython.display import SVG class Board: blocked = 0 @@ -71,10 +74,36 @@ class Board: return True else: return False + + def display_chess_board(self) -> None: + string = "" + for row in range(self.dimY): + spaces = 0 + for column in range(self.dimX): + if self.board[column, row] == self.queen: + if spaces > 0: + string += str(spaces) + string += "q" + spaces = 0 + else: + spaces += 1 + if spaces > 0: + string += str(spaces) + if row < self.dimY-1: + string += "/" + + board = chess.Board(string) + boardsvg = chess.svg.board(board, size=350) + outputfile = open('temp.svg', "w") + outputfile.write(boardsvg) + outputfile.close() + display(SVG("temp.svg")) if __name__ == "__main__": board = Board(8, 8) + num_queens = 8 + solutions = [] saved_boards = [] iters = 0 @@ -85,3 +114,15 @@ if __name__ == "__main__": board.toConsole() saved_boards.append(board.copy()) print("Queens: " + str(iters)) + board.display_chess_board() + + + def recurse(board: Board, branch: int, depth: int) -> None: + # Anker: + + + oldBoard = board + workboard = board.copy() + # traversiere links + + \ No newline at end of file -- GitLab