use clap::{Parser, Subcommand};
use cliard24::{
expression::ast::ExprNum,
tui::{game_mode::run_game_mode, solve_mode::run_solver_mode},
};
#[derive(Parser, Debug)]
#[command(
version,
author = "Expien1",
about = "cliard24 - A command-line 24-point card game with interactive play and expression solving capabilities.",
long_about = "cliard24 is a command-line 24-point card game. \
It provides two main functions: the game mode allows you to play the classic 24-point game interactively \
in the terminal, where you randomly draw 4 cards and use addition, subtraction, multiplication, division, \
and parentheses to reach 24; the solver mode lets you input any combination of numbers and a target value \
to calculate all possible expression solutions. The tool supports customizable attempt limits, endless mode, \
solution count limits, and mixed input of card letters (A/J/Q/K) and numbers."
)]
pub struct Cli {
#[command(subcommand)]
pub mode: Option<Mode>,
}
#[derive(Subcommand, Debug)]
pub enum Mode {
#[command(about = "Start a new interactive 24-point game")]
Play {
#[arg(short, long, default_value_t = 3)]
max_attempts: u8,
#[arg(short, long, default_value_t = 1)]
limit: usize,
#[arg(short, long, default_value_t = false)]
endless: bool,
},
#[command(about = "Find solutions for specific card combinations")]
Solve {
#[arg(required = true, num_args = 2..)]
nums: Vec<ExprNum>,
#[arg(short, long, default_value_t = 0)]
limit: usize,
#[arg(short, long, default_value_t = 24.0)]
target: ExprNum,
},
}
fn main() {
let cli = Cli::parse();
match cli.mode {
Some(Mode::Play {
max_attempts,
limit,
endless,
}) => {
if endless {
print_title("ENDLESS MODE");
} else {
print_title("WELCOME TO");
}
run_game_mode(max_attempts, limit, endless);
}
Some(Mode::Solve {
nums,
limit,
target,
}) => {
print_title("SOLVE MODE");
run_solver_mode(&nums, limit, target);
}
None => {
print_title(env!("CARGO_PKG_VERSION"));
run_game_mode(3, 1, false);
}
};
}
fn print_title(sub_title: &str) {
println!(
r#"
____ _ _ {:>12} _ .------..------.
/ ___| (_) __ _ _ __ __| ||2.--. ||4.--. |
| | | | |/ _` | '__/ _` || :/\: || (\/) |
| |___| | | (_| | | | (_| || (__) || :\/: |
\____|_|_|\__,_|_| \__,_|| '--'2|| '--'4|
---- - - --- -- --- `------'`------'
"#,
sub_title
);
}