mercury/src/azul.rs

166 lines
3.3 KiB
Rust
Raw Normal View History

2021-01-02 02:25:39 +01:00
use std::ops::{Deref, DerefMut};
2021-01-01 23:07:16 +01:00
#[derive(Debug)]
enum Tile {
2021-01-02 01:30:02 +01:00
Start,
2021-01-01 23:07:16 +01:00
Blue,
Yellow,
Red,
Black,
Teal
}
#[derive(Debug)]
2021-01-02 02:25:39 +01:00
struct Bag (Vec<Tile>);
2021-01-01 23:07:16 +01:00
impl Default for Bag {
fn default() -> Self {
2021-01-02 02:25:39 +01:00
let mut bag = Vec::<Tile>::with_capacity(100);
for _ in 0..20 {
bag.push(Tile::Blue);
};
for _ in 0..20 {
bag.push(Tile::Yellow);
};
for _ in 0..20 {
bag.push(Tile::Red);
};
for _ in 0..20 {
bag.push(Tile::Black);
};
for _ in 0..20 {
bag.push(Tile::Teal);
};
Bag(bag)
2021-01-01 23:07:16 +01:00
}
}
2021-01-02 02:25:39 +01:00
impl Deref for Bag {
type Target = Vec<Tile>;
fn deref(&self) -> &Vec<Tile> {
&self.0
}
}
impl DerefMut for Bag {
fn deref_mut(&mut self) -> &mut Vec<Tile> {
&mut self.0
}
}
2021-01-01 23:07:16 +01:00
#[derive(Default, Debug)]
2021-01-02 02:25:39 +01:00
struct Factory (Vec<Tile>);
impl Deref for Factory {
type Target = Vec<Tile>;
fn deref(&self) -> &Vec<Tile> {
&self.0
}
}
impl DerefMut for Factory {
fn deref_mut(&mut self) -> &mut Vec<Tile> {
&mut self.0
}
2021-01-01 23:07:16 +01:00
}
2021-01-02 02:25:39 +01:00
2021-01-01 23:07:16 +01:00
#[derive(Debug)]
2021-01-02 02:25:39 +01:00
struct Market (Vec<Tile>);
2021-01-01 23:07:16 +01:00
impl Default for Market {
fn default() -> Self {
2021-01-02 02:25:39 +01:00
let mut market = Vec::<Tile>::with_capacity(20);
market.push(Tile::Start);
Market(market)
2021-01-01 23:07:16 +01:00
}
}
2021-01-02 02:25:39 +01:00
impl Deref for Market {
type Target = Vec<Tile>;
fn deref(&self) -> &Vec<Tile> {
&self.0
}
}
impl DerefMut for Market {
fn deref_mut(&mut self) -> &mut Vec<Tile> {
&mut self.0
}
}
2021-01-01 23:07:16 +01:00
#[derive(Debug, Default)]
2021-01-02 02:25:39 +01:00
struct PatternLine (Option<Tile>, u8);
type Patterns = [PatternLine; 5];
2021-01-01 23:07:16 +01:00
type Row = [bool; 5];
type Wall = [Row; 5];
#[derive(Debug)]
struct Board {
score: u8,
wall: Wall,
2021-01-02 02:25:39 +01:00
floor: Vec<PatternLine>,
2021-01-01 23:07:16 +01:00
patterns: Patterns,
}
impl Default for Board {
fn default() -> Self {
Board {
score: 0,
wall: Wall::default(),
2021-01-02 01:30:02 +01:00
floor: Vec::default(),
2021-01-01 23:07:16 +01:00
patterns: Patterns::default()
}
}
}
#[derive(Default, Debug)]
pub struct Game {
2021-01-02 01:30:02 +01:00
turn: u8,
player: u8,
2021-01-02 02:25:39 +01:00
box_top: Bag,
2021-01-01 23:07:16 +01:00
bag: Bag,
market: Market,
factories: Vec<Factory>,
boards: Vec<Board>
}
impl Game {
pub fn new(players: usize) -> Result<Self, &'static str> {
let n_factories = match players {
2 => 5,
3 => 7,
4 => 9,
_ => return Err("Not a valid amount of players")
};
let mut factories = Vec::<Factory>::with_capacity(n_factories);
for _ in 0..n_factories {
factories.push(Factory::default())
}
let mut boards = Vec::<Board>::with_capacity(players);
for _ in 0..players {
boards.push(Board::default());
}
let game = Game {
2021-01-02 01:30:02 +01:00
turn: 0,
player: 0,
2021-01-02 02:25:39 +01:00
box_top: Bag::default(),
2021-01-01 23:07:16 +01:00
bag: Bag::default(),
market: Market::default(),
factories: factories,
boards: boards
};
Ok(game)
}
2021-01-02 02:25:39 +01:00
pub fn fill(&mut self) -> Result<(), &'static str> {
for factory in &self.factories {
if factory.len() != 0 {
return Err("Cannot fill, factories are not empty")
};
};
Ok(())
}
// pub fn shop(&mut self, )
2021-01-01 23:07:16 +01:00
}