Initial commit
This commit is contained in:
commit
4168800875
5 changed files with 148 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
target
|
||||
*.swp
|
26
Cargo.lock
generated
Normal file
26
Cargo.lock
generated
Normal file
|
@ -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)",
|
||||
]
|
||||
|
8
Cargo.toml
Normal file
8
Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "rust_hanabi"
|
||||
version = "0.1.0"
|
||||
authors = ["Jeff Wu <wuthefwasthat@gmail.com>"]
|
||||
|
||||
[dependencies]
|
||||
rand = "*"
|
||||
lazy_static = "0.1.*"
|
98
src/game.rs
Normal file
98
src/game.rs
Normal file
|
@ -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<Card>;
|
||||
pub type Hand = Vec<Card>;
|
||||
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<Color, Pile>,
|
||||
// // 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<Color> = {
|
||||
vec!["blue", "red", "yellow", "white", "green"].into_iter().collect::<HashSet<_,_>>()
|
||||
};
|
||||
// map from value to count
|
||||
static ref VALUE_COUNTS: HashMap<Value, i32> = {
|
||||
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() {
|
||||
}
|
14
src/main.rs
Normal file
14
src/main.rs
Normal file
|
@ -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,
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue