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