From 28c57d67ebd423aa46bf777f8456edea18af5ffe Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 16:53:40 -0700 Subject: [PATCH 001/113] Update .gitignore for .DS_Store --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 238d56c..79d7431 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ mkfs/mkfs kernel/kernel user/usys.S .gdbinit +.DS_Store From 05da80ff488da3a927d4df52fbbe5ae88563caa9 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:35:38 -0700 Subject: [PATCH 002/113] add textGame.c redoing from the repo i use for labs to here --- user/textGame.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 user/textGame.c diff --git a/user/textGame.c b/user/textGame.c new file mode 100644 index 0000000..e69de29 From 16e58841f4c9a86ba661786f0db1ef4903e8ec06 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:39:34 -0700 Subject: [PATCH 003/113] Update textGame.c add main, and some includes --- user/textGame.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index e69de29..0396aea 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -0,0 +1,10 @@ +#include "kernel/types.h" +#include "kernel/stat.h" +#include "kernel/fs.h" +#include "kernel/fcntl.h" +#include "user/user.h" + +int main() { + + return 0; +} \ No newline at end of file From 4ac636427332cd195264012e55f1805d2f6e2a06 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:41:06 -0700 Subject: [PATCH 004/113] add function to use for randomness --- user/textGame.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index 0396aea..cf0c8cf 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -4,6 +4,9 @@ #include "kernel/fcntl.h" #include "user/user.h" +int LCG(){// function that generates a psuedorandom number, using the previous value in the sequence, which starts at a seed + return 0; +} int main() { return 0; From 371949c5deb319e56ad01d8361730864fe924b2c Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:42:10 -0700 Subject: [PATCH 005/113] add params to LCG --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index cf0c8cf..2122295 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -4,7 +4,7 @@ #include "kernel/fcntl.h" #include "user/user.h" -int LCG(){// function that generates a psuedorandom number, using the previous value in the sequence, which starts at a seed +int LCG(long a, long c, long m, long prev){// function that generates a psuedorandom number, using the previous value in the sequence, which starts at a seed return 0; } int main() { From 1a86c07108114aac4f4a96465d69405a695cd065 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:43:33 -0700 Subject: [PATCH 006/113] do hardcoded values instead of parameters --- user/textGame.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 2122295..ab4db0d 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -4,7 +4,10 @@ #include "kernel/fcntl.h" #include "user/user.h" -int LCG(long a, long c, long m, long prev){// function that generates a psuedorandom number, using the previous value in the sequence, which starts at a seed +int LCG(int prev){// function that generates a psuedorandom number, using the previous value in the sequence, which starts at a seed + long a = 0; + long c = 0; + long m = 0; return 0; } int main() { From ea1bd19df838ef3db17a31bb3c53a583fb2f6816 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:44:09 -0700 Subject: [PATCH 007/113] Add actual algorithm --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index ab4db0d..1486051 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -8,7 +8,7 @@ int LCG(int prev){// function that generates a psuedorandom number, using the pr long a = 0; long c = 0; long m = 0; - return 0; + return (a*prev+c)%m; } int main() { From 7f49e81ddc0a8711bd953972350f46e443ad7a98 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:45:47 -0700 Subject: [PATCH 008/113] prev between 0 and m --- user/textGame.c | 1 + 1 file changed, 1 insertion(+) diff --git a/user/textGame.c b/user/textGame.c index 1486051..10a0709 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -5,6 +5,7 @@ #include "user/user.h" int LCG(int prev){// function that generates a psuedorandom number, using the previous value in the sequence, which starts at a seed + prev = prev % m; long a = 0; long c = 0; long m = 0; From 06dadc4ef33a0c3c3bfa56858786ec3a127ed6d4 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:47:01 -0700 Subject: [PATCH 009/113] add values from chart --- user/textGame.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index 10a0709..05ed526 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -6,10 +6,11 @@ int LCG(int prev){// function that generates a psuedorandom number, using the previous value in the sequence, which starts at a seed prev = prev % m; - long a = 0; - long c = 0; - long m = 0; - return (a*prev+c)%m; + //https://www.ams.org/journals/mcom/1999-68-225/S0025-5718-99-00996-5/S0025-5718-99-00996-5.pdf has table of values + long a = 530877178; + long c = 0;//c = 0, since it is what the chart has + long m = 536870909;// 2^29 -3 + return (a*prev+c)%m; } int main() { From e0f0dad93e0a2a9e20cebdf110182cb6ccd41207 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:47:36 -0700 Subject: [PATCH 010/113] add some starting values --- user/textGame.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 05ed526..91c89e5 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -13,6 +13,7 @@ int LCG(int prev){// function that generates a psuedorandom number, using the pr return (a*prev+c)%m; } int main() { - + int coins = 100;//starting Coins + int stuff = 12;//starting stuff return 0; } \ No newline at end of file From 52e2270e54aee3169ff7a07f0118e52bf715ed81 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:48:51 -0700 Subject: [PATCH 011/113] update gametest with comment on source --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 91c89e5..4f1c8a3 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -12,7 +12,7 @@ int LCG(int prev){// function that generates a psuedorandom number, using the pr long m = 536870909;// 2^29 -3 return (a*prev+c)%m; } -int main() { +int main() {// a reimplementation of a simple casino game I wrote in python a while ago int coins = 100;//starting Coins int stuff = 12;//starting stuff return 0; From 5805e21cb607b6de3eb5d731b60d3d7720b9c49e Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:49:53 -0700 Subject: [PATCH 012/113] main game loop --- user/textGame.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index 4f1c8a3..1cb869a 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -13,7 +13,10 @@ int LCG(int prev){// function that generates a psuedorandom number, using the pr return (a*prev+c)%m; } int main() {// a reimplementation of a simple casino game I wrote in python a while ago - int coins = 100;//starting Coins - int stuff = 12;//starting stuff + int coins = 100;//starting Coins + int stuff = 12;//starting stuff + while (coins >= 0){//keep going while coins <= 0, not < because allows you to sell stuff at 0 + + } return 0; } \ No newline at end of file From eb2373063b89ca7f6e45c88964d42560a11a6141 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:51:46 -0700 Subject: [PATCH 013/113] get the bet from user --- user/textGame.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 1cb869a..5cb3b31 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -15,8 +15,10 @@ int LCG(int prev){// function that generates a psuedorandom number, using the pr int main() {// a reimplementation of a simple casino game I wrote in python a while ago int coins = 100;//starting Coins int stuff = 12;//starting stuff + char *betInput = malloc(128*sizeof(char));// a var for holding the bet while (coins >= 0){//keep going while coins <= 0, not < because allows you to sell stuff at 0 - + printf("how much to bet (type leave to leave the casino)"); + gets(betInput, 128); } return 0; } \ No newline at end of file From c216fa0b6e72213565327c9e42d2f963d121dd87 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:52:32 -0700 Subject: [PATCH 014/113] handle leaving --- user/textGame.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index 5cb3b31..65e46b4 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -19,6 +19,9 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh while (coins >= 0){//keep going while coins <= 0, not < because allows you to sell stuff at 0 printf("how much to bet (type leave to leave the casino)"); gets(betInput, 128); + if (strcmp(bet, "leave")){//handle input of leave + + } } return 0; } \ No newline at end of file From a20d65fea7542bc62e9472f1892431d0f362f528 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:52:53 -0700 Subject: [PATCH 015/113] break when leaving --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 65e46b4..f599850 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -20,7 +20,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("how much to bet (type leave to leave the casino)"); gets(betInput, 128); if (strcmp(bet, "leave")){//handle input of leave - + break; } } return 0; From bbeac3c4fb72f4d17d20f3eacfe48cbbbb6ba16e Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:53:26 -0700 Subject: [PATCH 016/113] create function to check if bet is valid --- user/textGame.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index f599850..7a83849 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -12,6 +12,8 @@ int LCG(int prev){// function that generates a psuedorandom number, using the pr long m = 536870909;// 2^29 -3 return (a*prev+c)%m; } +int isValidBet(char *bet){ +} int main() {// a reimplementation of a simple casino game I wrote in python a while ago int coins = 100;//starting Coins int stuff = 12;//starting stuff From 176f64aab4e783b165f938a8b1bc6dd55b0ab11b Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:54:15 -0700 Subject: [PATCH 017/113] prevent negative bets --- user/textGame.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index 7a83849..e5f7cb3 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -13,6 +13,10 @@ int LCG(int prev){// function that generates a psuedorandom number, using the pr return (a*prev+c)%m; } int isValidBet(char *bet){ + if bet[0] == '-'{//no negative bets allowed + return 0; + } + return 1; } int main() {// a reimplementation of a simple casino game I wrote in python a while ago int coins = 100;//starting Coins From e92a4bbc42807631ee851a5b73404dc3cccdd77a Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:55:09 -0700 Subject: [PATCH 018/113] loop over string --- user/textGame.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index e5f7cb3..9519a91 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -16,7 +16,12 @@ int isValidBet(char *bet){ if bet[0] == '-'{//no negative bets allowed return 0; } + int i = 0; + while (str[i] != '\0') {//loop over every char in string + i++; + } return 1; + } int main() {// a reimplementation of a simple casino game I wrote in python a while ago int coins = 100;//starting Coins From 3fcd3149c606cfc7c798fc2b27732c95f8dc04b6 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:56:28 -0700 Subject: [PATCH 019/113] check if char is digit --- user/textGame.c | 1 + 1 file changed, 1 insertion(+) diff --git a/user/textGame.c b/user/textGame.c index 9519a91..94cbb21 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -18,6 +18,7 @@ int isValidBet(char *bet){ } int i = 0; while (str[i] != '\0') {//loop over every char in string + if (str[i]!='0' && str[i]!='1' && str[i]!='2'&& str[i]!='3'&& str[i]!='4'&& str[i]!='5'&& str[i]!='6'&& str[i]!='7'&& str[i]!='8'&& str[i]!='9') i++; } return 1; From dcbfcf4ae63ba70dd9e72438a1a04fdc0b7050f2 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:57:40 -0700 Subject: [PATCH 020/113] simplify the check, to check if not in ascii range of digits --- user/textGame.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 94cbb21..68fbf75 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -18,7 +18,9 @@ int isValidBet(char *bet){ } int i = 0; while (str[i] != '\0') {//loop over every char in string - if (str[i]!='0' && str[i]!='1' && str[i]!='2'&& str[i]!='3'&& str[i]!='4'&& str[i]!='5'&& str[i]!='6'&& str[i]!='7'&& str[i]!='8'&& str[i]!='9') + if (str[i] < '0' || str[i] > '9'){ + + } i++; } return 1; From ddeb46c9edcebd54bae5560132a32124aed78641 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:58:06 -0700 Subject: [PATCH 021/113] Add a comment --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 68fbf75..6a4f92d 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -18,7 +18,7 @@ int isValidBet(char *bet){ } int i = 0; while (str[i] != '\0') {//loop over every char in string - if (str[i] < '0' || str[i] > '9'){ + if (str[i] < '0' || str[i] > '9'){// not a digit } i++; From 2534774720d317c5c2162e4609d06c6ce0e3031d Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:58:35 -0700 Subject: [PATCH 022/113] return 0 if one of characters not digit --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 6a4f92d..bbbcc74 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -19,7 +19,7 @@ int isValidBet(char *bet){ int i = 0; while (str[i] != '\0') {//loop over every char in string if (str[i] < '0' || str[i] > '9'){// not a digit - + return 0; } i++; } From 30c75036536dbd363df995391a598a785f3c6479 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:59:29 -0700 Subject: [PATCH 023/113] keep asking for bet until we get a valid one --- user/textGame.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index bbbcc74..8d682af 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -36,6 +36,13 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh if (strcmp(bet, "leave")){//handle input of leave break; } + //not leave, so now check if it is a valid bet + while (!isValidBet(betInput)){ + printf("invalid bet") + printf("how much to bet"); + gets(betInput, 128); + } + } return 0; } \ No newline at end of file From c3e2a1f2b7ca3cd3c60bbe7aa71331560cc8ccf9 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:01:57 -0700 Subject: [PATCH 024/113] use uptime as seed --- user/textGame.c | 1 + 1 file changed, 1 insertion(+) diff --git a/user/textGame.c b/user/textGame.c index 8d682af..69d8c83 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -30,6 +30,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh int coins = 100;//starting Coins int stuff = 12;//starting stuff char *betInput = malloc(128*sizeof(char));// a var for holding the bet + int randVal = uptime();// set seed for lcg as uptime while (coins >= 0){//keep going while coins <= 0, not < because allows you to sell stuff at 0 printf("how much to bet (type leave to leave the casino)"); gets(betInput, 128); From 503ef6dcc7cad33a4949db6f0e3bb927a4f1d591 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:02:19 -0700 Subject: [PATCH 025/113] get new random val --- user/textGame.c | 1 + 1 file changed, 1 insertion(+) diff --git a/user/textGame.c b/user/textGame.c index 69d8c83..012dd72 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -43,6 +43,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("how much to bet"); gets(betInput, 128); } + randVal = LCG(randVal);// get a new random val with LCG } return 0; From 602003980972377109e342a7b4e8e4cfcfb54b2d Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:03:50 -0700 Subject: [PATCH 026/113] create new roll var --- user/textGame.c | 1 + 1 file changed, 1 insertion(+) diff --git a/user/textGame.c b/user/textGame.c index 012dd72..8b1cf64 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -31,6 +31,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh int stuff = 12;//starting stuff char *betInput = malloc(128*sizeof(char));// a var for holding the bet int randVal = uptime();// set seed for lcg as uptime + int roll = 0;//set roll var to 0; while (coins >= 0){//keep going while coins <= 0, not < because allows you to sell stuff at 0 printf("how much to bet (type leave to leave the casino)"); gets(betInput, 128); From d43fc9133f29cdaa0e9114a67798251f94840e70 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:04:28 -0700 Subject: [PATCH 027/113] get roll --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 8b1cf64..16d3968 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -45,7 +45,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh gets(betInput, 128); } randVal = LCG(randVal);// get a new random val with LCG - + roll = (randVal % 97) + 1; // get a roll from 1-98 } return 0; } \ No newline at end of file From 49d70a6f7ca81189461ca15eeaddf7da892b40e8 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:05:18 -0700 Subject: [PATCH 028/113] game logic --- user/textGame.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index 16d3968..0097948 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -46,6 +46,15 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh } randVal = LCG(randVal);// get a new random val with LCG roll = (randVal % 97) + 1; // get a roll from 1-98 + if (roll == 1){// win more coins if roll is one + + } + else if (roll == 2){//win stuff if roll is 2 + + } + else{//you lose + + } } return 0; } \ No newline at end of file From 94f963a12118d87a7724434478ade45485c15257 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:05:51 -0700 Subject: [PATCH 029/113] temp add blank lines --- user/textGame.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index 0097948..a0297b7 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -47,13 +47,13 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh randVal = LCG(randVal);// get a new random val with LCG roll = (randVal % 97) + 1; // get a roll from 1-98 if (roll == 1){// win more coins if roll is one - + ; } else if (roll == 2){//win stuff if roll is 2 - + ; } else{//you lose - + ; } } return 0; From bf174d75747d95b947ab7e291381118e65213c89 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:07:16 -0700 Subject: [PATCH 030/113] add winning condition --- user/textGame.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index a0297b7..a47336e 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -47,7 +47,8 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh randVal = LCG(randVal);// get a new random val with LCG roll = (randVal % 97) + 1; // get a roll from 1-98 if (roll == 1){// win more coins if roll is one - ; + coins = coins + atoi(betInput)*48;//win 48 times your bet + printf("you won"); } else if (roll == 2){//win stuff if roll is 2 ; From 03a1c50d9961b9f051fac79f7f5b44a89c689954 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:07:51 -0700 Subject: [PATCH 031/113] Update textGame.c --- user/textGame.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index a47336e..95212b2 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -51,7 +51,8 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("you won"); } else if (roll == 2){//win stuff if roll is 2 - ; + stuff=stuff+(atoi(bet));// win your bet in stuff + printf('you have %d things', stuff); } else{//you lose ; From 38a1be90c709eb0816446de20798d21ef900142d Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:08:54 -0700 Subject: [PATCH 032/113] lose, and also print out money after roll Beta --- user/textGame.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 95212b2..68c13df 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -55,8 +55,11 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf('you have %d things', stuff); } else{//you lose - ; + money=money-atoi(betInput);// lose your bet + printf("you lose"); + } + print("you have $%d", coins);//print money after bet } return 0; } \ No newline at end of file From 067ebe7f1a6dc9e196315680cd0c4ac920ac5b85 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:26:37 -0700 Subject: [PATCH 033/113] move %m to after m defined Finally reached new stuff --- user/textGame.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 68c13df..a657496 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -5,11 +5,12 @@ #include "user/user.h" int LCG(int prev){// function that generates a psuedorandom number, using the previous value in the sequence, which starts at a seed - prev = prev % m; + //https://www.ams.org/journals/mcom/1999-68-225/S0025-5718-99-00996-5/S0025-5718-99-00996-5.pdf has table of values long a = 530877178; long c = 0;//c = 0, since it is what the chart has long m = 536870909;// 2^29 -3 + prev = prev % m; return (a*prev+c)%m; } int isValidBet(char *bet){ From 7380d6e5c3a7e03776de6487a45238739ad3ed06 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:39:14 -0700 Subject: [PATCH 034/113] fix using str instead of bet --- user/textGame.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index a657496..0b4ded0 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -18,8 +18,8 @@ int isValidBet(char *bet){ return 0; } int i = 0; - while (str[i] != '\0') {//loop over every char in string - if (str[i] < '0' || str[i] > '9'){// not a digit + while (bet[i] != '\0') {//loop over every char in string + if (bet[i] < '0' || bet[i] > '9'){// not a digit return 0; } i++; From a25fd114782bb0fc992c6d5ca8826329d2438abe Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:39:50 -0700 Subject: [PATCH 035/113] add missing paren around condition --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 0b4ded0..478f9b2 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -14,7 +14,7 @@ int LCG(int prev){// function that generates a psuedorandom number, using the pr return (a*prev+c)%m; } int isValidBet(char *bet){ - if bet[0] == '-'{//no negative bets allowed + if (bet[0] == '-'){//no negative bets allowed return 0; } int i = 0; From 435aae9825099e0673e08e3a303f57cd3cc28d68 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:40:25 -0700 Subject: [PATCH 036/113] replace uses of bet when i wanted betInput --- user/textGame.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index 478f9b2..4d04cf4 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -36,7 +36,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh while (coins >= 0){//keep going while coins <= 0, not < because allows you to sell stuff at 0 printf("how much to bet (type leave to leave the casino)"); gets(betInput, 128); - if (strcmp(bet, "leave")){//handle input of leave + if (strcmp(betInput, "leave")){//handle input of leave break; } //not leave, so now check if it is a valid bet @@ -52,7 +52,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("you won"); } else if (roll == 2){//win stuff if roll is 2 - stuff=stuff+(atoi(bet));// win your bet in stuff + stuff=stuff+(atoi(betInput));// win your bet in stuff printf('you have %d things', stuff); } else{//you lose From 747e3cc254406036ef2f9574fa18a8705f58ffc9 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:40:55 -0700 Subject: [PATCH 037/113] add missing ; --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 4d04cf4..68d8a5e 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -41,7 +41,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh } //not leave, so now check if it is a valid bet while (!isValidBet(betInput)){ - printf("invalid bet") + printf("invalid bet"); printf("how much to bet"); gets(betInput, 128); } From 8f7728bb49987acff46c469d2bc5ddee2f413285 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:41:26 -0700 Subject: [PATCH 038/113] fix using money instead of coins --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 68d8a5e..a0daa6a 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -56,7 +56,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf('you have %d things', stuff); } else{//you lose - money=money-atoi(betInput);// lose your bet + coins=coins-atoi(betInput);// lose your bet printf("you lose"); } From 0ff3d5c208752fc2cccd2c6965d589507fb70e27 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:41:45 -0700 Subject: [PATCH 039/113] fix using print instead of printf --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index a0daa6a..e839a6a 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -60,7 +60,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("you lose"); } - print("you have $%d", coins);//print money after bet + printf("you have $%d", coins);//print money after bet } return 0; } \ No newline at end of file From 6f89f1a417679b620b6a9306b03754a14839c975 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:48:00 -0700 Subject: [PATCH 040/113] add asking about selling --- user/textGame.c | 1 + 1 file changed, 1 insertion(+) diff --git a/user/textGame.c b/user/textGame.c index e839a6a..0654821 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -50,6 +50,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh if (roll == 1){// win more coins if roll is one coins = coins + atoi(betInput)*48;//win 48 times your bet printf("you won"); + printf("would you like to sell some of your stuff"); } else if (roll == 2){//win stuff if roll is 2 stuff=stuff+(atoi(betInput));// win your bet in stuff From 8747a0347814d05725bc5a304cb6ce1893144b95 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:48:11 -0700 Subject: [PATCH 041/113] add ? --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 0654821..b7b3983 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -50,7 +50,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh if (roll == 1){// win more coins if roll is one coins = coins + atoi(betInput)*48;//win 48 times your bet printf("you won"); - printf("would you like to sell some of your stuff"); + printf("would you like to sell some of your stuff?"); } else if (roll == 2){//win stuff if roll is 2 stuff=stuff+(atoi(betInput));// win your bet in stuff From 969eba4023078bbbf8b41a87048006b539885237 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:50:34 -0700 Subject: [PATCH 042/113] response var, plus prompt for response for selling --- user/textGame.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index b7b3983..574c625 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -31,6 +31,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh int coins = 100;//starting Coins int stuff = 12;//starting stuff char *betInput = malloc(128*sizeof(char));// a var for holding the bet + char *responseInput = malloc(128*sizeof(char));//a var for holding various responses int randVal = uptime();// set seed for lcg as uptime int roll = 0;//set roll var to 0; while (coins >= 0){//keep going while coins <= 0, not < because allows you to sell stuff at 0 @@ -51,6 +52,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh coins = coins + atoi(betInput)*48;//win 48 times your bet printf("you won"); printf("would you like to sell some of your stuff?"); + printf("yes/no"); } else if (roll == 2){//win stuff if roll is 2 stuff=stuff+(atoi(betInput));// win your bet in stuff From 3fdba546c763e86560a052bb69562e026ca1629f Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:56:19 -0700 Subject: [PATCH 043/113] fix '' instead of "" and start handling selling --- user/textGame.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 574c625..ff1cd67 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -53,10 +53,15 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("you won"); printf("would you like to sell some of your stuff?"); printf("yes/no"); + gets(responseInput, 128); + if (strcmp(responseInput, "yes")){//said yes to selling + printf("you have %d things", stuff);// print out how much stuff we have, so the user knows + + } } else if (roll == 2){//win stuff if roll is 2 stuff=stuff+(atoi(betInput));// win your bet in stuff - printf('you have %d things', stuff); + printf("you have %d things", stuff); } else{//you lose coins=coins-atoi(betInput);// lose your bet From 49c358aadfa8d82cbb9b5c8eead021845c80c098 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:57:26 -0700 Subject: [PATCH 044/113] ask how much to sell --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index ff1cd67..0433822 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -56,7 +56,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh gets(responseInput, 128); if (strcmp(responseInput, "yes")){//said yes to selling printf("you have %d things", stuff);// print out how much stuff we have, so the user knows - + printf("how many things would you like to sell?"); } } else if (roll == 2){//win stuff if roll is 2 From d488a6b41f14e11ba473866c1fd1ab20362a496a Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 19:11:54 -0700 Subject: [PATCH 045/113] handle getting amount to sell --- user/textGame.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index 0433822..3edc4f9 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -57,6 +57,14 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh if (strcmp(responseInput, "yes")){//said yes to selling printf("you have %d things", stuff);// print out how much stuff we have, so the user knows printf("how many things would you like to sell?"); + gets(responseInput, 128);// get amount to sell in response var + while (!isValidBet(responseInput) || atoi(responseInput)>stuff){//reuse bet handling to check if we can convert, and check we have enough stuff + printf("invalid input. Make sure you input an int, and you have enough stuff."); + printf("how many things would you like to sell?"); + gets(responseInput, 128);// get amount to sell in response var + } + + } } else if (roll == 2){//win stuff if roll is 2 From 25c802ff4a22ca8eaeb36ad3bcb3fb69b2e7a16d Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 19:12:07 -0700 Subject: [PATCH 046/113] remove the amount --- user/textGame.c | 1 + 1 file changed, 1 insertion(+) diff --git a/user/textGame.c b/user/textGame.c index 3edc4f9..6be0630 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -63,6 +63,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("how many things would you like to sell?"); gets(responseInput, 128);// get amount to sell in response var } + stuff = stuff - atoi(responseInput); } From db4eeabd1174f98437700f3100fee50e32c31e61 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 19:12:41 -0700 Subject: [PATCH 047/113] get a new random value, for use in determining selling price --- user/textGame.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 6be0630..7e6e3c2 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -64,7 +64,8 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh gets(responseInput, 128);// get amount to sell in response var } stuff = stuff - atoi(responseInput); - + randVal = LCG(randVal);// get a new random val with LCG + } } From b908ed76da5992d117f1eb5359ffc2eeff03a29c Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 19:15:15 -0700 Subject: [PATCH 048/113] get sale price from value --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 7e6e3c2..44d6ba2 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -65,7 +65,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh } stuff = stuff - atoi(responseInput); randVal = LCG(randVal);// get a new random val with LCG - + int saleAmount = randVal%99+1;//random int from 1-100 } } From 6058c847af9f01a2744faad31fb26803f0923f61 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 19:16:27 -0700 Subject: [PATCH 049/113] update variable name --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 44d6ba2..7f6eb9a 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -65,7 +65,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh } stuff = stuff - atoi(responseInput); randVal = LCG(randVal);// get a new random val with LCG - int saleAmount = randVal%99+1;//random int from 1-100 + int salePrice = randVal%99+1;//random int from 1-100 } } From 0fe24acb39ad7637a623cd5a6598a3a271985ee0 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 19:17:34 -0700 Subject: [PATCH 050/113] print info to user --- user/textGame.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 7f6eb9a..a8948de 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -66,7 +66,8 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh stuff = stuff - atoi(responseInput); randVal = LCG(randVal);// get a new random val with LCG int salePrice = randVal%99+1;//random int from 1-100 - + printf("your stuff sold for $%d each", salePrice); + printf("you have %d things", stuff); } } else if (roll == 2){//win stuff if roll is 2 From 3e754fe81d4afe6d7d25cfabba2653a3a0c79fd3 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 19:21:00 -0700 Subject: [PATCH 051/113] finish handling selling, adding money and printing out total --- user/textGame.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index a8948de..1182f4e 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -68,6 +68,8 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh int salePrice = randVal%99+1;//random int from 1-100 printf("your stuff sold for $%d each", salePrice); printf("you have %d things", stuff); + coins = coins + salePrice * atoi(responseInput); + printf("$%d", coins); } } else if (roll == 2){//win stuff if roll is 2 From 9842e4651c12d30bf524fd94339f64977ebf9be3 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 19:26:09 -0700 Subject: [PATCH 052/113] allow user to leave after winning roll of 1 --- user/textGame.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index 1182f4e..9afbd9c 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -71,6 +71,11 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh coins = coins + salePrice * atoi(responseInput); printf("$%d", coins); } + printf("would you like to leave yes/no"); + gets(responseInput, 128); + if (strcmp(responseInput, "yes")){//said yes to leaving + break; + } } else if (roll == 2){//win stuff if roll is 2 stuff=stuff+(atoi(betInput));// win your bet in stuff From 03c25728d02197f34c11230d7e1b0ed8965e3111 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 19:29:10 -0700 Subject: [PATCH 053/113] handling buying stuff --- user/textGame.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index 9afbd9c..62fc4ea 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -80,6 +80,11 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh else if (roll == 2){//win stuff if roll is 2 stuff=stuff+(atoi(betInput));// win your bet in stuff printf("you have %d things", stuff); + printf("would you like to buy some things yes/no"); + gets(responseInput, 128); + if (strcmp(responseInput, "yes")){//said yes to buying + + } } else{//you lose coins=coins-atoi(betInput);// lose your bet From b0da6bdb52228135b7807d00f44296568652ecba Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 19:39:16 -0700 Subject: [PATCH 054/113] get amount to buy --- user/textGame.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 62fc4ea..5f7178a 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -83,7 +83,13 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("would you like to buy some things yes/no"); gets(responseInput, 128); if (strcmp(responseInput, "yes")){//said yes to buying - + printf("how many things would you like to buy for $50 each?"); + gets(responseInput, 128);// get amount to sell in response var + while (!isValidBet(responseInput) || atoi(responseInput)<0){//reuse bet handling to check if we can convert, and check we have enough stuff + printf("invalid input. Make sure you input a positive int."); + printf("how many things would you like to buy for $50 each?"); + gets(responseInput, 128);// get amount to sell in response var + } } } else{//you lose From f447e89eb76a99f5a4a888e211e5e2591d79788b Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 19:40:53 -0700 Subject: [PATCH 055/113] fix comment from copy and paste --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 5f7178a..66fe5b6 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -85,7 +85,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh if (strcmp(responseInput, "yes")){//said yes to buying printf("how many things would you like to buy for $50 each?"); gets(responseInput, 128);// get amount to sell in response var - while (!isValidBet(responseInput) || atoi(responseInput)<0){//reuse bet handling to check if we can convert, and check we have enough stuff + while (!isValidBet(responseInput) || atoi(responseInput)<0){//reuse bet handling to check if we can convert, and check we are buying positive amount printf("invalid input. Make sure you input a positive int."); printf("how many things would you like to buy for $50 each?"); gets(responseInput, 128);// get amount to sell in response var From 50ccf71692e053750ff0c449b27f03dc38ddcaf8 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 19:51:38 -0700 Subject: [PATCH 056/113] handle actcually buying --- user/textGame.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index 66fe5b6..3985a64 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -90,6 +90,9 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("how many things would you like to buy for $50 each?"); gets(responseInput, 128);// get amount to sell in response var } + stuff = stuff + atoi(responseInput);//increase stuff + coins = coins - atoi(responseInput)*50;//decrease money + } } else{//you lose From 477ef479ecd4ff691a154e5470527060277460a8 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 20:07:16 -0700 Subject: [PATCH 057/113] add a comment for the next part --- user/textGame.c | 1 + 1 file changed, 1 insertion(+) diff --git a/user/textGame.c b/user/textGame.c index 3985a64..01b4bd1 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -101,6 +101,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh } printf("you have $%d", coins);//print money after bet + //now allow the user to sell stuff if they are out of money. } return 0; } \ No newline at end of file From da7efa709ed50f618688eabb513011e99ce02b0c Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 20:31:02 -0700 Subject: [PATCH 058/113] handling when you can buy --- user/textGame.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index 01b4bd1..21a1700 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -102,6 +102,9 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh } printf("you have $%d", coins);//print money after bet //now allow the user to sell stuff if they are out of money. + if (coins <= 0){//not enough money + + } } return 0; } \ No newline at end of file From 6d1e76ef36f88438e6a8f2c7780d193ece7c7616 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 20:40:15 -0700 Subject: [PATCH 059/113] finish handling selling stuff mostly just copying from earlier selling code changed value around sale price random number --- user/textGame.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 21a1700..d83c592 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -103,8 +103,34 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("you have $%d", coins);//print money after bet //now allow the user to sell stuff if they are out of money. if (coins <= 0){//not enough money - + printf(" would you like to sell some of your stuff?"); + printf("yes/no"); + gets(responseInput, 128); + if (strcmp(responseInput, "yes")){//said yes to selling + if (stuff<=0){//out of money and stuff + printf("not enough stuff"); + break; + } + else{//have at least some stuff + printf("you have %d things", stuff);// print out how much stuff we have, so the user knows + printf("how many things would you like to sell?"); + gets(responseInput, 128);// get amount to sell in response var + while (!isValidBet(responseInput) || atoi(responseInput)>stuff){//reuse bet handling to check if we can convert, and check we have enough stuff + printf("invalid input. Make sure you input an int, and you have enough stuff."); + printf("how many things would you like to sell?"); + gets(responseInput, 128);// get amount to sell in response var + } + stuff = stuff - atoi(responseInput); + randVal = LCG(randVal);// get a new random val with LCG + int salePrice = randVal%20+1;//random int from 1-20 + printf("your stuff sold for $%d each", salePrice); + printf("you have %d things", stuff); + coins = coins + salePrice * atoi(responseInput); + printf("$%d", coins); + } + } } + } return 0; } \ No newline at end of file From 9ea3792c91665230b2e1fced8fa6d06356cc5163 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 20:59:11 -0700 Subject: [PATCH 060/113] allow user to buy stuff another copy and paste --- user/textGame.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index d83c592..52bc930 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -130,7 +130,20 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh } } } - + // allow user to buy stuff + printf("would you like to buy some things yes/no"); + gets(responseInput, 128); + if (strcmp(responseInput, "yes")){//said yes to buying + printf("how many things would you like to buy for $50 each?"); + gets(responseInput, 128);// get amount to sell in response var + while (!isValidBet(responseInput) || atoi(responseInput)<0){//reuse bet handling to check if we can convert, and check we are buying positive amount + printf("invalid input. Make sure you input a positive int."); + printf("how many things would you like to buy for $50 each?"); + gets(responseInput, 128);// get amount to sell in response var + } + stuff = stuff + atoi(responseInput);//increase stuff + coins = coins - atoi(responseInput)*50;//decrease money + } } return 0; } \ No newline at end of file From 8590de43080d56fb3e1cc3b4f5541fb69732f1fd Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 20:59:47 -0700 Subject: [PATCH 061/113] fix sell when i meant buy --- user/textGame.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index 52bc930..d06bb26 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -84,11 +84,11 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh gets(responseInput, 128); if (strcmp(responseInput, "yes")){//said yes to buying printf("how many things would you like to buy for $50 each?"); - gets(responseInput, 128);// get amount to sell in response var + gets(responseInput, 128);// get amount to buy in response var while (!isValidBet(responseInput) || atoi(responseInput)<0){//reuse bet handling to check if we can convert, and check we are buying positive amount printf("invalid input. Make sure you input a positive int."); printf("how many things would you like to buy for $50 each?"); - gets(responseInput, 128);// get amount to sell in response var + gets(responseInput, 128);// get amount to buy in response var } stuff = stuff + atoi(responseInput);//increase stuff coins = coins - atoi(responseInput)*50;//decrease money @@ -135,11 +135,11 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh gets(responseInput, 128); if (strcmp(responseInput, "yes")){//said yes to buying printf("how many things would you like to buy for $50 each?"); - gets(responseInput, 128);// get amount to sell in response var + gets(responseInput, 128);// get amount to buy in response var while (!isValidBet(responseInput) || atoi(responseInput)<0){//reuse bet handling to check if we can convert, and check we are buying positive amount printf("invalid input. Make sure you input a positive int."); printf("how many things would you like to buy for $50 each?"); - gets(responseInput, 128);// get amount to sell in response var + gets(responseInput, 128);// get amount to buy in response var } stuff = stuff + atoi(responseInput);//increase stuff coins = coins - atoi(responseInput)*50;//decrease money From 1a7f680091c9e105dc6b43c29720c6565ef7ab46 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 21:00:39 -0700 Subject: [PATCH 062/113] print out profit at the end --- user/textGame.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index d06bb26..3b82413 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -145,5 +145,6 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh coins = coins - atoi(responseInput)*50;//decrease money } } - return 0; + printf("profit was $%d",coins-100) + return 0; } \ No newline at end of file From f6dff2015d92b3d4ce243f4b0698451ea7c0b424 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 21:05:56 -0700 Subject: [PATCH 063/113] add missing ; --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 3b82413..e8425c2 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -145,6 +145,6 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh coins = coins - atoi(responseInput)*50;//decrease money } } - printf("profit was $%d",coins-100) + printf("profit was $%d",coins-100); return 0; } \ No newline at end of file From 69e3efe7126aa0c692c82e5afb0cfbb412dd9c50 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 21:14:13 -0700 Subject: [PATCH 064/113] add /n to prints --- user/textGame.c | 70 ++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index e8425c2..7fd7e28 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -35,43 +35,43 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh int randVal = uptime();// set seed for lcg as uptime int roll = 0;//set roll var to 0; while (coins >= 0){//keep going while coins <= 0, not < because allows you to sell stuff at 0 - printf("how much to bet (type leave to leave the casino)"); + printf("how much to bet (type leave to leave the casino)\n"); gets(betInput, 128); if (strcmp(betInput, "leave")){//handle input of leave break; } //not leave, so now check if it is a valid bet while (!isValidBet(betInput)){ - printf("invalid bet"); - printf("how much to bet"); + printf("invalid bet\n"); + printf("how much to bet\n"); gets(betInput, 128); } randVal = LCG(randVal);// get a new random val with LCG roll = (randVal % 97) + 1; // get a roll from 1-98 if (roll == 1){// win more coins if roll is one coins = coins + atoi(betInput)*48;//win 48 times your bet - printf("you won"); - printf("would you like to sell some of your stuff?"); - printf("yes/no"); + printf("you won\n"); + printf("would you like to sell some of your stuff?\n"); + printf("yes/no\n"); gets(responseInput, 128); if (strcmp(responseInput, "yes")){//said yes to selling - printf("you have %d things", stuff);// print out how much stuff we have, so the user knows - printf("how many things would you like to sell?"); + printf("you have %d things\n", stuff);// print out how much stuff we have, so the user knows + printf("how many things would you like to sell?\n"); gets(responseInput, 128);// get amount to sell in response var while (!isValidBet(responseInput) || atoi(responseInput)>stuff){//reuse bet handling to check if we can convert, and check we have enough stuff - printf("invalid input. Make sure you input an int, and you have enough stuff."); - printf("how many things would you like to sell?"); + printf("invalid input. Make sure you input an int, and you have enough stuff.\n"); + printf("how many things would you like to sell?\n"); gets(responseInput, 128);// get amount to sell in response var } stuff = stuff - atoi(responseInput); randVal = LCG(randVal);// get a new random val with LCG int salePrice = randVal%99+1;//random int from 1-100 - printf("your stuff sold for $%d each", salePrice); - printf("you have %d things", stuff); + printf("your stuff sold for $%d each\n", salePrice); + printf("you have %d things\n", stuff); coins = coins + salePrice * atoi(responseInput); printf("$%d", coins); } - printf("would you like to leave yes/no"); + printf("would you like to leave yes/no\n"); gets(responseInput, 128); if (strcmp(responseInput, "yes")){//said yes to leaving break; @@ -79,15 +79,15 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh } else if (roll == 2){//win stuff if roll is 2 stuff=stuff+(atoi(betInput));// win your bet in stuff - printf("you have %d things", stuff); - printf("would you like to buy some things yes/no"); + printf("you have %d things\n", stuff); + printf("would you like to buy some things yes/no\n"); gets(responseInput, 128); if (strcmp(responseInput, "yes")){//said yes to buying - printf("how many things would you like to buy for $50 each?"); + printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var while (!isValidBet(responseInput) || atoi(responseInput)<0){//reuse bet handling to check if we can convert, and check we are buying positive amount - printf("invalid input. Make sure you input a positive int."); - printf("how many things would you like to buy for $50 each?"); + printf("invalid input. Make sure you input a positive int.\n"); + printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var } stuff = stuff + atoi(responseInput);//increase stuff @@ -97,54 +97,54 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh } else{//you lose coins=coins-atoi(betInput);// lose your bet - printf("you lose"); + printf("you lose\n"); } - printf("you have $%d", coins);//print money after bet + printf("you have $%d\n", coins);//print money after bet //now allow the user to sell stuff if they are out of money. if (coins <= 0){//not enough money - printf(" would you like to sell some of your stuff?"); - printf("yes/no"); + printf(" would you like to sell some of your stuff?\n"); + printf("yes/no\n"); gets(responseInput, 128); if (strcmp(responseInput, "yes")){//said yes to selling if (stuff<=0){//out of money and stuff - printf("not enough stuff"); + printf("not enough stuff\n"); break; } else{//have at least some stuff - printf("you have %d things", stuff);// print out how much stuff we have, so the user knows - printf("how many things would you like to sell?"); + printf("you have %d things\n", stuff);// print out how much stuff we have, so the user knows + printf("how many things would you like to sell?\n"); gets(responseInput, 128);// get amount to sell in response var while (!isValidBet(responseInput) || atoi(responseInput)>stuff){//reuse bet handling to check if we can convert, and check we have enough stuff - printf("invalid input. Make sure you input an int, and you have enough stuff."); - printf("how many things would you like to sell?"); + printf("invalid input. Make sure you input an int, and you have enough stuff.\n"); + printf("how many things would you like to sell?\n"); gets(responseInput, 128);// get amount to sell in response var } stuff = stuff - atoi(responseInput); randVal = LCG(randVal);// get a new random val with LCG int salePrice = randVal%20+1;//random int from 1-20 - printf("your stuff sold for $%d each", salePrice); - printf("you have %d things", stuff); + printf("your stuff sold for $%d each\n", salePrice); + printf("you have %d things\n", stuff); coins = coins + salePrice * atoi(responseInput); - printf("$%d", coins); + printf("$%d\n", coins); } } } // allow user to buy stuff - printf("would you like to buy some things yes/no"); + printf("would you like to buy some things yes/no\n"); gets(responseInput, 128); if (strcmp(responseInput, "yes")){//said yes to buying - printf("how many things would you like to buy for $50 each?"); + printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var while (!isValidBet(responseInput) || atoi(responseInput)<0){//reuse bet handling to check if we can convert, and check we are buying positive amount - printf("invalid input. Make sure you input a positive int."); - printf("how many things would you like to buy for $50 each?"); + printf("invalid input. Make sure you input a positive int.\n"); + printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var } stuff = stuff + atoi(responseInput);//increase stuff coins = coins - atoi(responseInput)*50;//decrease money } } - printf("profit was $%d",coins-100); + printf("profit was $%d\n",coins-100); return 0; } \ No newline at end of file From 07f3640c2876d782fccdb24cbb696a6de8a61d4a Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 21:49:25 -0700 Subject: [PATCH 065/113] fix strcmps actually checking if not equal --- user/textGame.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index 7fd7e28..efb4719 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -37,7 +37,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh while (coins >= 0){//keep going while coins <= 0, not < because allows you to sell stuff at 0 printf("how much to bet (type leave to leave the casino)\n"); gets(betInput, 128); - if (strcmp(betInput, "leave")){//handle input of leave + if (strcmp(betInput, "leave")==0){//handle input of leave break; } //not leave, so now check if it is a valid bet @@ -54,7 +54,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("would you like to sell some of your stuff?\n"); printf("yes/no\n"); gets(responseInput, 128); - if (strcmp(responseInput, "yes")){//said yes to selling + if (strcmp(responseInput, "yes")==0){//said yes to selling printf("you have %d things\n", stuff);// print out how much stuff we have, so the user knows printf("how many things would you like to sell?\n"); gets(responseInput, 128);// get amount to sell in response var @@ -73,7 +73,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh } printf("would you like to leave yes/no\n"); gets(responseInput, 128); - if (strcmp(responseInput, "yes")){//said yes to leaving + if (strcmp(responseInput, "yes")==0){//said yes to leaving break; } } @@ -82,7 +82,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("you have %d things\n", stuff); printf("would you like to buy some things yes/no\n"); gets(responseInput, 128); - if (strcmp(responseInput, "yes")){//said yes to buying + if (strcmp(responseInput, "yes")==0){//said yes to buying printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var while (!isValidBet(responseInput) || atoi(responseInput)<0){//reuse bet handling to check if we can convert, and check we are buying positive amount @@ -103,10 +103,10 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("you have $%d\n", coins);//print money after bet //now allow the user to sell stuff if they are out of money. if (coins <= 0){//not enough money - printf(" would you like to sell some of your stuff?\n"); + printf("would you like to sell some of your stuff?\n"); printf("yes/no\n"); gets(responseInput, 128); - if (strcmp(responseInput, "yes")){//said yes to selling + if (strcmp(responseInput, "yes")==0){//said yes to selling if (stuff<=0){//out of money and stuff printf("not enough stuff\n"); break; @@ -133,7 +133,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh // allow user to buy stuff printf("would you like to buy some things yes/no\n"); gets(responseInput, 128); - if (strcmp(responseInput, "yes")){//said yes to buying + if (strcmp(responseInput, "yes")==0){//said yes to buying printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var while (!isValidBet(responseInput) || atoi(responseInput)<0){//reuse bet handling to check if we can convert, and check we are buying positive amount From 7b37961a533a313e4e4bc549a63d50849d4208dd Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 21:50:11 -0700 Subject: [PATCH 066/113] formatting --- user/textGame.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index efb4719..e642c27 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -37,7 +37,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh while (coins >= 0){//keep going while coins <= 0, not < because allows you to sell stuff at 0 printf("how much to bet (type leave to leave the casino)\n"); gets(betInput, 128); - if (strcmp(betInput, "leave")==0){//handle input of leave + if (strcmp(betInput, "leave") == 0){//handle input of leave break; } //not leave, so now check if it is a valid bet @@ -54,7 +54,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("would you like to sell some of your stuff?\n"); printf("yes/no\n"); gets(responseInput, 128); - if (strcmp(responseInput, "yes")==0){//said yes to selling + if (strcmp(responseInput, "yes") == 0){//said yes to selling printf("you have %d things\n", stuff);// print out how much stuff we have, so the user knows printf("how many things would you like to sell?\n"); gets(responseInput, 128);// get amount to sell in response var @@ -73,7 +73,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh } printf("would you like to leave yes/no\n"); gets(responseInput, 128); - if (strcmp(responseInput, "yes")==0){//said yes to leaving + if (strcmp(responseInput, "yes") == 0){//said yes to leaving break; } } @@ -82,7 +82,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("you have %d things\n", stuff); printf("would you like to buy some things yes/no\n"); gets(responseInput, 128); - if (strcmp(responseInput, "yes")==0){//said yes to buying + if (strcmp(responseInput, "yes") == 0){//said yes to buying printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var while (!isValidBet(responseInput) || atoi(responseInput)<0){//reuse bet handling to check if we can convert, and check we are buying positive amount @@ -106,7 +106,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("would you like to sell some of your stuff?\n"); printf("yes/no\n"); gets(responseInput, 128); - if (strcmp(responseInput, "yes")==0){//said yes to selling + if (strcmp(responseInput, "yes") == 0){//said yes to selling if (stuff<=0){//out of money and stuff printf("not enough stuff\n"); break; @@ -133,7 +133,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh // allow user to buy stuff printf("would you like to buy some things yes/no\n"); gets(responseInput, 128); - if (strcmp(responseInput, "yes")==0){//said yes to buying + if (strcmp(responseInput, "yes") == 0){//said yes to buying printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var while (!isValidBet(responseInput) || atoi(responseInput)<0){//reuse bet handling to check if we can convert, and check we are buying positive amount From b6488b7b27adb36884bf3adac5c03071f0473e15 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 22:13:38 -0700 Subject: [PATCH 067/113] free vars --- user/textGame.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index e642c27..2fc2a94 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -146,5 +146,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh } } printf("profit was $%d\n",coins-100); + free(betInput); + free(responseInput); return 0; } \ No newline at end of file From c1c02ef6c35ec965cb7ac96728115db0caeea2f0 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 22:15:21 -0700 Subject: [PATCH 068/113] add function for removing trailing newlines --- user/textGame.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index 2fc2a94..fdc63c9 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -26,6 +26,9 @@ int isValidBet(char *bet){ } return 1; +} +void removeTrailingNewline(char *string){ + } int main() {// a reimplementation of a simple casino game I wrote in python a while ago int coins = 100;//starting Coins From 04aa244c15b8c70cbf0b28a076bf5c64c5fa0a76 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 22:17:53 -0700 Subject: [PATCH 069/113] get string length --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index fdc63c9..1fea82d 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -28,7 +28,7 @@ int isValidBet(char *bet){ } void removeTrailingNewline(char *string){ - + int stringLength = strlen(string); } int main() {// a reimplementation of a simple casino game I wrote in python a while ago int coins = 100;//starting Coins From 46b547ccbe2d158983c946705115bdb5bc38bee4 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 22:20:02 -0700 Subject: [PATCH 070/113] finish removing trailing newline function --- user/textGame.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index 1fea82d..176b934 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -29,6 +29,9 @@ int isValidBet(char *bet){ } void removeTrailingNewline(char *string){ int stringLength = strlen(string); + if (stringLength > 0 && string[stringLength-1] == '\n'){//if string has at least one character, and last char is newline + string[stringLength-1] = '\0'; + } } int main() {// a reimplementation of a simple casino game I wrote in python a while ago int coins = 100;//starting Coins From 4f6f66e2edd152df6069ac6af9504c5b78051ba9 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Fri, 20 Sep 2024 22:24:51 -0700 Subject: [PATCH 071/113] call remove trailing newline whenever we use gets --- user/textGame.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index 176b934..6e733d0 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -43,6 +43,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh while (coins >= 0){//keep going while coins <= 0, not < because allows you to sell stuff at 0 printf("how much to bet (type leave to leave the casino)\n"); gets(betInput, 128); + removeTrailingNewline(betInput); if (strcmp(betInput, "leave") == 0){//handle input of leave break; } @@ -51,6 +52,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("invalid bet\n"); printf("how much to bet\n"); gets(betInput, 128); + removeTrailingNewline(betInput); } randVal = LCG(randVal);// get a new random val with LCG roll = (randVal % 97) + 1; // get a roll from 1-98 @@ -60,14 +62,19 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("would you like to sell some of your stuff?\n"); printf("yes/no\n"); gets(responseInput, 128); + removeTrailingNewline(responseInput); if (strcmp(responseInput, "yes") == 0){//said yes to selling printf("you have %d things\n", stuff);// print out how much stuff we have, so the user knows printf("how many things would you like to sell?\n"); gets(responseInput, 128);// get amount to sell in response var + removeTrailingNewline(responseInput); + while (!isValidBet(responseInput) || atoi(responseInput)>stuff){//reuse bet handling to check if we can convert, and check we have enough stuff printf("invalid input. Make sure you input an int, and you have enough stuff.\n"); printf("how many things would you like to sell?\n"); gets(responseInput, 128);// get amount to sell in response var + removeTrailingNewline(responseInput); + } stuff = stuff - atoi(responseInput); randVal = LCG(randVal);// get a new random val with LCG @@ -79,6 +86,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh } printf("would you like to leave yes/no\n"); gets(responseInput, 128); + removeTrailingNewline(responseInput); if (strcmp(responseInput, "yes") == 0){//said yes to leaving break; } @@ -88,13 +96,16 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("you have %d things\n", stuff); printf("would you like to buy some things yes/no\n"); gets(responseInput, 128); + removeTrailingNewline(responseInput); if (strcmp(responseInput, "yes") == 0){//said yes to buying printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var + removeTrailingNewline(responseInput); while (!isValidBet(responseInput) || atoi(responseInput)<0){//reuse bet handling to check if we can convert, and check we are buying positive amount printf("invalid input. Make sure you input a positive int.\n"); printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var + removeTrailingNewline(responseInput); } stuff = stuff + atoi(responseInput);//increase stuff coins = coins - atoi(responseInput)*50;//decrease money @@ -112,6 +123,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("would you like to sell some of your stuff?\n"); printf("yes/no\n"); gets(responseInput, 128); + removeTrailingNewline(responseInput); if (strcmp(responseInput, "yes") == 0){//said yes to selling if (stuff<=0){//out of money and stuff printf("not enough stuff\n"); @@ -121,10 +133,12 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("you have %d things\n", stuff);// print out how much stuff we have, so the user knows printf("how many things would you like to sell?\n"); gets(responseInput, 128);// get amount to sell in response var + removeTrailingNewline(responseInput); while (!isValidBet(responseInput) || atoi(responseInput)>stuff){//reuse bet handling to check if we can convert, and check we have enough stuff printf("invalid input. Make sure you input an int, and you have enough stuff.\n"); printf("how many things would you like to sell?\n"); gets(responseInput, 128);// get amount to sell in response var + removeTrailingNewline(responseInput); } stuff = stuff - atoi(responseInput); randVal = LCG(randVal);// get a new random val with LCG @@ -139,13 +153,16 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh // allow user to buy stuff printf("would you like to buy some things yes/no\n"); gets(responseInput, 128); + removeTrailingNewline(responseInput); if (strcmp(responseInput, "yes") == 0){//said yes to buying printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var + removeTrailingNewline(responseInput); while (!isValidBet(responseInput) || atoi(responseInput)<0){//reuse bet handling to check if we can convert, and check we are buying positive amount printf("invalid input. Make sure you input a positive int.\n"); printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var + removeTrailingNewline(responseInput); } stuff = stuff + atoi(responseInput);//increase stuff coins = coins - atoi(responseInput)*50;//decrease money From 5789e65513217dc847a972911cd3b532c1558bbd Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 11:48:56 -0700 Subject: [PATCH 072/113] make sure we have enough coins to make our bet --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 6e733d0..bdc9c8d 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -48,7 +48,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh break; } //not leave, so now check if it is a valid bet - while (!isValidBet(betInput)){ + while (!isValidBet(betInput) || atoi(betInput)>coins){//make sure it is valid int input, if it is, also make sure we have enough coins printf("invalid bet\n"); printf("how much to bet\n"); gets(betInput, 128); From e16e40b5a75bee1a43e55adbefe538250da1480e Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 11:52:52 -0700 Subject: [PATCH 073/113] better invalid bet error message --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index bdc9c8d..40b8d3c 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -49,7 +49,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh } //not leave, so now check if it is a valid bet while (!isValidBet(betInput) || atoi(betInput)>coins){//make sure it is valid int input, if it is, also make sure we have enough coins - printf("invalid bet\n"); + printf("invalid bet. make sure you give a positive integer, and have enough money.\n"); printf("how much to bet\n"); gets(betInput, 128); removeTrailingNewline(betInput); From 47d379ecdc1bc885f21ee155b6f71d4ee6347652 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 12:23:56 -0700 Subject: [PATCH 074/113] new variable to store starting coins amount --- user/textGame.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 40b8d3c..4e71cb7 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -34,7 +34,8 @@ void removeTrailingNewline(char *string){ } } int main() {// a reimplementation of a simple casino game I wrote in python a while ago - int coins = 100;//starting Coins + int initialCoins = 100;// starting coins amount + int coins = initialCoins;//set coins var int stuff = 12;//starting stuff char *betInput = malloc(128*sizeof(char));// a var for holding the bet char *responseInput = malloc(128*sizeof(char));//a var for holding various responses From f31f2e6171397e8bf91c73195059ec318db7245c Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 12:24:14 -0700 Subject: [PATCH 075/113] profit calc with initialCoins --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 4e71cb7..1348093 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -169,7 +169,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh coins = coins - atoi(responseInput)*50;//decrease money } } - printf("profit was $%d\n",coins-100); + printf("profit was $%d\n",coins-initialCoins); free(betInput); free(responseInput); return 0; From 6f710e34e383de7ee24d6abf0a9b590c82616ca3 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 12:41:30 -0700 Subject: [PATCH 076/113] make init coins const, as well as a,c,m const --- user/textGame.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index 1348093..6a9647e 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -7,9 +7,9 @@ int LCG(int prev){// function that generates a psuedorandom number, using the previous value in the sequence, which starts at a seed //https://www.ams.org/journals/mcom/1999-68-225/S0025-5718-99-00996-5/S0025-5718-99-00996-5.pdf has table of values - long a = 530877178; - long c = 0;//c = 0, since it is what the chart has - long m = 536870909;// 2^29 -3 + const long a = 530877178; + const long c = 0;//c = 0, since it is what the chart has + const long m = 536870909;// 2^29 -3 prev = prev % m; return (a*prev+c)%m; } @@ -34,7 +34,7 @@ void removeTrailingNewline(char *string){ } } int main() {// a reimplementation of a simple casino game I wrote in python a while ago - int initialCoins = 100;// starting coins amount + const int initialCoins = 100;// starting coins amount int coins = initialCoins;//set coins var int stuff = 12;//starting stuff char *betInput = malloc(128*sizeof(char));// a var for holding the bet From 88f2fcfc6e28f49a62a9d9320f1c33f8c4ca8f7d Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 12:48:43 -0700 Subject: [PATCH 077/113] print that you. won things when you do --- user/textGame.c | 1 + 1 file changed, 1 insertion(+) diff --git a/user/textGame.c b/user/textGame.c index 6a9647e..536ff07 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -94,6 +94,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh } else if (roll == 2){//win stuff if roll is 2 stuff=stuff+(atoi(betInput));// win your bet in stuff + printf("you won %d things\n", atoi(betInput)); printf("you have %d things\n", stuff); printf("would you like to buy some things yes/no\n"); gets(responseInput, 128); From 3db3aa8b44b915fbff4081e112a0e805f1283d50 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 13:03:05 -0700 Subject: [PATCH 078/113] make stuff start value a constant, and pirnt out how many things you gain --- user/textGame.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 536ff07..446f9f4 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -34,9 +34,10 @@ void removeTrailingNewline(char *string){ } } int main() {// a reimplementation of a simple casino game I wrote in python a while ago + const int initialStuff = 12;// starting stuff amount const int initialCoins = 100;// starting coins amount int coins = initialCoins;//set coins var - int stuff = 12;//starting stuff + int stuff = initialStuff;//set stuff var char *betInput = malloc(128*sizeof(char));// a var for holding the bet char *responseInput = malloc(128*sizeof(char));//a var for holding various responses int randVal = uptime();// set seed for lcg as uptime @@ -171,6 +172,8 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh } } printf("profit was $%d\n",coins-initialCoins); + printf("you gained %d things\n",stuff-initialStuff); + free(betInput); free(responseInput); return 0; From ce5a77cb09f30703cea2f2fc3b539810f102a99d Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 13:17:57 -0700 Subject: [PATCH 079/113] stop if out of money and stuff --- user/textGame.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index 446f9f4..ed4f60e 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -43,6 +43,9 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh int randVal = uptime();// set seed for lcg as uptime int roll = 0;//set roll var to 0; while (coins >= 0){//keep going while coins <= 0, not < because allows you to sell stuff at 0 + if (coins == 0 && stuff == 0){//stop if you have no money and no stuff to sell + break; + } printf("how much to bet (type leave to leave the casino)\n"); gets(betInput, 128); removeTrailingNewline(betInput); From 876ed83380d4d214de9072a42ac1c0e18bfbb873 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:03:07 -0700 Subject: [PATCH 080/113] fix message --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index ed4f60e..5a17da6 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -75,7 +75,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh removeTrailingNewline(responseInput); while (!isValidBet(responseInput) || atoi(responseInput)>stuff){//reuse bet handling to check if we can convert, and check we have enough stuff - printf("invalid input. Make sure you input an int, and you have enough stuff.\n"); + printf("invalid input. Make sure you input a non-negative integer, and you have enough stuff.\n"); printf("how many things would you like to sell?\n"); gets(responseInput, 128);// get amount to sell in response var removeTrailingNewline(responseInput); From 3ef0960e31e95f10cd8b1a2a16c472d4bee3d1f3 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:04:47 -0700 Subject: [PATCH 081/113] fix other usage of that message --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 5a17da6..f86a3ae 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -141,7 +141,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh gets(responseInput, 128);// get amount to sell in response var removeTrailingNewline(responseInput); while (!isValidBet(responseInput) || atoi(responseInput)>stuff){//reuse bet handling to check if we can convert, and check we have enough stuff - printf("invalid input. Make sure you input an int, and you have enough stuff.\n"); + printf("invalid input. Make sure you input a non-negative integer, and you have enough stuff.\n"); printf("how many things would you like to sell?\n"); gets(responseInput, 128);// get amount to sell in response var removeTrailingNewline(responseInput); From 495a75d022493ca7480905d9619a7cba34770605 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:07:09 -0700 Subject: [PATCH 082/113] fix being able to buy things when you can't afford --- user/textGame.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index f86a3ae..f061658 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -107,8 +107,8 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var removeTrailingNewline(responseInput); - while (!isValidBet(responseInput) || atoi(responseInput)<0){//reuse bet handling to check if we can convert, and check we are buying positive amount - printf("invalid input. Make sure you input a positive int.\n"); + while (!isValidBet(responseInput) || atoi(responseInput)<0 || 50*atoi(responseInput)>coins){//reuse bet handling to check if we can convert, and check we are buying positive amount, and that we have enough money + printf("invalid input. Make sure you input a positive int, and have enough money to buy that many.\n"); printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var removeTrailingNewline(responseInput); @@ -164,8 +164,8 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var removeTrailingNewline(responseInput); - while (!isValidBet(responseInput) || atoi(responseInput)<0){//reuse bet handling to check if we can convert, and check we are buying positive amount - printf("invalid input. Make sure you input a positive int.\n"); + while (!isValidBet(responseInput) || atoi(responseInput)<0 || 50*atoi(responseInput)>coins){//reuse bet handling to check if we can convert, and check we are buying positive amount, and that we have enough money + printf("invalid input. Make sure you input a positive int, and have enough money to buy that many.\n"); printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var removeTrailingNewline(responseInput); From 6496fab11e357add56dc14867b243c1b3834d513 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:08:56 -0700 Subject: [PATCH 083/113] stop if both coins and stuff negativve or 0 don't just stop if both exactly 0 --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index f061658..e28fdd9 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -43,7 +43,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh int randVal = uptime();// set seed for lcg as uptime int roll = 0;//set roll var to 0; while (coins >= 0){//keep going while coins <= 0, not < because allows you to sell stuff at 0 - if (coins == 0 && stuff == 0){//stop if you have no money and no stuff to sell + if (coins <= 0 && stuff <= 0){//stop if you are out of money and stuff(changed from equals zero, since if negative, also want to stop) break; } printf("how much to bet (type leave to leave the casino)\n"); From cf54c0be6a30c45041fe8305e44e8c9a8ab5a70e Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:30:51 -0700 Subject: [PATCH 084/113] change isValidBet name to be more descriptive isNonNegativeInt is what it actually checks --- user/textGame.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index e28fdd9..e282af7 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -13,7 +13,7 @@ int LCG(int prev){// function that generates a psuedorandom number, using the pr prev = prev % m; return (a*prev+c)%m; } -int isValidBet(char *bet){ +int isNonNegativeInt(char *bet){ if (bet[0] == '-'){//no negative bets allowed return 0; } @@ -53,7 +53,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh break; } //not leave, so now check if it is a valid bet - while (!isValidBet(betInput) || atoi(betInput)>coins){//make sure it is valid int input, if it is, also make sure we have enough coins + while (!isNonNegativeInt(betInput) || atoi(betInput)>coins){//make sure it is valid int input, if it is, also make sure we have enough coins printf("invalid bet. make sure you give a positive integer, and have enough money.\n"); printf("how much to bet\n"); gets(betInput, 128); @@ -74,7 +74,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh gets(responseInput, 128);// get amount to sell in response var removeTrailingNewline(responseInput); - while (!isValidBet(responseInput) || atoi(responseInput)>stuff){//reuse bet handling to check if we can convert, and check we have enough stuff + while (!isNonNegativeInt(responseInput) || atoi(responseInput)>stuff){//reuse bet handling to check if we can convert, and check we have enough stuff printf("invalid input. Make sure you input a non-negative integer, and you have enough stuff.\n"); printf("how many things would you like to sell?\n"); gets(responseInput, 128);// get amount to sell in response var @@ -107,7 +107,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var removeTrailingNewline(responseInput); - while (!isValidBet(responseInput) || atoi(responseInput)<0 || 50*atoi(responseInput)>coins){//reuse bet handling to check if we can convert, and check we are buying positive amount, and that we have enough money + while (!isNonNegativeInt(responseInput) || atoi(responseInput)<0 || 50*atoi(responseInput)>coins){//reuse bet handling to check if we can convert, and check we are buying positive amount, and that we have enough money printf("invalid input. Make sure you input a positive int, and have enough money to buy that many.\n"); printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var @@ -140,7 +140,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("how many things would you like to sell?\n"); gets(responseInput, 128);// get amount to sell in response var removeTrailingNewline(responseInput); - while (!isValidBet(responseInput) || atoi(responseInput)>stuff){//reuse bet handling to check if we can convert, and check we have enough stuff + while (!isNonNegativeInt(responseInput) || atoi(responseInput)>stuff){//reuse bet handling to check if we can convert, and check we have enough stuff printf("invalid input. Make sure you input a non-negative integer, and you have enough stuff.\n"); printf("how many things would you like to sell?\n"); gets(responseInput, 128);// get amount to sell in response var @@ -164,7 +164,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var removeTrailingNewline(responseInput); - while (!isValidBet(responseInput) || atoi(responseInput)<0 || 50*atoi(responseInput)>coins){//reuse bet handling to check if we can convert, and check we are buying positive amount, and that we have enough money + while (!isNonNegativeInt(responseInput) || atoi(responseInput)<0 || 50*atoi(responseInput)>coins){//reuse bet handling to check if we can convert, and check we are buying positive amount, and that we have enough money printf("invalid input. Make sure you input a positive int, and have enough money to buy that many.\n"); printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var From e0564f32623722a0fbc8ca182ca82decb6bec7b5 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:39:54 -0700 Subject: [PATCH 085/113] rename param to fit better with the new func name --- user/textGame.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index e282af7..b143a4b 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -13,13 +13,13 @@ int LCG(int prev){// function that generates a psuedorandom number, using the pr prev = prev % m; return (a*prev+c)%m; } -int isNonNegativeInt(char *bet){ - if (bet[0] == '-'){//no negative bets allowed +int isNonNegativeInt(char *inString){ + if (inString[0] == '-'){//no negative bets allowed return 0; } int i = 0; - while (bet[i] != '\0') {//loop over every char in string - if (bet[i] < '0' || bet[i] > '9'){// not a digit + while (inString[i] != '\0') {//loop over every char in string + if (inString[i] < '0' || inString[i] > '9'){// not a digit return 0; } i++; From 6da9e9f0278e4da7a16e0397091ce9ad753fda48 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 15:28:46 -0700 Subject: [PATCH 086/113] add some spaces to make room for new function for big changes am rewriting things to do buying and selling in functions, reducing code duplication --- user/textGame.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index b143a4b..c8750cb 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -33,6 +33,8 @@ void removeTrailingNewline(char *string){ string[stringLength-1] = '\0'; } } + + int main() {// a reimplementation of a simple casino game I wrote in python a while ago const int initialStuff = 12;// starting stuff amount const int initialCoins = 100;// starting coins amount From 609425eea0f9de481a0ff701c93ee931fbd6ec8c Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 15:31:38 -0700 Subject: [PATCH 087/113] functions that tell us whether user wants to buy and sell stuff --- user/textGame.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index c8750cb..488e6c7 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -34,6 +34,13 @@ void removeTrailingNewline(char *string){ } } +int shouldBuyStuff(char *responseInput){ + +} + +int shouldSellStuff(char *responseInput){ + +} int main() {// a reimplementation of a simple casino game I wrote in python a while ago const int initialStuff = 12;// starting stuff amount From 3612305e690b9dcb9b5c4c8a0b6a7855871efaa1 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 15:36:19 -0700 Subject: [PATCH 088/113] implement functions to see if user wants to buy and sell --- user/textGame.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index 488e6c7..d4f52d8 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -35,11 +35,25 @@ void removeTrailingNewline(char *string){ } int shouldBuyStuff(char *responseInput){ - + // allow user to buy stuff + printf("would you like to buy some things yes/no\n"); + gets(responseInput, 128); + removeTrailingNewline(responseInput); + if (strcmp(responseInput, "yes") == 0){//said yes to buying + return 1; + } + return 0; //didn't want to buy } int shouldSellStuff(char *responseInput){ - + printf("would you like to sell some of your stuff?\n"); + printf("yes/no\n"); + gets(responseInput, 128); + removeTrailingNewline(responseInput); + if (strcmp(responseInput, "yes") == 0){//said yes to selling + return 1; + } + return 0;// didn't want to sell } int main() {// a reimplementation of a simple casino game I wrote in python a while ago From ae6f7952e958ca91f91dd2dda4721cc9e9a9af23 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 15:39:13 -0700 Subject: [PATCH 089/113] make selling use this new function --- user/textGame.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index d4f52d8..b75c842 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -87,11 +87,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh if (roll == 1){// win more coins if roll is one coins = coins + atoi(betInput)*48;//win 48 times your bet printf("you won\n"); - printf("would you like to sell some of your stuff?\n"); - printf("yes/no\n"); - gets(responseInput, 128); - removeTrailingNewline(responseInput); - if (strcmp(responseInput, "yes") == 0){//said yes to selling + if (shouldSellStuff(responseInput)){//does the user want to sell printf("you have %d things\n", stuff);// print out how much stuff we have, so the user knows printf("how many things would you like to sell?\n"); gets(responseInput, 128);// get amount to sell in response var @@ -149,11 +145,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("you have $%d\n", coins);//print money after bet //now allow the user to sell stuff if they are out of money. if (coins <= 0){//not enough money - printf("would you like to sell some of your stuff?\n"); - printf("yes/no\n"); - gets(responseInput, 128); - removeTrailingNewline(responseInput); - if (strcmp(responseInput, "yes") == 0){//said yes to selling + if (shouldSellStuff(responseInput)){//user wants to sell if (stuff<=0){//out of money and stuff printf("not enough stuff\n"); break; From 22c264c6c1127874a8b0bebd7a772181e4dd8bb2 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 15:41:29 -0700 Subject: [PATCH 090/113] use the new functions for buying --- user/textGame.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index b75c842..4c585cd 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -119,10 +119,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh stuff=stuff+(atoi(betInput));// win your bet in stuff printf("you won %d things\n", atoi(betInput)); printf("you have %d things\n", stuff); - printf("would you like to buy some things yes/no\n"); - gets(responseInput, 128); - removeTrailingNewline(responseInput); - if (strcmp(responseInput, "yes") == 0){//said yes to buying + if (shouldBuyStuff(responseInput)){//user wants to buy things printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var removeTrailingNewline(responseInput); @@ -172,10 +169,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh } } // allow user to buy stuff - printf("would you like to buy some things yes/no\n"); - gets(responseInput, 128); - removeTrailingNewline(responseInput); - if (strcmp(responseInput, "yes") == 0){//said yes to buying + if (shouldBuyStuff(responseInput)){//user wants to buy things printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var removeTrailingNewline(responseInput); From 72600cd726ede3389b9cdc787b47b030aeab8521 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:03:18 -0700 Subject: [PATCH 091/113] a function we can call to do the buying uses pointers to update the values without having to set them after --- user/textGame.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index 4c585cd..371b2d2 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -56,6 +56,10 @@ int shouldSellStuff(char *responseInput){ return 0;// didn't want to sell } +void performBuying(int *coinAmount, int *stuffAmount){ + +} + int main() {// a reimplementation of a simple casino game I wrote in python a while ago const int initialStuff = 12;// starting stuff amount const int initialCoins = 100;// starting coins amount From 7166c77a28d2389c8fe678800ec982c33a06751e Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:06:35 -0700 Subject: [PATCH 092/113] copy the code used for buying into the function will need some fixes before it can be used --- user/textGame.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 371b2d2..d9f0f4b 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -57,7 +57,18 @@ int shouldSellStuff(char *responseInput){ } void performBuying(int *coinAmount, int *stuffAmount){ - + printf("how many things would you like to buy for $50 each?\n"); + gets(responseInput, 128);// get amount to buy in response var + removeTrailingNewline(responseInput); + while (!isNonNegativeInt(responseInput) || atoi(responseInput)<0 || 50*atoi(responseInput)>coins){//reuse bet handling to check if we can convert, and check we are buying positive amount, and that we have enough money + printf("invalid input. Make sure you input a positive int, and have enough money to buy that many.\n"); + printf("how many things would you like to buy for $50 each?\n"); + gets(responseInput, 128);// get amount to buy in response var + removeTrailingNewline(responseInput); + } + stuff = stuff + atoi(responseInput);//increase stuff + coins = coins - atoi(responseInput)*50;//decrease money + } int main() {// a reimplementation of a simple casino game I wrote in python a while ago From c2d5b6cb590ab9df6d95bfce199ca273cf562cde Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:07:41 -0700 Subject: [PATCH 093/113] perform the fixes --- user/textGame.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index d9f0f4b..ea6cf2f 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -56,18 +56,18 @@ int shouldSellStuff(char *responseInput){ return 0;// didn't want to sell } -void performBuying(int *coinAmount, int *stuffAmount){ +void performBuying(int *coinAmount, int *stuffAmount, char *responseInput){ printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var removeTrailingNewline(responseInput); - while (!isNonNegativeInt(responseInput) || atoi(responseInput)<0 || 50*atoi(responseInput)>coins){//reuse bet handling to check if we can convert, and check we are buying positive amount, and that we have enough money + while (!isNonNegativeInt(responseInput) || atoi(responseInput)<0 || 50*atoi(responseInput)>*coinAmount){//reuse bet handling to check if we can convert, and check we are buying positive amount, and that we have enough money printf("invalid input. Make sure you input a positive int, and have enough money to buy that many.\n"); printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var removeTrailingNewline(responseInput); } - stuff = stuff + atoi(responseInput);//increase stuff - coins = coins - atoi(responseInput)*50;//decrease money + *stuffAmount = *stuffAmount + atoi(responseInput);//increase stuff + *coinAmount = *coinAmount - atoi(responseInput)*50;//decrease money } From bca8c0e246cac73296bef171638eb0ae1e90cfd1 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:14:16 -0700 Subject: [PATCH 094/113] actually use the function for buying --- user/textGame.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index ea6cf2f..8b9337b 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -135,17 +135,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("you won %d things\n", atoi(betInput)); printf("you have %d things\n", stuff); if (shouldBuyStuff(responseInput)){//user wants to buy things - printf("how many things would you like to buy for $50 each?\n"); - gets(responseInput, 128);// get amount to buy in response var - removeTrailingNewline(responseInput); - while (!isNonNegativeInt(responseInput) || atoi(responseInput)<0 || 50*atoi(responseInput)>coins){//reuse bet handling to check if we can convert, and check we are buying positive amount, and that we have enough money - printf("invalid input. Make sure you input a positive int, and have enough money to buy that many.\n"); - printf("how many things would you like to buy for $50 each?\n"); - gets(responseInput, 128);// get amount to buy in response var - removeTrailingNewline(responseInput); - } - stuff = stuff + atoi(responseInput);//increase stuff - coins = coins - atoi(responseInput)*50;//decrease money + performBuying(&coins, &stuff, responseInput); } } @@ -185,17 +175,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh } // allow user to buy stuff if (shouldBuyStuff(responseInput)){//user wants to buy things - printf("how many things would you like to buy for $50 each?\n"); - gets(responseInput, 128);// get amount to buy in response var - removeTrailingNewline(responseInput); - while (!isNonNegativeInt(responseInput) || atoi(responseInput)<0 || 50*atoi(responseInput)>coins){//reuse bet handling to check if we can convert, and check we are buying positive amount, and that we have enough money - printf("invalid input. Make sure you input a positive int, and have enough money to buy that many.\n"); - printf("how many things would you like to buy for $50 each?\n"); - gets(responseInput, 128);// get amount to buy in response var - removeTrailingNewline(responseInput); - } - stuff = stuff + atoi(responseInput);//increase stuff - coins = coins - atoi(responseInput)*50;//decrease money + performBuying(&coins, &stuff, responseInput); } } printf("profit was $%d\n",coins-initialCoins); From 2a688511dd9332b955a24969349834a8e51b1786 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:28:54 -0700 Subject: [PATCH 095/113] add function to do the selling --- user/textGame.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index 8b9337b..c3269f8 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -71,6 +71,10 @@ void performBuying(int *coinAmount, int *stuffAmount, char *responseInput){ } +void performSelling(int *coinAmount, int *stuffAmount, char *responseInput){ + +} + int main() {// a reimplementation of a simple casino game I wrote in python a while ago const int initialStuff = 12;// starting stuff amount const int initialCoins = 100;// starting coins amount From 75cfc2310ede2f92a28e47430df752b57e7fb23b Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:39:13 -0700 Subject: [PATCH 096/113] paste in code for running the selling, still needs fixes --- user/textGame.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index c3269f8..0160910 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -72,7 +72,24 @@ void performBuying(int *coinAmount, int *stuffAmount, char *responseInput){ } void performSelling(int *coinAmount, int *stuffAmount, char *responseInput){ + printf("how many things would you like to sell?\n"); + gets(responseInput, 128);// get amount to sell in response var + removeTrailingNewline(responseInput); + + while (!isNonNegativeInt(responseInput) || atoi(responseInput)>stuff){//reuse bet handling to check if we can convert, and check we have enough stuff + printf("invalid input. Make sure you input a non-negative integer, and you have enough stuff.\n"); + printf("how many things would you like to sell?\n"); + gets(responseInput, 128);// get amount to sell in response var + removeTrailingNewline(responseInput); + } + stuff = stuff - atoi(responseInput); + randVal = LCG(randVal);// get a new random val with LCG + int salePrice = randVal%99+1;//random int from 1-100 + printf("your stuff sold for $%d each\n", salePrice); + printf("you have %d things\n", stuff); + coins = coins + salePrice * atoi(responseInput); + printf("$%d", coins); } int main() {// a reimplementation of a simple casino game I wrote in python a while ago From 06275b652b6d70ed11184672837e8d0397e0225e Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:40:06 -0700 Subject: [PATCH 097/113] apply fixes --- user/textGame.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index 0160910..56b8bed 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -71,25 +71,25 @@ void performBuying(int *coinAmount, int *stuffAmount, char *responseInput){ } -void performSelling(int *coinAmount, int *stuffAmount, char *responseInput){ +void performSelling(int *coinAmount, int *stuffAmount, int *randomNumber, int maxSalePrice, char *responseInput){ printf("how many things would you like to sell?\n"); gets(responseInput, 128);// get amount to sell in response var removeTrailingNewline(responseInput); - while (!isNonNegativeInt(responseInput) || atoi(responseInput)>stuff){//reuse bet handling to check if we can convert, and check we have enough stuff + while (!isNonNegativeInt(responseInput) || atoi(responseInput)>*stuffAmount){//reuse bet handling to check if we can convert, and check we have enough stuff printf("invalid input. Make sure you input a non-negative integer, and you have enough stuff.\n"); printf("how many things would you like to sell?\n"); gets(responseInput, 128);// get amount to sell in response var removeTrailingNewline(responseInput); } - stuff = stuff - atoi(responseInput); - randVal = LCG(randVal);// get a new random val with LCG - int salePrice = randVal%99+1;//random int from 1-100 + *stuffAmount = *stuffAmount - atoi(responseInput); + *randomNumber = LCG(*randomNumber);// get a new random val with LCG + int salePrice = *randomNumber%(maxSalePrice-1)+1;//random int from 1-100 printf("your stuff sold for $%d each\n", salePrice); - printf("you have %d things\n", stuff); - coins = coins + salePrice * atoi(responseInput); - printf("$%d", coins); + printf("you have %d things\n", *stuffAmount); + *coinAmount = *coinAmount + salePrice * atoi(responseInput); + printf("$%d", *coinAmount); } int main() {// a reimplementation of a simple casino game I wrote in python a while ago From ee7d76415f2ccf9cdad0fe1f759773e4a297b758 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:45:08 -0700 Subject: [PATCH 098/113] fix comment to reflect code --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 56b8bed..da9ca7b 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -85,7 +85,7 @@ void performSelling(int *coinAmount, int *stuffAmount, int *randomNumber, int ma } *stuffAmount = *stuffAmount - atoi(responseInput); *randomNumber = LCG(*randomNumber);// get a new random val with LCG - int salePrice = *randomNumber%(maxSalePrice-1)+1;//random int from 1-100 + int salePrice = *randomNumber%(maxSalePrice-1)+1;//random int from 1-maxSalePrice printf("your stuff sold for $%d each\n", salePrice); printf("you have %d things\n", *stuffAmount); *coinAmount = *coinAmount + salePrice * atoi(responseInput); From 5efc93cbbcd393a068599c715404f90775dafb4b Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:50:29 -0700 Subject: [PATCH 099/113] use the function for selling --- user/textGame.c | 36 ++---------------------------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index da9ca7b..ae87b88 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -125,24 +125,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("you won\n"); if (shouldSellStuff(responseInput)){//does the user want to sell printf("you have %d things\n", stuff);// print out how much stuff we have, so the user knows - printf("how many things would you like to sell?\n"); - gets(responseInput, 128);// get amount to sell in response var - removeTrailingNewline(responseInput); - - while (!isNonNegativeInt(responseInput) || atoi(responseInput)>stuff){//reuse bet handling to check if we can convert, and check we have enough stuff - printf("invalid input. Make sure you input a non-negative integer, and you have enough stuff.\n"); - printf("how many things would you like to sell?\n"); - gets(responseInput, 128);// get amount to sell in response var - removeTrailingNewline(responseInput); - - } - stuff = stuff - atoi(responseInput); - randVal = LCG(randVal);// get a new random val with LCG - int salePrice = randVal%99+1;//random int from 1-100 - printf("your stuff sold for $%d each\n", salePrice); - printf("you have %d things\n", stuff); - coins = coins + salePrice * atoi(responseInput); - printf("$%d", coins); + performSelling(&coins, &stuff, &randVal, 100, responseInput); } printf("would you like to leave yes/no\n"); gets(responseInput, 128); @@ -175,22 +158,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh } else{//have at least some stuff printf("you have %d things\n", stuff);// print out how much stuff we have, so the user knows - printf("how many things would you like to sell?\n"); - gets(responseInput, 128);// get amount to sell in response var - removeTrailingNewline(responseInput); - while (!isNonNegativeInt(responseInput) || atoi(responseInput)>stuff){//reuse bet handling to check if we can convert, and check we have enough stuff - printf("invalid input. Make sure you input a non-negative integer, and you have enough stuff.\n"); - printf("how many things would you like to sell?\n"); - gets(responseInput, 128);// get amount to sell in response var - removeTrailingNewline(responseInput); - } - stuff = stuff - atoi(responseInput); - randVal = LCG(randVal);// get a new random val with LCG - int salePrice = randVal%20+1;//random int from 1-20 - printf("your stuff sold for $%d each\n", salePrice); - printf("you have %d things\n", stuff); - coins = coins + salePrice * atoi(responseInput); - printf("$%d\n", coins); + performSelling(&coins, &stuff, &randVal, 20, responseInput); } } } From ae339a42415b772e780621265e7c0f7bb0434a1c Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:53:26 -0700 Subject: [PATCH 100/113] better print of money after selling, add newline char --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index ae87b88..1a17290 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -89,7 +89,7 @@ void performSelling(int *coinAmount, int *stuffAmount, int *randomNumber, int ma printf("your stuff sold for $%d each\n", salePrice); printf("you have %d things\n", *stuffAmount); *coinAmount = *coinAmount + salePrice * atoi(responseInput); - printf("$%d", *coinAmount); + printf("You now have $%d\n", *coinAmount); } int main() {// a reimplementation of a simple casino game I wrote in python a while ago From 6d6f3b3925b479efa84cd4c0b4bb10326ea1a2e0 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:39:49 -0700 Subject: [PATCH 101/113] add another function to reduce code duplication --- user/textGame.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index 1a17290..e64705e 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -34,6 +34,10 @@ void removeTrailingNewline(char *string){ } } +int getInputAndCompare(char *userInput, char *comparisonString){ + +} + int shouldBuyStuff(char *responseInput){ // allow user to buy stuff printf("would you like to buy some things yes/no\n"); From 38b7548321724e969edadb6a1b117eac7c71f80a Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:42:37 -0700 Subject: [PATCH 102/113] fill in actual implementation --- user/textGame.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index e64705e..6f1b00d 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -35,7 +35,12 @@ void removeTrailingNewline(char *string){ } int getInputAndCompare(char *userInput, char *comparisonString){ - + gets(userInput, 128); + removeTrailingNewline(userInput); + if (strcmp(userInput, comparisonString) == 0){ + return 1; + } + return 0; } int shouldBuyStuff(char *responseInput){ From 1c744a4bac26b9e00f5725f7e344885e3eab929e Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:50:16 -0700 Subject: [PATCH 103/113] use ternary operator to simplify --- user/textGame.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index 6f1b00d..1b6e271 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -37,10 +37,7 @@ void removeTrailingNewline(char *string){ int getInputAndCompare(char *userInput, char *comparisonString){ gets(userInput, 128); removeTrailingNewline(userInput); - if (strcmp(userInput, comparisonString) == 0){ - return 1; - } - return 0; + return ((strcmp(userInput, comparisonString) == 0)? 1 : 0);//1 if they match, 0 otherwise } int shouldBuyStuff(char *responseInput){ From 5c67c0bb9c75a1509510ed3de549aa26299aaa57 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:52:42 -0700 Subject: [PATCH 104/113] test using this func in shouldbuy --- user/textGame.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index 1b6e271..a6b464d 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -37,18 +37,14 @@ void removeTrailingNewline(char *string){ int getInputAndCompare(char *userInput, char *comparisonString){ gets(userInput, 128); removeTrailingNewline(userInput); + //probably could just return (strcmp(userInput, comparisonString) == 0), but wanting to be explicit about the return here return ((strcmp(userInput, comparisonString) == 0)? 1 : 0);//1 if they match, 0 otherwise } int shouldBuyStuff(char *responseInput){ // allow user to buy stuff printf("would you like to buy some things yes/no\n"); - gets(responseInput, 128); - removeTrailingNewline(responseInput); - if (strcmp(responseInput, "yes") == 0){//said yes to buying - return 1; - } - return 0; //didn't want to buy + return getInputAndCompare(responseInput, "yes"); } int shouldSellStuff(char *responseInput){ From 9c7e3a0f2acdc6e0876640639b815c588d7f78d2 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:56:37 -0700 Subject: [PATCH 105/113] test simplifying return further --- user/textGame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index a6b464d..b7e6e30 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -38,7 +38,7 @@ int getInputAndCompare(char *userInput, char *comparisonString){ gets(userInput, 128); removeTrailingNewline(userInput); //probably could just return (strcmp(userInput, comparisonString) == 0), but wanting to be explicit about the return here - return ((strcmp(userInput, comparisonString) == 0)? 1 : 0);//1 if they match, 0 otherwise + return (strcmp(userInput, comparisonString) == 0);//1 if they match, 0 otherwise } int shouldBuyStuff(char *responseInput){ From 5528db569e64ae316b8fbfbf54a110f31e03a7a3 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:58:22 -0700 Subject: [PATCH 106/113] remove unneeded comment --- user/textGame.c | 1 - 1 file changed, 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index b7e6e30..4da5932 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -37,7 +37,6 @@ void removeTrailingNewline(char *string){ int getInputAndCompare(char *userInput, char *comparisonString){ gets(userInput, 128); removeTrailingNewline(userInput); - //probably could just return (strcmp(userInput, comparisonString) == 0), but wanting to be explicit about the return here return (strcmp(userInput, comparisonString) == 0);//1 if they match, 0 otherwise } From 85cbdbe04af8554d3e8bf396f962858d7a9714e3 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 18:01:27 -0700 Subject: [PATCH 107/113] simplify should sell with this func --- user/textGame.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index 4da5932..c257674 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -49,12 +49,8 @@ int shouldBuyStuff(char *responseInput){ int shouldSellStuff(char *responseInput){ printf("would you like to sell some of your stuff?\n"); printf("yes/no\n"); - gets(responseInput, 128); - removeTrailingNewline(responseInput); - if (strcmp(responseInput, "yes") == 0){//said yes to selling - return 1; - } - return 0;// didn't want to sell + return getInputAndCompare(responseInput, "yes"); + } void performBuying(int *coinAmount, int *stuffAmount, char *responseInput){ From 67e9b263b7997e327c96ccdf181714eb9ac3f1b5 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 18:01:53 -0700 Subject: [PATCH 108/113] combine should sell print statements into 1 --- user/textGame.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index c257674..ef5acfe 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -47,8 +47,7 @@ int shouldBuyStuff(char *responseInput){ } int shouldSellStuff(char *responseInput){ - printf("would you like to sell some of your stuff?\n"); - printf("yes/no\n"); + printf("would you like to sell some of your stuff yes/no\n"); return getInputAndCompare(responseInput, "yes"); } From f6f4c5f098a8beb1ed5d597bf66cf4226895c82d Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 18:03:52 -0700 Subject: [PATCH 109/113] make user input for leaving use this func --- user/textGame.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index ef5acfe..41ad044 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -102,9 +102,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh break; } printf("how much to bet (type leave to leave the casino)\n"); - gets(betInput, 128); - removeTrailingNewline(betInput); - if (strcmp(betInput, "leave") == 0){//handle input of leave + if (getInputAndCompare(betInput, "leave")){//handle input of leave break; } //not leave, so now check if it is a valid bet @@ -124,9 +122,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh performSelling(&coins, &stuff, &randVal, 100, responseInput); } printf("would you like to leave yes/no\n"); - gets(responseInput, 128); - removeTrailingNewline(responseInput); - if (strcmp(responseInput, "yes") == 0){//said yes to leaving + if (getInputAndCompare(responseInput, "yes")){//said yes to leaving break; } } From aacac33530bf584ea31d52eafb97b3cfed4f0c76 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 18:20:16 -0700 Subject: [PATCH 110/113] delete extra blank line combining shouldbuy and should sell next --- user/textGame.c | 1 - 1 file changed, 1 deletion(-) diff --git a/user/textGame.c b/user/textGame.c index 41ad044..c949438 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -49,7 +49,6 @@ int shouldBuyStuff(char *responseInput){ int shouldSellStuff(char *responseInput){ printf("would you like to sell some of your stuff yes/no\n"); return getInputAndCompare(responseInput, "yes"); - } void performBuying(int *coinAmount, int *stuffAmount, char *responseInput){ From b01fd8ff9ac85f5bea5b752bbbbeba2b55b6ffb3 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 18:27:59 -0700 Subject: [PATCH 111/113] finish combining them --- user/textGame.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/user/textGame.c b/user/textGame.c index c949438..648cf58 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -51,6 +51,11 @@ int shouldSellStuff(char *responseInput){ return getInputAndCompare(responseInput, "yes"); } +int shouldBuyOrSellStuff(char *responseInput, int isSelling){//isSelling is 1 if selling, 0 if buying + printf("would you like to %s\n", (isSelling ? "sell some of your stuff yes/no" : "buy some things yes/no"));//use ternary operator to change the print depending on if buying or selling + return getInputAndCompare(responseInput, "yes"); +} + void performBuying(int *coinAmount, int *stuffAmount, char *responseInput){ printf("how many things would you like to buy for $50 each?\n"); gets(responseInput, 128);// get amount to buy in response var From 092533e4db25618d8758557a40bc33d2dc8aead3 Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 18:33:22 -0700 Subject: [PATCH 112/113] remove shouldBuy and ShouldSell will replace them with new function now --- user/textGame.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index 648cf58..137aa8b 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -40,17 +40,6 @@ int getInputAndCompare(char *userInput, char *comparisonString){ return (strcmp(userInput, comparisonString) == 0);//1 if they match, 0 otherwise } -int shouldBuyStuff(char *responseInput){ - // allow user to buy stuff - printf("would you like to buy some things yes/no\n"); - return getInputAndCompare(responseInput, "yes"); -} - -int shouldSellStuff(char *responseInput){ - printf("would you like to sell some of your stuff yes/no\n"); - return getInputAndCompare(responseInput, "yes"); -} - int shouldBuyOrSellStuff(char *responseInput, int isSelling){//isSelling is 1 if selling, 0 if buying printf("would you like to %s\n", (isSelling ? "sell some of your stuff yes/no" : "buy some things yes/no"));//use ternary operator to change the print depending on if buying or selling return getInputAndCompare(responseInput, "yes"); From 39256fd79f997a113b28be897c2b4fde336c612a Mon Sep 17 00:00:00 2001 From: CB4747 <123422381+CB4747@users.noreply.github.com> Date: Mon, 23 Sep 2024 18:34:48 -0700 Subject: [PATCH 113/113] replace usage of shouldbuy and shouldsell with new func --- user/textGame.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/user/textGame.c b/user/textGame.c index 137aa8b..94b9abc 100644 --- a/user/textGame.c +++ b/user/textGame.c @@ -110,7 +110,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh if (roll == 1){// win more coins if roll is one coins = coins + atoi(betInput)*48;//win 48 times your bet printf("you won\n"); - if (shouldSellStuff(responseInput)){//does the user want to sell + if (shouldBuyOrSellStuff(responseInput, 1)){//does the user want to sell printf("you have %d things\n", stuff);// print out how much stuff we have, so the user knows performSelling(&coins, &stuff, &randVal, 100, responseInput); } @@ -123,7 +123,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh stuff=stuff+(atoi(betInput));// win your bet in stuff printf("you won %d things\n", atoi(betInput)); printf("you have %d things\n", stuff); - if (shouldBuyStuff(responseInput)){//user wants to buy things + if (shouldBuyOrSellStuff(responseInput, 0)){//user wants to buy things performBuying(&coins, &stuff, responseInput); } @@ -136,7 +136,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh printf("you have $%d\n", coins);//print money after bet //now allow the user to sell stuff if they are out of money. if (coins <= 0){//not enough money - if (shouldSellStuff(responseInput)){//user wants to sell + if (shouldBuyOrSellStuff(responseInput, 1)){//user wants to sell if (stuff<=0){//out of money and stuff printf("not enough stuff\n"); break; @@ -148,7 +148,7 @@ int main() {// a reimplementation of a simple casino game I wrote in python a wh } } // allow user to buy stuff - if (shouldBuyStuff(responseInput)){//user wants to buy things + if (shouldBuyOrSellStuff(responseInput, 0)){//user wants to buy things performBuying(&coins, &stuff, responseInput); } }