core_rust/core/game/
state.rs

1use crate::core::game::utils::actions;
2use actions::Action;
3use serde::{Deserialize, Serialize};
4
5/// MDP state: agent position plus available actions (optionally indexed).
6#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
7pub struct State {
8    pub unit_position: (usize, usize),
9    pub valid_moves: Vec<Action>,
10    pub index: Option<isize>,
11}
12
13impl State {
14    /// Create a new state at the given position with the provided action set.
15    pub fn new(unit_position: (usize, usize), valid_moves: Vec<Action>) -> Self {
16        Self {
17            unit_position,
18            valid_moves,
19            index: None,
20        }
21    }
22
23    /// Borrow the valid actions for this state.
24    pub fn valid_moves(&self) -> &Vec<Action> {
25        &self.valid_moves
26    }
27}