diff --git a/10_Blackjack/rust/Cargo.toml b/10_Blackjack/rust/Cargo.toml new file mode 100644 index 00000000..1c2935d4 --- /dev/null +++ b/10_Blackjack/rust/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "rust" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +rand = "0.8.5" \ No newline at end of file diff --git a/10_Blackjack/rust/src/main.rs b/10_Blackjack/rust/src/main.rs new file mode 100644 index 00000000..8db2a0b3 --- /dev/null +++ b/10_Blackjack/rust/src/main.rs @@ -0,0 +1,105 @@ +use rand::{Rng, prelude::thread_rng}; +use std::{io}; + +//DATA +struct CARD { + name: String, + value: u8, +} +impl CARD { + +} +struct HAND { + cards: Vec, + total: u8, +} +impl HAND { + fn drawCard(deck: DECK) -> CARD { + //pull a random card from deck + + } +} +struct DECK { + cards: Vec, +} +struct PLAYER { + hand: HAND, +} + +struct GAME { + human_player: PLAYER, + computer_players: Vec, + dealer: PLAYER, + + deck: DECK, + discard_pile: DECK, +} +impl GAME { + fn start(num_players:u8) { + //ask user how many players there should be, not including them + let num_players = loop { + //input loop + + let mut raw_input = String::new(); // temporary variable for user input that can be parsed later + //print prompt + println!("How many other players should there by?"); + + //read user input from standard input, and store it to raw_input + raw_input.clear(); //clear input + io::stdin().read_line(&mut raw_input).expect( "CANNOT READ INPUT!"); + + //from input, try to read a number + match raw_input.trim().parse::() { + Ok(i) => break i, // this escapes the loop, returning i + Err(e) => { + println!("MEANINGLESS NUMBER. TRY AGAIN. {}", e.to_string().to_uppercase()); + continue; // run the loop again + } + }; + }; + + + } +} + +const card_names: [&str;13] = ["Ace","2","3","4","5","6","7","8","9","10","Jack","Queen","King"]; + +fn main() { + //DATA + //P(I,J) IS THE JTH CARD IN HAND I, Q(I) IS TOTAL OF HAND I + //C IS THE DECK BEING DEALT FROM, D IS THE DISCARD PILE, + //T(I) IS THE TOTAL FOR PLAYER I, S(I) IS THE TOTAL THIS HAND FOR + //PLAYER I, B(I) IS TH BET FOR HAND I + //R(I) IS THE LENGTH OF P(I,*) + + //print welcome message + welcome(); + + +} + +fn welcome() { + //welcome message + println!(" + BLACK JACK + CREATIVE COMPUTING MORRISTOWN, NEW JERSEY + \n\n\n"); +} + +fn instructions() { + println!(" + THIS IS THE GAME OF 21. AS MANY AS 7 PLAYERS MAY PLAY THE + GAME. ON EACH DEAL, BETS WILL BE ASKED FOR, AND THE + PLAYERS' BETS SHOULD BE TYPED IN. THE CARDS WILL THEN BE + DEALT, AND EACH PLAYER IN TURN PLAYS HIS HAND. THE + FIRST RESPONSE SHOULD BE EITHER 'D', INDICATING THAT THE + PLAYER IS DOUBLING DOWN, 'S', INDICATING THAT HE IS + STANDING, 'H', INDICATING HE WANTS ANOTHER CARD, OR '/', + INDICATING THAT HE WANTS TO SPLIT HIS CARDS. AFTER THE + INITIAL RESPONSE, ALL FURTHER RESPONSES SHOULD BE 'S' OR + 'H', UNLESS THE CARDS WERE SPLIT, IN WHICH CASE DOUBLING + DOWN IS AGAIN PERMITTED. IN ORDER TO COLLECT FOR + BLACKJACK, THE INITIAL RESPONSE SHOULD BE 'S'. + NUMBER OF PLAYERS + "); +} \ No newline at end of file