From 9491bac9d6e8cfcbcfcb0cd895cc55e7942eeb0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eirik=20Witters=C3=B8?= Date: Sat, 9 Mar 2024 21:49:53 +0100 Subject: [PATCH] Fix scoring function Co-authored-by: Daniel Olsen --- src/azul.rs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/azul.rs b/src/azul.rs index de3e6a7..a116760 100644 --- a/src/azul.rs +++ b/src/azul.rs @@ -691,10 +691,9 @@ impl Player { return 0; } - let mut sum = 0; // Count connected tiles in the on the row - let mut count = 0; + let mut horizontal = 0; let mut active = false; for i in 0..5 { if (row, i) == (row, column) { @@ -703,16 +702,17 @@ impl Player { if active == true && wall[row][i] == false { break; - } else if wall[row][i] == false { - count = 0; + } + + if wall[row][i] == false { + horizontal = 0; } else { - count += 1 + horizontal += 1 } } - sum += count; // Count connected tiles in the column - let mut count = 0; + let mut vertical = 0; let mut active = false; for i in 0..5 { if (i, column) == (row, column) { @@ -721,15 +721,20 @@ impl Player { if active == true && wall[i][column] == false { break; - } else if wall[i][column] == false { - count = 0; + } + + if wall[i][column] == false { + vertical = 0; } else { - count += 1 + vertical += 1 } } - sum += count; - return sum; + match (horizontal, vertical) { + (h, 1) => h, + (1, v) => v, + (h, v) => h+v, + } } /// Calculates end-of-game bonus