Compare commits
2 commits
27fc08c47d
...
3d01e8fe06
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d01e8fe06 | ||
|
|
4fd1f00af0 |
|
|
@ -58,12 +58,17 @@ impl GameRunner {
|
|||
}
|
||||
|
||||
pub fn handle_event(&mut self, event: &GameEvent) -> Option<GameEvent> {
|
||||
if !self.state.validate(event) {
|
||||
println!("event not valid : {:?}", event);
|
||||
if event == &GameEvent::PlayError {
|
||||
return None;
|
||||
}
|
||||
// println!("consuming {:?}", event);
|
||||
self.state.consume(event);
|
||||
let valid_event = if self.state.validate(event) {
|
||||
self.state.consume(event);
|
||||
event
|
||||
} else {
|
||||
println!("{}", self.state);
|
||||
println!("event not valid : {:?}", event);
|
||||
&GameEvent::PlayError
|
||||
};
|
||||
|
||||
// chain all successive bot actions
|
||||
if self.bots.is_empty() {
|
||||
|
|
@ -74,7 +79,7 @@ impl GameRunner {
|
|||
let bot_events: Vec<GameEvent> = self
|
||||
.bots
|
||||
.iter_mut()
|
||||
.filter_map(|bot| bot.handle_event(event))
|
||||
.filter_map(|bot| bot.handle_event(valid_event))
|
||||
.collect();
|
||||
|
||||
// if bot_events.len() > 1 {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import trictrac
|
||||
import store
|
||||
# import trictrac
|
||||
|
||||
game = trictrac.TricTrac()
|
||||
game = store.TricTrac()
|
||||
print(game.get_state()) # "Initial state"
|
||||
|
||||
moves = game.get_available_moves()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import gymnasium as gym
|
||||
import numpy as np
|
||||
from gymnasium import spaces
|
||||
import trictrac # module Rust exposé via PyO3
|
||||
# import trictrac # module Rust exposé via PyO3
|
||||
import store # module Rust exposé via PyO3
|
||||
from typing import Dict, List, Tuple, Optional, Any, Union
|
||||
|
||||
class TricTracEnv(gym.Env):
|
||||
|
|
@ -13,7 +14,7 @@ class TricTracEnv(gym.Env):
|
|||
super(TricTracEnv, self).__init__()
|
||||
|
||||
# Instancier le jeu
|
||||
self.game = trictrac.TricTrac()
|
||||
self.game = store.TricTrac()
|
||||
|
||||
# Stratégie de l'adversaire
|
||||
self.opponent_strategy = opponent_strategy
|
||||
|
|
|
|||
|
|
@ -331,6 +331,9 @@ impl GameState {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
PlayError => {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// We couldn't find anything wrong with the event so it must be good
|
||||
|
|
@ -479,6 +482,7 @@ impl GameState {
|
|||
TurnStage::RollDice
|
||||
};
|
||||
}
|
||||
PlayError => {}
|
||||
}
|
||||
self.history.push(valid_event.clone());
|
||||
}
|
||||
|
|
@ -620,6 +624,7 @@ pub enum GameEvent {
|
|||
player_id: PlayerId,
|
||||
moves: (CheckerMove, CheckerMove),
|
||||
},
|
||||
PlayError,
|
||||
}
|
||||
|
||||
impl GameEvent {
|
||||
|
|
|
|||
Loading…
Reference in a new issue