P2 init des Schachbretts und Visualisierung in der Ausgabe
This commit is contained in:
44
P2.py
Normal file
44
P2.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import random
|
||||
|
||||
class Field:
|
||||
def __init__(self, init_state=None):
|
||||
self.state = []
|
||||
|
||||
if init_state is None:
|
||||
for i in range(8):
|
||||
self.state.append(random.randint(1,8)) # row number (0:8] => [1:8]
|
||||
else:
|
||||
self.state = init_state.copy()
|
||||
|
||||
def print_field(self):
|
||||
print(" ┌───┬───┬───┬───┬───┬───┬───┬───┐")
|
||||
for row in range(8,0,-1): # (0:8]
|
||||
row_string = ""
|
||||
for line in range(8):
|
||||
if row is self.state[line]: # is there a Queen in this line (spalte) in this row
|
||||
row_string += "Q │ "
|
||||
else:
|
||||
row_string += " │ "
|
||||
print(f"{row} | {row_string}")
|
||||
if row > 1 : print(" ├───┼───┼───┼───┼───┼───┼───┼───┤")
|
||||
|
||||
print(" └───┴───┴───┴───┴───┴───┴───┴───┘")
|
||||
print(" A B C D E F G H ")
|
||||
|
||||
print(self.state)
|
||||
|
||||
def get_state(self):
|
||||
return self.state
|
||||
|
||||
def collisions(self, current_state):
|
||||
# wagerechte haben die gleiche zahl stehe
|
||||
# diagonale haben einen wert der um den abstand gemindert ist => gleichseitiges rechtwinkliges Dreieck
|
||||
# Beachte die Spalten/ Linien Nr ist um eins verringert [0, 1, ...,7]
|
||||
return 0
|
||||
|
||||
|
||||
def main():
|
||||
new_field = Field()
|
||||
new_field.print_field()
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user