diff --git a/P2.py b/P2.py index a5fd1b7..6230a81 100644 --- a/P2.py +++ b/P2.py @@ -34,11 +34,19 @@ class Field: # 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 + collisions = 0 + for i, row_i in enumerate(current_state): + for j, row_j in enumerate(current_state): + if j is not i: + # horizontal diagonal in both directions and counting twice + if row_i == row_j or row_j == (row_i + (j-i)) or row_j == (row_i - (j-i)): + collisions += 1 + return collisions def main(): new_field = Field() new_field.print_field() + print(new_field.collisions(new_field.get_state())) main() \ No newline at end of file