From f94c6d9fe66141f02830da232baea52d7afcca50 Mon Sep 17 00:00:00 2001 From: Safak Date: Tue, 17 Jun 2025 19:08:34 +0200 Subject: [PATCH] collision count --- P2.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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