chore: fix deprecation warnings
This commit is contained in:
parent
8f8e7f958b
commit
54d9ad70ad
4 changed files with 20 additions and 20 deletions
|
|
@ -3,7 +3,7 @@ use std::io::Write;
|
||||||
use crate::training_common;
|
use crate::training_common;
|
||||||
use burn::{prelude::Backend, tensor::Tensor};
|
use burn::{prelude::Backend, tensor::Tensor};
|
||||||
use burn_rl::base::{Action, Environment, Snapshot, State};
|
use burn_rl::base::{Action, Environment, Snapshot, State};
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{rng, Rng};
|
||||||
use store::{GameEvent, GameState, PlayerId, PointsRules, Stage, TurnStage};
|
use store::{GameEvent, GameState, PlayerId, PointsRules, Stage, TurnStage};
|
||||||
|
|
||||||
const ERROR_REWARD: f32 = -1.0012121;
|
const ERROR_REWARD: f32 = -1.0012121;
|
||||||
|
|
@ -52,10 +52,10 @@ pub struct TrictracAction {
|
||||||
|
|
||||||
impl Action for TrictracAction {
|
impl Action for TrictracAction {
|
||||||
fn random() -> Self {
|
fn random() -> Self {
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{rng, Rng};
|
||||||
let mut rng = thread_rng();
|
let mut rng = rng();
|
||||||
TrictracAction {
|
TrictracAction {
|
||||||
index: rng.gen_range(0..Self::size() as u32),
|
index: rng.random_range(0..Self::size() as u32),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -288,8 +288,8 @@ impl TrictracEnvironment {
|
||||||
// reward += REWARD_VALID_MOVE;
|
// reward += REWARD_VALID_MOVE;
|
||||||
// Simuler le résultat des dés après un Roll
|
// Simuler le résultat des dés après un Roll
|
||||||
if matches!(action, TrictracAction::Roll) {
|
if matches!(action, TrictracAction::Roll) {
|
||||||
let mut rng = thread_rng();
|
let mut rng = rng();
|
||||||
let dice_values = (rng.gen_range(1..=6), rng.gen_range(1..=6));
|
let dice_values = (rng.random_range(1..=6), rng.random_range(1..=6));
|
||||||
let dice_event = GameEvent::RollResult {
|
let dice_event = GameEvent::RollResult {
|
||||||
player_id: self.active_player_id,
|
player_id: self.active_player_id,
|
||||||
dice: store::Dice {
|
dice: store::Dice {
|
||||||
|
|
@ -346,8 +346,8 @@ impl TrictracEnvironment {
|
||||||
player_id: self.opponent_id,
|
player_id: self.opponent_id,
|
||||||
},
|
},
|
||||||
TurnStage::RollWaiting => {
|
TurnStage::RollWaiting => {
|
||||||
let mut rng = thread_rng();
|
let mut rng = rng();
|
||||||
let dice_values = (rng.gen_range(1..=6), rng.gen_range(1..=6));
|
let dice_values = (rng.random_range(1..=6), rng.random_range(1..=6));
|
||||||
calculate_points = true;
|
calculate_points = true;
|
||||||
GameEvent::RollResult {
|
GameEvent::RollResult {
|
||||||
player_id: self.opponent_id,
|
player_id: self.opponent_id,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::training_common;
|
use crate::training_common;
|
||||||
use burn::{prelude::Backend, tensor::Tensor};
|
use burn::{prelude::Backend, tensor::Tensor};
|
||||||
use burn_rl::base::{Action, Environment, Snapshot, State};
|
use burn_rl::base::{Action, Environment, Snapshot, State};
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{rng, Rng};
|
||||||
use store::{GameEvent, GameState, PlayerId, PointsRules, Stage, TurnStage};
|
use store::{GameEvent, GameState, PlayerId, PointsRules, Stage, TurnStage};
|
||||||
|
|
||||||
const ERROR_REWARD: f32 = -1.0012121;
|
const ERROR_REWARD: f32 = -1.0012121;
|
||||||
|
|
@ -48,10 +48,10 @@ pub struct TrictracAction {
|
||||||
|
|
||||||
impl Action for TrictracAction {
|
impl Action for TrictracAction {
|
||||||
fn random() -> Self {
|
fn random() -> Self {
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{rng, Rng};
|
||||||
let mut rng = thread_rng();
|
let mut rng = rng();
|
||||||
TrictracAction {
|
TrictracAction {
|
||||||
index: rng.gen_range(0..Self::size() as u32),
|
index: rng.random_range(0..Self::size() as u32),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -258,8 +258,8 @@ impl TrictracEnvironment {
|
||||||
// reward += REWARD_VALID_MOVE;
|
// reward += REWARD_VALID_MOVE;
|
||||||
// Simuler le résultat des dés après un Roll
|
// Simuler le résultat des dés après un Roll
|
||||||
if matches!(action, TrictracAction::Roll) {
|
if matches!(action, TrictracAction::Roll) {
|
||||||
let mut rng = thread_rng();
|
let mut rng = rng();
|
||||||
let dice_values = (rng.gen_range(1..=6), rng.gen_range(1..=6));
|
let dice_values = (rng.random_range(1..=6), rng.random_range(1..=6));
|
||||||
let dice_event = GameEvent::RollResult {
|
let dice_event = GameEvent::RollResult {
|
||||||
player_id: self.active_player_id,
|
player_id: self.active_player_id,
|
||||||
dice: store::Dice {
|
dice: store::Dice {
|
||||||
|
|
@ -316,8 +316,8 @@ impl TrictracEnvironment {
|
||||||
player_id: self.opponent_id,
|
player_id: self.opponent_id,
|
||||||
},
|
},
|
||||||
TurnStage::RollWaiting => {
|
TurnStage::RollWaiting => {
|
||||||
let mut rng = thread_rng();
|
let mut rng = rng();
|
||||||
let dice_values = (rng.gen_range(1..=6), rng.gen_range(1..=6));
|
let dice_values = (rng.random_range(1..=6), rng.random_range(1..=6));
|
||||||
calculate_points = true;
|
calculate_points = true;
|
||||||
GameEvent::RollResult {
|
GameEvent::RollResult {
|
||||||
player_id: self.opponent_id,
|
player_id: self.opponent_id,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::{BotStrategy, CheckerMove, Color, GameState, PlayerId};
|
use crate::{BotStrategy, CheckerMove, Color, GameState, PlayerId};
|
||||||
|
use rand::{prelude::IndexedRandom, rng};
|
||||||
use store::MoveRules;
|
use store::MoveRules;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -51,8 +52,7 @@ impl BotStrategy for RandomStrategy {
|
||||||
let rules = MoveRules::new(&self.color, &self.game.board, self.game.dice);
|
let rules = MoveRules::new(&self.color, &self.game.board, self.game.dice);
|
||||||
let possible_moves = rules.get_possible_moves_sequences(true, vec![]);
|
let possible_moves = rules.get_possible_moves_sequences(true, vec![]);
|
||||||
|
|
||||||
use rand::{seq::SliceRandom, thread_rng};
|
let mut rng = rng();
|
||||||
let mut rng = thread_rng();
|
|
||||||
let choosen_move = possible_moves
|
let choosen_move = possible_moves
|
||||||
.choose(&mut rng)
|
.choose(&mut rng)
|
||||||
.cloned()
|
.cloned()
|
||||||
|
|
|
||||||
|
|
@ -324,10 +324,10 @@ pub fn get_valid_action_indices(game_state: &crate::GameState) -> Vec<usize> {
|
||||||
|
|
||||||
/// Sélectionne une action valide aléatoire
|
/// Sélectionne une action valide aléatoire
|
||||||
pub fn sample_valid_action(game_state: &crate::GameState) -> Option<TrictracAction> {
|
pub fn sample_valid_action(game_state: &crate::GameState) -> Option<TrictracAction> {
|
||||||
use rand::{seq::SliceRandom, thread_rng};
|
use rand::{prelude::IndexedRandom, rng};
|
||||||
|
|
||||||
let valid_actions = get_valid_actions(game_state);
|
let valid_actions = get_valid_actions(game_state);
|
||||||
let mut rng = thread_rng();
|
let mut rng = rng();
|
||||||
valid_actions.choose(&mut rng).cloned()
|
valid_actions.choose(&mut rng).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue