Fix scoring function
Co-authored-by: Daniel Olsen <daniel.olsen99@gmail.com>
This commit is contained in:
parent
fbdf776141
commit
9491bac9d6
29
src/azul.rs
29
src/azul.rs
|
@ -691,10 +691,9 @@ impl Player {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut sum = 0;
|
|
||||||
|
|
||||||
// Count connected tiles in the on the row
|
// Count connected tiles in the on the row
|
||||||
let mut count = 0;
|
let mut horizontal = 0;
|
||||||
let mut active = false;
|
let mut active = false;
|
||||||
for i in 0..5 {
|
for i in 0..5 {
|
||||||
if (row, i) == (row, column) {
|
if (row, i) == (row, column) {
|
||||||
|
@ -703,16 +702,17 @@ impl Player {
|
||||||
|
|
||||||
if active == true && wall[row][i] == false {
|
if active == true && wall[row][i] == false {
|
||||||
break;
|
break;
|
||||||
} else if wall[row][i] == false {
|
}
|
||||||
count = 0;
|
|
||||||
|
if wall[row][i] == false {
|
||||||
|
horizontal = 0;
|
||||||
} else {
|
} else {
|
||||||
count += 1
|
horizontal += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sum += count;
|
|
||||||
|
|
||||||
// Count connected tiles in the column
|
// Count connected tiles in the column
|
||||||
let mut count = 0;
|
let mut vertical = 0;
|
||||||
let mut active = false;
|
let mut active = false;
|
||||||
for i in 0..5 {
|
for i in 0..5 {
|
||||||
if (i, column) == (row, column) {
|
if (i, column) == (row, column) {
|
||||||
|
@ -721,15 +721,20 @@ impl Player {
|
||||||
|
|
||||||
if active == true && wall[i][column] == false {
|
if active == true && wall[i][column] == false {
|
||||||
break;
|
break;
|
||||||
} else if wall[i][column] == false {
|
}
|
||||||
count = 0;
|
|
||||||
|
if wall[i][column] == false {
|
||||||
|
vertical = 0;
|
||||||
} else {
|
} 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
|
/// Calculates end-of-game bonus
|
||||||
|
|
Loading…
Reference in New Issue