improved arguments, updated lib and clap

This commit is contained in:
JOLIMAITRE Matthieu 2022-09-29 15:49:08 +02:00
parent 0080b94fd2
commit 544c261c3b
2 changed files with 13 additions and 13 deletions

View file

@ -9,6 +9,6 @@ repository = "https://github.com/MajorBarnulf/rs48"
homepage = "https://github.com/MajorBarnulf/rs48" homepage = "https://github.com/MajorBarnulf/rs48"
[dependencies] [dependencies]
clap = { version = "3.2", features = ["derive"] } clap = { version = "4.0", features = ["derive"] }
rs48_lib = "1.2" rs48_lib = "1.3"
rand = "0.8" rand = "0.8"

View file

@ -1,9 +1,9 @@
use std::{fmt::Display, str::FromStr, time::Duration}; use std::{fmt::Display, str::FromStr, time::Duration};
use clap::{ArgEnum, Parser}; use clap::Parser;
use rs48_lib::prelude::*; use rs48_lib::prelude::*;
#[derive(Clone, ArgEnum, Debug)] #[derive(Clone, Debug)]
pub enum ControllerParam { pub enum ControllerParam {
Player, Player,
Random, Random,
@ -42,7 +42,7 @@ pub struct Arguments {
size: usize, size: usize,
/// number of tiles that will spawn on the grid each turn /// number of tiles that will spawn on the grid each turn
#[clap(long, default_value_t = 1)] #[clap(short = 'w', long, default_value_t = 1)]
spawn: usize, spawn: usize,
/// disable clearing the terminal to refresh the screen /// disable clearing the terminal to refresh the screen
@ -50,15 +50,15 @@ pub struct Arguments {
no_clear: bool, no_clear: bool,
/// skips the refresh of that many turns, allow AIs to play faster /// skips the refresh of that many turns, allow AIs to play faster
#[clap(long, default_value_t = 0)] #[clap(short = 'k', long, default_value_t = 0)]
display_skips: usize, display_skips: usize,
/// delay in ms to add between each turns /// delay in ms to add between each turns
#[clap(long, default_value_t = 0)] #[clap(short, long, default_value_t = 0)]
delay: u64, delay: u64,
/// the controller to use for the game /// the controller to use for the game
#[clap(long, default_value_t = ControllerParam::Player)] #[clap(short, long, default_value_t = ControllerParam::Player)]
controller: ControllerParam, controller: ControllerParam,
/// sets a seed for the color pattern, 0 for random, default is 35 /// sets a seed for the color pattern, 0 for random, default is 35
@ -81,13 +81,13 @@ fn main() -> Result<(), GameError> {
.turn_duration(Duration::from_millis(arguments.delay)); .turn_duration(Duration::from_millis(arguments.delay));
let controller = match arguments.controller { let controller = match arguments.controller {
ControllerParam::Player => PlayerController::new().into_box(), ControllerParam::Player => PlayerController::default().into_box(),
ControllerParam::Random => RandomController::new().into_box(), ControllerParam::Random => RandomController::default().into_box(),
ControllerParam::Simulated => SimulatedController::new(80, 50).into_box(), ControllerParam::Simulated => SimulatedController::new(100, 20).into_box(),
}; };
let mut managed = GameManager::new(game_rules, manager_rules, controller); let mut managed = GameManager::new(game_rules, manager_rules, controller);
let err = managed.play_all();
err managed.play_all()
} }
fn seed_or_random(input: u16) -> u16 { fn seed_or_random(input: u16) -> u16 {