Skip to content
Snippets Groups Projects
Commit 50dff95a authored by tobiglaser's avatar tobiglaser
Browse files

board to svg display working

parent b847bf97
No related branches found
No related tags found
No related merge requests found
*.svg
\ No newline at end of file
import numpy as np import numpy as np
from copy import deepcopy from copy import deepcopy
import chess
import chess.svg
from IPython.display import Image
from IPython.display import SVG
class Board: class Board:
blocked = 0 blocked = 0
...@@ -71,10 +74,36 @@ class Board: ...@@ -71,10 +74,36 @@ class Board:
return True return True
else: else:
return False 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__": if __name__ == "__main__":
board = Board(8, 8) board = Board(8, 8)
num_queens = 8
solutions = []
saved_boards = [] saved_boards = []
iters = 0 iters = 0
...@@ -85,3 +114,15 @@ if __name__ == "__main__": ...@@ -85,3 +114,15 @@ if __name__ == "__main__":
board.toConsole() board.toConsole()
saved_boards.append(board.copy()) saved_boards.append(board.copy())
print("Queens: " + str(iters)) 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment