ELASTIC WORDS (ELW) DocumentationHour 1: Cargo Setup & Memory Structures for Family Feud 2. Section 1: Project InitializationSet up the Rust environment and add the necessary dependencies. Verify the installation by running the initial build. cargo new family_feud cd family_feud cargo add ratatui crossterm rand cargo run Section 2: Core Data StructuresDefine the base models in main.rs. We use i8 for the PointPool to prevent integer underflow during calculations before clamping. use rand::Rng;
#[derive(Debug, Clone)]
pub struct PointPool {
pub aggro: i8,
pub comm: i8,
pub amor: i8,
pub prize: i8,
}
#[derive(Debug, Clone)]
pub enum EraModifier { Golden, Dark, None }
#[derive(Debug, Clone)]
pub enum Quirk {
Charismatic, Frugal, Fierce, Passionate, Visionary,
Peacemaker, Ruthless, Fertile, MidasTouch, Loyal,
}
#[derive(Debug, Clone)]
pub enum Fault {
Abrasive, Wasteful, Cowardly, Frigid, Gullible,
Traitorous, Reckless, Lustful, Slothful, Paranoid,
}
#[derive(Debug, Clone)]
pub struct FamilyMember {
pub name: String,
pub quirk: Quirk,
pub fault: Fault,
}
#[derive(Debug, Clone)]
pub struct Family {
pub members: Vec<FamilyMember>,
pub pool: PointPool,
pub active_era: EraModifier,
pub growth_rate: u8,
}
Section 3: Trait EnumerationsThese enums will be assigned to Family Members and influence the simulation's algorithmic weights.
Section 4: ImplementationImplement the clamping logic to strictly enforce the 0-15 bounds of the Golden Rule. impl PointPool {
pub fn new() -> Self {
Self {
aggro: 7,
comm: 7,
amor: 7,
prize: 7,
}
}
pub fn apply_modifier(&mut self, aggro_mod: i8, comm_mod: i8, amor_mod: i8, prize_mod: i8) {
self.aggro = (self.aggro + aggro_mod).clamp(0, 15);
self.comm = (self.comm + comm_mod).clamp(0, 15);
self.amor = (self.amor + amor_mod).clamp(0, 15);
self.prize = (self.prize + prize_mod).clamp(0, 15);
}
}
Section 5: TestingVerify that large modifiers do not bypass the integer limits by running the unit tests. #[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_point_pool_clamping() {
let mut pp = PointPool::new();
pp.apply_modifier(10, -10, 20, -20);
assert_eq!(pp.aggro, 15);
assert_eq!(pp.comm, 0);
assert_eq!(pp.amor, 15);
assert_eq!(pp.prize, 0);
}
}
Optimized for 800x600 resolution. |