return Err("Internal error: get_ai_choice() iterated to SlotChoice::Invalid".into());
}
if let Some(utility) = get_utility_for_slot(player, slot, board) {
- utilities.push(utility);
+ utilities.push((i, utility));
}
}
}
// shuffle utilities for the cases where there are equivalent utilities
- let mut utilities: Vec<(usize, f64)> = utilities.into_iter().enumerate().collect();
if utilities.len() > 1 {
for i in 1..utilities.len() {
utilities.swap(i, rng.rand_range(0..((i + 1) as u32)) as usize);
if let Err(e) = text_append_result {
log::warn!("ERROR: text append to info_text0 failed: {}", e);
}
+ shared
+ .game_state
+ .replace(GameState::PostGameResults(BoardState::Empty));
} else {
// a player won
let turn = Turn::from(endgame_state);
log::warn!("ERROR: text append to info_text0 failed: {}", e);
}
+ shared
+ .game_state
+ .replace(GameState::PostGameResults(turn.into()));
+
match win_type {
WinType::Horizontal(idx) => {
let placed_class_erase_result = element_remove_class(
shared.board[idx + 3 + 3 * (COLS as usize)].get().into_win(),
);
}
- WinType::None => todo!(),
+ WinType::None => unreachable!("WinType should never be None on win"),
}
}
{
if shared.turn.get() != player_type {
// get AI's choice
- let choice = get_ai_choice(ai_difficulty, Turn::CyanPlayer, &shared.board)
- .expect("AI should have an available choice");
+ let choice =
+ get_ai_choice(ai_difficulty, player_type.get_opposite(), &shared.board)
+ .expect("AI should have an available choice");
ctx.link()
.send_message(WrapperMsg::Pressed(usize::from(choice) as u8));
}