From: Stephen Seo Date: Thu, 10 Mar 2022 07:44:01 +0000 (+0900) Subject: More AI tweaks X-Git-Tag: sprint_02_day_4~3 X-Git-Url: https://git.seodisparate.com/stephenseo/static/UDPC_8h_source.html?a=commitdiff_plain;h=38e7772d4f78601ba570bfca8083989a9be91f36;p=EN605.607.81.SP22_ASDM_Project More AI tweaks --- diff --git a/front_end/src/ai.rs b/front_end/src/ai.rs index 1c0d825..8640f5d 100644 --- a/front_end/src/ai.rs +++ b/front_end/src/ai.rs @@ -1,8 +1,9 @@ use std::collections::BTreeMap; use crate::constants::{AI_EASY_MAX_CHOICES, AI_NORMAL_MAX_CHOICES, COLS, ROWS}; +use crate::game_logic::check_win_draw; use crate::random_helper::get_seeded_random; -use crate::state::{BoardState, BoardType, Turn}; +use crate::state::{board_deep_clone, BoardState, BoardType, Turn}; #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum AIDifficulty { @@ -190,6 +191,18 @@ fn get_utility_for_slot(player: Turn, slot: SlotChoice, board: &BoardType) -> Op } } + // check if placing a token here allows the opposing player to win + if idx >= COLS as usize { + let cloned_board = board_deep_clone(board); + cloned_board[idx].replace(player.into()); + cloned_board[idx - (COLS as usize)].replace(player.get_opposite().into()); + if let Some((state, _)) = check_win_draw(&cloned_board) { + if state == player.get_opposite().into() { + utility *= 0.1; + } + } + } + Some(utility) }