Fix scoring function

Co-authored-by: Daniel Olsen <daniel.olsen99@gmail.com>
This commit is contained in:
Eirik Witterso 2024-03-09 21:49:53 +01:00
parent fbdf776141
commit 7d1a2f8d4b
1 changed files with 17 additions and 12 deletions

View File

@ -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;
} else {
count += 1
}
}
sum += count;
return sum;
if wall[i][column] == false {
vertical = 0;
} else {
vertical += 1
}
}
match (horizontal, vertical) {
(h, 1) => h,
(1, v) => v,
(h, v) => h + v,
}
}
/// Calculates end-of-game bonus