Function battleship_bot::valid_shot

source ·
pub fn valid_shot(shots: ShotMap, pos: Pos) -> bool
Expand description

Check if pos is a valid position for a shot in shots

Checks if pos is in range of the board and the position isn’t shot yet.

Example

use battleship_bot::*;
 
let mut shots = [[None; 10]; 10];
 
assert!(valid_shot(shots, pos!(0, 0)));
assert!(!valid_shot(shots, pos!(10, 0)));
assert!(!valid_shot(shots, pos!(10, 10)));
 
shots[3][5] = Some(Shot::Miss);
assert!(!valid_shot(shots, pos!(3, 5)));