mahjong_core/ai/
best_drops.rs1use crate::{game_summary::GameSummary, PlayerId, TileId};
2
3use super::StandardAI;
4
5impl StandardAI<'_> {
6 pub fn get_best_drops(&self, player_id: &PlayerId) -> Option<Vec<TileId>> {
12 let game_clone = self.game.clone();
13 let game_summary = GameSummary::from_game(&game_clone, player_id)?;
14
15 if !game_summary.hand.clone().unwrap().can_drop_tile() {
16 return None;
17 }
18
19 struct TileDrop {
20 id: TileId,
21 score: usize,
22 }
23
24 let mut drops: Vec<TileDrop> = vec![];
25
26 for tile in game_summary.hand.unwrap().list.iter() {
27 if tile.set_id.is_some() {
28 drops.push(TileDrop {
29 id: tile.id,
30 score: 0,
31 });
32 }
33
34 }
37
38 drops.sort_by(|a, b| a.score.cmp(&b.score));
40
41 let best_drops = drops.iter().map(|drop| drop.id).collect::<Vec<TileId>>();
42
43 Some(best_drops)
44 }
45}