formated a document

This commit is contained in:
Heli-o 2023-12-29 16:35:56 +01:00
parent 81a597fc19
commit 6d0b218dc3

View file

@ -2,6 +2,7 @@ import copy
import math
from PIL import Image, ImageDraw
class Board:
def __init__(self, size=0):
self.size = size
@ -35,12 +36,14 @@ class Board:
self._colors[9] = "#FA7921" # pumpkin
self._colors[10] = "#566E3D" # dark olive green
def inBoard(self, p, q):
"""return True if (p,q) is valid coordinate"""
return (q>= 0) and (q < self.size) and (p >= -(q//2)) and (p < (self.size - q//2))
return (
(q >= 0)
and (q < self.size)
and (p >= -(q // 2))
and (p < (self.size - q // 2))
)
def rotateRight(self, p, q):
pp = -q
@ -52,11 +55,8 @@ class Board:
qq = -p
return pp, qq
def saveImage(self, filename):
""" draw actual board to png
"""
"""draw actual board to png"""
cellRadius = 60
cellWidth = int(cellRadius * (3**0.5))
@ -65,13 +65,12 @@ class Board:
width = cellWidth * self.size + cellRadius * 3
height = cellHeight * self.size
img = Image.new('RGB',(width,height),"white")
img = Image.new("RGB", (width, height), "white")
draw = ImageDraw.Draw(img)
lineColor = (50, 50, 50)
for p in self.board:
for q in self.board[p]:
cx = cellRadius * (math.sqrt(3) * p + math.sqrt(3) / 2 * q) + cellRadius
@ -91,10 +90,11 @@ class Board:
pts.append(pts[0])
pts.append(pts[1])
draw.line(pts, fill="black", width=1)
draw.text([cx-3,cy-3], "{} {}".format(p,q), fill="black", anchor="m")
draw.text(
[cx - 3, cy - 3], "{} {}".format(p, q), fill="black", anchor="m"
)
img.save(filename)
def loadBoard(self, filename):
board = {}
fread = open(filename, "rt")
@ -109,7 +109,9 @@ class Board:
self.board = board
self.size = size + 1
import sys
# alternativa: nacteni ze souboru
b = Board()
b.loadBoard(sys.argv[1])
@ -125,6 +127,8 @@ for p in b.board:
spider_q = q
smer = ((0, -1), (1, -1), (1, 0), (0, 1), (-1, 1), (-1, 0))
def okoli(b, p, q):
o = [0] * 6
for i in range(6):
@ -135,14 +139,18 @@ def okoli(b, p, q):
o[i] = -1
return o
def spider_tah1(p, q, o):
mozne_tahy = []
for i in range(6):
if o[i]==0 and ((o[(i-1)%6]==0 and o[(i+1)%6]==1)
or(o[(i-1)%6]==1 and o[(i+1)%6]==0)):
if o[i] == 0 and (
(o[(i - 1) % 6] == 0 and o[(i + 1) % 6] == 1)
or (o[(i - 1) % 6] == 1 and o[(i + 1) % 6] == 0)
):
mozne_tahy.append([p + smer[i][0], q + smer[i][1]])
return mozne_tahy
o_spider = okoli(b, spider_p, spider_q)
print(o_spider)
@ -173,13 +181,3 @@ for i in range(3):
pos = pos2
pos2.sort()
print(pos2)