diff --git a/src/azul.rs b/src/azul.rs index 642578c..6bab061 100644 --- a/src/azul.rs +++ b/src/azul.rs @@ -154,48 +154,6 @@ impl GameState { Ok(()) } - - /// Calculates end-of-game bonus - fn bonus_score(player: &Player) -> Result { - 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 { + 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)]