battleship_bot 1.1.5

The game of battleship and a few bot implementations
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use crate::battleship::boat::Boat;
use crate::battleship::shot::Shot;
use crate::battleship::constants::ShotMap;

pub fn get_hits(shots: ShotMap) -> Vec<(Boat, usize, usize)> {
    let mut hits = vec![];

    for (x, column) in shots.iter().enumerate() {
        for (y, shot) in column.iter().enumerate() {
            if let Some(Shot::Hit(boat)) = shot {
                hits.push((*boat, x, y));
            }
        }
    }

    hits
}