Something went wrong. Try again.
Star Gambit Computer Player SDK
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193//! Game configuration and the base Star Gambit ruleset, ported from//! `base_config.dart` / `star_config.dart`.
use crate::hex::{self, Hex, HexFace, HexTransform};use crate::model::{KindOfUnit, Move, RayAttack};
/// Lightweight game parameters. Mirrors `StarConfig`.#[derive(Clone, Debug)]pub struct StarConfig { pub board_size: i32, pub counts: Vec<i32>,}
impl StarConfig { pub fn new(board_size: i32) -> StarConfig { StarConfig { board_size, counts: vec![3, 2, 1, 0], } }
pub fn with_counts(board_size: i32, counts: Vec<i32>) -> StarConfig { StarConfig { board_size, counts } }}
/// A pre-placed unit at game start. Mirrors `InitialPlacement`.#[derive(Clone, Debug)]pub struct InitialPlacement { pub kind_index: usize, pub player_index: i32, pub transform: HexTransform, pub initial_damage: i32,}
impl InitialPlacement { pub fn new(kind_index: usize, player_index: i32, transform: HexTransform) -> InitialPlacement { InitialPlacement { kind_index, player_index, transform, initial_damage: 0, } }}
/// Full game configuration. Mirrors `StarGambitConfig`. The notation is/// fixed (OGSGN) and so is not stored.#[derive(Clone, Debug)]pub struct StarGambitConfig { pub unit_kinds: Vec<KindOfUnit>, /// Placement options per unit-kind index (portal has none). pub placements: Vec<Vec<HexTransform>>, pub initial_placements: Vec<InitialPlacement>, pub counts: Vec<i32>, pub board_size: i32,}
impl StarGambitConfig { pub fn from_star_config(sc: &StarConfig) -> StarGambitConfig { let b = sc.board_size; let initial_placements = vec![ InitialPlacement::new(3, 0, HexTransform::from_translate(scale(hex::D, b))), InitialPlacement::new(3, 1, HexTransform::new(scale(hex::A, b), 3)), ]; Self::from_star_config_custom(sc, initial_placements) }
pub fn from_star_config_custom( sc: &StarConfig, initial_placements: Vec<InitialPlacement>, ) -> StarGambitConfig { StarGambitConfig { unit_kinds: base_units(), placements: base_placements(), initial_placements, counts: sc.counts.clone(), board_size: sc.board_size, } }}
fn scale(h: Hex, s: i32) -> Hex { Hex::new(h.x * s, h.y * s, h.z * s)}
/// The four base unit kinds, in canonical order:/// `[Fighter, Cruiser, Dreadnought, Portal]`. Mirrors `BaseStarGambit`.pub fn base_units() -> Vec<KindOfUnit> { vec![fighter(), cruiser(), dreadnought(), portal()]}
pub fn fighter() -> KindOfUnit { KindOfUnit { name: "Fighter".to_string(), body: vec![Hex::new(0, 0, 0)], move_: 2, ray_attacks: vec![RayAttack::new("bow", HexFace::A, Hex::ORIGIN)], moves: vec![ Move::new("forward", hex::A, 0), Move::new("Right", hex::B, 1), Move::new("Left", hex::F, 5), ], health: 3, }}
pub fn cruiser() -> KindOfUnit { KindOfUnit { name: "Cruiser".to_string(), body: vec![Hex::ORIGIN, hex::D], move_: 1, ray_attacks: vec![ RayAttack::new("L", HexFace::F, Hex::ORIGIN), RayAttack::new("F", HexFace::A, Hex::ORIGIN), RayAttack::new("R", HexFace::B, Hex::ORIGIN), ], moves: vec![ Move::new("a", hex::A, 0), Move::new("a", hex::B, 1), Move::new("a", hex::F, 5), Move::new("a", hex::C, 1), Move::new("a", hex::E, 5), ], health: 4, }}
pub fn dreadnought() -> KindOfUnit { KindOfUnit { name: "Dreadnought".to_string(), body: vec![Hex::ORIGIN, hex::D, hex::E], move_: 1, ray_attacks: vec![ RayAttack::new("L2", HexFace::A, hex::E), RayAttack::new("L1", HexFace::A, Hex::ORIGIN), RayAttack::new("R1", HexFace::B, Hex::ORIGIN), RayAttack::new("R2", HexFace::B, hex::D), ], moves: vec![ Move::new("a", hex::A, 0), Move::new("a", hex::B, 0), Move::new("a", hex::C, 1), Move::new("a", hex::F, 5), ], health: 6, }}
pub fn portal() -> KindOfUnit { KindOfUnit { name: "Portal".to_string(), body: vec![Hex::ORIGIN, hex::F, hex::B], move_: 0, ray_attacks: vec![], moves: vec![], health: 5, }}
/// Placement options per unit-kind index. Mirrors `BaseStarGambit.placements`/// (portal index 3 has no placements).pub fn base_placements() -> Vec<Vec<HexTransform>> { vec![ // fighter vec![ HexTransform::new(Hex::ORIGIN, 5), HexTransform::IDENTITY, HexTransform::new(Hex::ORIGIN, 1), ], // cruiser vec![ HexTransform::new(hex::F, -1), HexTransform::from_translate(hex::A), HexTransform::new(hex::B, 1), ], // dreadnought vec![ HexTransform::new(hex::F, -2), HexTransform::from_translate(hex::A), HexTransform::new(hex::A, -1), HexTransform::new(hex::B, 1), ], // portal (none) vec![], ]}
/// The standard Star Gambit config: board size 5, counts `[3,2,1,0]`.pub fn base_config() -> StarGambitConfig { StarGambitConfig::from_star_config(&StarConfig::new(5))}