From 41688008758fe8f62f2b8506309da018a23ed4cf Mon Sep 17 00:00:00 2001 From: Jeff Wu Date: Sat, 5 Mar 2016 16:54:46 -0800 Subject: [PATCH] Initial commit --- .gitignore | 2 ++ Cargo.lock | 26 ++++++++++++++ Cargo.toml | 8 +++++ src/game.rs | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 14 ++++++++ 5 files changed, 148 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/game.rs create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c6262ea --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +target +*.swp diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..79018f4 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,26 @@ +[root] +name = "rust_hanabi" +version = "0.1.0" +dependencies = [ + "lazy_static 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "lazy_static" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "libc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rand" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..6eda067 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "rust_hanabi" +version = "0.1.0" +authors = ["Jeff Wu "] + +[dependencies] +rand = "*" +lazy_static = "0.1.*" diff --git a/src/game.rs b/src/game.rs new file mode 100644 index 0000000..aaf4a9f --- /dev/null +++ b/src/game.rs @@ -0,0 +1,98 @@ +use rand::{thread_rng, Rng}; +use std::collections::HashSet; +use std::collections::HashMap; +use std::fmt; + +// Type definitions + +pub type Color = &'static str; +pub type Value = i32; + +pub struct Card { + pub color: Color, + pub value: Value, +} +impl fmt::Debug for Card { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{} {}", self.color, self.value) + } +} + +pub type Pile = Vec; +pub type Hand = Vec; +pub type Player = i32; + +pub struct GameOptions { + pub num_players: i32, + pub hand_size: i32, + pub total_hints: i32, + pub total_lives: i32, +} + +// The state of a given player: all other players may see this +struct PlayerState { + hand: Hand, +} + +pub struct GameState { + pub deck: Pile, + // pub players: PlayerState, + // pub discard: Pile, + // pub fireworks: HashMap, + // // whose turn is it? + // pub next: Player, + // pub hints_remaining: i32, + // pub lives_remaining: i32, + // // only relevant when deck runs out + // pub turns_remaining: i32, +} + +impl GameState { + pub fn new(opts: GameOptions) -> GameState { + let deck = GameState::make_deck(); + GameState { + deck: deck, + } + } + + fn make_deck() -> Pile { + let mut deck: Pile = Vec::new(); + for color in COLORS.iter() { + for (value, count) in VALUE_COUNTS.iter() { + for _ in 0..*count { + deck.push(Card {color: color, value: *value}); + } + } + }; + thread_rng().shuffle(&mut deck[..]); + println!("Created deck: {:?}", deck); + deck + } +} + +lazy_static! { + static ref COLORS: HashSet = { + vec!["blue", "red", "yellow", "white", "green"].into_iter().collect::>() + }; + // map from value to count + static ref VALUE_COUNTS: HashMap = { + let mut map = HashMap::new(); + map.insert(1, 3); + map.insert(2, 2); + map.insert(3, 2); + map.insert(4, 2); + map.insert(5, 1); + map + }; +} + +fn validate_card(card: &Card) { +} + +trait Strategy { + fn decide(&self) -> f64; + fn update(&self) -> f64; +} + +fn simulate() { +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..9d53dc2 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,14 @@ +extern crate rand; +#[macro_use] +extern crate lazy_static; + +mod game; + +fn main() { + game::GameState::new(game::GameOptions { + num_players: 4, + hand_size: 4, + total_hints: 8, + total_lives: 3, + }); +}