hive/engine/moves/
ladybug.rs1use crate::engine::{
2 grid::{coordinate::hex::Hex, Grid},
3 moves::extract_moves_from_paths,
4 rules::one_hive_rule,
5};
6
7pub fn ladybug_moves(grid: &Grid, hex: &Hex) -> Vec<Hex> {
8 let initial_path: Vec<Hex> = vec![*hex];
9 let paths: Vec<Vec<Hex>> = ladybug_moves_it(grid, hex, hex, initial_path);
10
11 extract_moves_from_paths(paths, 4)
12}
13
14fn ladybug_moves_it(grid: &Grid, hex: &Hex, initital_hex: &Hex, path: Vec<Hex>) -> Vec<Vec<Hex>> {
15 let mut _path = path;
16 let mut paths: Vec<Vec<Hex>> = Vec::new();
17
18 for neighbor in hex.neighbors() {
19 if !_path.contains(&neighbor)
20 && one_hive_rule(grid, initital_hex, &neighbor)
21 && (((_path.len() == 1 || _path.len() == 2) && grid.is_hex_occupied(&neighbor))
22 || (_path.len() == 3 && !grid.is_hex_occupied(&neighbor)))
23 {
24 let mut current_path = _path.clone();
25 current_path.push(neighbor);
26
27 if current_path.len() < 4 {
28 let mut new_paths = ladybug_moves_it(grid, &neighbor, initital_hex, current_path);
29 paths.append(&mut new_paths);
30 } else {
31 paths.push(current_path);
32 }
33 }
34 }
35
36 paths
37}