azul: move bonus score function to player

This commit is contained in:
Daniel Lovbrotte Olsen 2024-01-29 19:48:27 +01:00
parent 9f38d6612e
commit 4470f87654
1 changed files with 42 additions and 42 deletions

View File

@ -154,48 +154,6 @@ impl GameState {
Ok(())
}
/// Calculates end-of-game bonus
fn bonus_score(player: &Player) -> Result<usize, &'static str> {
let mut bonus = 0;
// Horizontal
for row in player.wall {
if row.iter().all(|&x| x == true) {
bonus += 2;
};
}
// Vertical
for column in 0..5 {
let mut tiles = 0;
for row in 0..5 {
if player.wall[row][column] == true {
tiles += 1;
}
}
if tiles == 5 {
bonus += 7
}
}
// 5 of a color
for color in Color::Blue.into_iter() {
let mut tiles = 0;
for row in 0..5 {
let index = Player::get_wall_index(row, color)?;
if player.wall[row][index] == true {
tiles += 1
}
}
if tiles == 5 {
bonus += 10;
}
}
return Ok(bonus);
}
}
#[derive(Debug, Serialize, Deserialize, Clone, Default, Copy)]
@ -382,6 +340,48 @@ impl Player {
return sum;
}
/// Calculates end-of-game bonus
fn bonus_score(&self) -> Result<usize, &'static str> {
let mut bonus = 0;
// Horizontal
for row in self.wall {
if row.iter().all(|&x| x == true) {
bonus += 2;
};
}
// Vertical
for column in 0..5 {
let mut tiles = 0;
for row in 0..5 {
if self.wall[row][column] == true {
tiles += 1;
}
}
if tiles == 5 {
bonus += 7
}
}
// 5 of a color
for color in Color::Blue.into_iter() {
let mut tiles = 0;
for row in 0..5 {
let index = Player::get_wall_index(row, color)?;
if self.wall[row][index] == true {
tiles += 1
}
}
if tiles == 5 {
bonus += 10;
}
}
return Ok(bonus);
}
}
#[derive(Debug, Serialize, Deserialize, Clone, Default)]