Merge branch 'coding-horror:main' into main

This commit is contained in:
Anthony Rubick
2022-09-08 19:29:42 -07:00
committed by GitHub
15 changed files with 399 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
Conversion to [C++14](https://en.wikipedia.org/wiki/C%2B%2B14)
The build folder are executables for x86 and x64 systems. Compiled and built using Visual Studio.

View File

@@ -0,0 +1,123 @@
#include <iostream>
#include <time.h>
#include "Aceyducey.h"
int main()
{
//Setting Seed for the Random Generator
srand((unsigned int)time(NULL));
bool isPlaying(true);
Money = 100;
WelcomeMessage();
while (isPlaying)
{
Play(isPlaying);
}
printf("O.K., HOPE YOU HAD FUN!\n");
}
void WelcomeMessage()
{
for (int i = 0; i < 25; i++)
{
printf(" ");
}
printf("ACEY DUCEY CARD GAME\n");
for (int i = 0; i < 14; i++)
{
printf(" ");
}
printf("CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n\n\nACEY-DUCEY IS PLAYED IN THE FOLLOWING MANNER \n");
printf("THE DEALER (COMPUTER) DEALS TWO CARDS FACE UP\nYOU HAVE AN OPTION TO BET OR NOT BET DEPENDING\n");
printf("ON WHETHER OR NOT YOU FEEL THE CARD WILL HAVE\nA VALUE BETWEEN THE FIRST TWO.\n");
printf("IF YOU DO NOT WANT TO BET, INPUT A 0\n");
}
void Play(bool& isPlaying)
{
short int DealerCards[2];
int Bet;
short int CurrentCard;
printf("YOU NOW HAVE %d DOLLARS.\n\n", Money);
printf("HERE ARE YOUR NEXT TWO CARDS: \n");
//Draw Dealers Cards
DrawCard(DealerCards[0]);
printf("\n");
DrawCard(DealerCards[1]);
printf("\n\n\n");
//Check if Bet is Valid
do {
printf("WHAT IS YOUR BET: ");
std::cin >> Bet;
if (Bet == 0)
{
printf("CHICKEN!!\n\n");
}
} while (Bet > Money || Bet < 0);
//Draw Players Card
DrawCard(CurrentCard);
printf("\n");
if (CurrentCard > DealerCards[0] && CurrentCard < DealerCards[1])
{
printf("YOU WIN!!!\n");
Money += Bet;
return;
}
else
{
printf("SORRY, YOU LOSE\n");
Money -= Bet;
}
if (isGameOver())
{
printf("TRY AGAIN (YES OR NO)\n\n");
std::string response;
std::cin >> response;
if (response != "YES")
{
isPlaying = false;
}
Money = 100;
}
}
bool isGameOver()
{
if (Money <= 0)
{
printf("\n\n");
printf("SORRY, FRIEND, BUT YOU BLEW YOUR WAD.\n\n");
return true;
}
return false;
}
void DrawCard(short int& Card)
{
//Basically generate 2 numbers first one is between 2-11 and second one 0-3
short int RandomNum1 = (rand() % 10) + 2;
short int RandomNum2 = rand() % 4;
Card = RandomNum1 + RandomNum2;
switch (Card)
{
case 11:
printf("JACK");
break;
case 12:
printf("QUEEN");
break;
case 13:
printf("KING");
break;
case 14:
printf("ACE");
break;
default:
printf("%d", Card);
}
}

View File

@@ -0,0 +1,7 @@
#pragma once
void WelcomeMessage();
void DrawCard(short int& Card);
void Play(bool& isPlaying);
bool isGameOver();
int Money;

View File

@@ -0,0 +1,92 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
//check if windows or linux for the clear screen
#ifdef _WIN32
#define CLEAR "cls"
#else
#define CLEAR "clear"
#endif
void show_solution(float guess);
float guess_number(float number);
void game();
float guess_number(float number){
float guess;
guess = ((((number - 4) * 5) / 8) * 5 - 3);
return guess;
}
void game(){
float number,guess;
char answer[4];
printf("Think a number\n");
printf("Then add to it 3 and divide it by 5\n");
printf("Now multiply by 8, divide by 5 and then add 5\n");
printf("Finally substract 1\n");
printf("What is the number you got?(if you got decimals put them ex: 23.6): ");
scanf("%f",&number);
guess = guess_number(number);
printf("The number you thought was %f am I right(Yes or No)?\n",guess);
scanf("%s",answer);
for(int i = 0; i < strlen(answer); i++){
answer[i] = tolower(answer[i]);
}
if(strcmp(answer,"yes") == 0){
printf("\nHuh, I Knew I was unbeatable");
printf("And here is how i did it:\n");
show_solution(guess);
}
else if (strcmp(answer,"no") == 0){
printf("HUH!! what was you original number?: ");
scanf("%f",&number);
if(number == guess){
printf("Huh, I Knew I was unbeatable");
printf("And here is how i did it:\n");
show_solution(guess);
}
else{
printf("If I got it wrong I guess you are smarter than me");
}
}
else{
system(CLEAR);
printf("I don't understand what you said\n");
printf("Please answer with Yes or No\n");
game();
}
}
void show_solution(float guess){
printf("%f plus 3 is %f\n",guess,guess + 3);
printf("%f divided by 5 is %f\n",guess + 3,(guess + 3) / 5);
printf("%f multiplied by 8 is %f\n",(guess + 3) / 5,(guess + 3) / 5 * 8);
printf("%f divided by 5 is %f\n",(guess + 3) / 5 * 8,(guess + 3) / 5 * 8 / 5);
printf("%f plus 5 is %f\n",(guess + 3) / 5 * 8 / 5,(guess + 3) / 5 * 8 / 5 + 5);
printf("%f minus 1 is %f\n",(guess + 3) / 5 * 8 / 5 + 5,(guess + 3) / 5 * 8 / 5 + 5 - 1);
}
void main(){
char answer[4];
printf("I am CHIEF NUMBERS FREEK, The GREAT INDIAN MATH GOD.\n");
printf("Are you ready to take the test you called me out for(Yes or No)? ");
scanf("%s",answer);
for(int i = 0; i < strlen(answer); i++){
answer[i] = tolower(answer[i]);
}
if(strcmp(answer,"yes") == 0){
game();
}else if (strcmp(answer,"no") == 0){
printf("You are a coward, I will not play with you.%d %s\n",strcmp(answer,"yes"),answer);
}
else{
system(CLEAR);
printf("I don't understand what you said\n");
printf("Please answer with Yes or No\n");
main();
}
}

View File

@@ -0,0 +1,142 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//check if windows or linux for the clear screen
#ifdef _WIN32
#define CLEAR "cls"
#else
#define CLEAR "clear"
#endif
typedef struct{
int x;
int y;
int z;
}coords;
void instuctions(){
printf("\nThis is a game in which you will be playing against the\n");
printf("random decisions of the computer. The field of play is a\n");
printf("cube of side 3. Any of the 27 locations can be designated\n");
printf("by inputing three numbers such as 2,3,1. At the start,\n");
printf("you are automatically at location 1,1,1. The object of\n");
printf("the game is to get to location 3,3,3. One minor detail:\n");
printf("the computer will pick, at random, 5 locations at which\n");
printf("it will plant land mines. If you hit one of these locations\n");
printf("you lose. One other detail: You may move only one space\n");
printf("in one direction each move. For example: From 1,1,2 you\n");
printf("may move to 2,1,2 or 1,1,3. You may not change\n");
printf("two of the numbers on the same move. If you make an illegal\n");
printf("move, you lose and the computer takes the money you may\n");
printf("have bet on that round.\n\n");
printf("When stating the amount of a wager, printf only the number\n");
printf("of dollars (example: 250) you are automatically started with\n");
printf("500 dollars in your account.\n\n");
printf("Good luck!\n");
}
void game(int money){
coords player,playerold,mines[5];
int wager,account = money;
char choice;
if(money == 0){
printf("You have no money left. See ya next time.\n");
exit(0);
}
player.x = 1;
player.y = 1;
player.z = 1;
printf("You have $%d in your account.\n",account);
printf("How much do you want to wager? ");
scanf("%d",&wager);
while(wager > account){
system(CLEAR);
printf("You do not have that much money in your account.\n");
printf("How much do you want to wager? ");
scanf("%d",&wager);
}
srand(time(NULL));
for(int i=0;i<5;i++){
mines[i].x = rand()%3+1;
mines[i].y = rand()%3+1;
mines[i].z = rand()%3+1;
if(mines[i].x == 3 && mines[i].y == 3 && mines[i].z == 3){
i--;
}
}
while(player.x != 3 || player.y != 3 || player.z != 3){
printf("You are at location %d.%d.%d\n",player.x,player.y,player.z);
if(player.x == 1 && player.y == 1 && player.z == 1)
printf("Enter new location(use commas like 1,1,2 or else the program will break...): ");
else printf("Enter new location: ");
playerold.x = player.x;
playerold.y = player.y;
playerold.z = player.z;
scanf("%d,%d,%d",&player.x,&player.y,&player.z);
if(((player.x + player.y + player.z) > (playerold.x + playerold.y + playerold.z + 1)) || ((player.x + player.y + player.z) < (playerold.x + playerold.y + playerold.z -1))){
system(CLEAR);
printf("Illegal move!\n");
printf("You lose $%d.\n",wager);
game(account -= wager);
break;
}
if(player.x < 1 || player.x > 3 || player.y < 1 || player.y > 3 || player.z < 1 || player.z > 3){
system(CLEAR);
printf("Illegal move. You lose!\n");
game(account -= wager);
break;
}
for(int i=0;i<5;i++){
if(player.x == mines[i].x && player.y == mines[i].y && player.z == mines[i].z){
system(CLEAR);
printf("You hit a mine!\n");
printf("You lose $%d.\n",wager);
game(account -= wager);
exit(0);
}
}
if(account == 0){
system(CLEAR);
printf("You have no money left!\n");
printf("Game over!\n");
exit(0);
}
}
if(player.x == 3 && player.y == 3 && player.z == 3){
system(CLEAR);
printf("You made it to the end. You win!\n");
game(account += wager);
exit(0);
}
}
void init(){
int account = 500;
char choice;
printf("Welcome to the game of Cube!\n");
printf("wanna see the instructions? (y/n): ");
scanf("%c",&choice);
if(choice == 'y'){
system(CLEAR);
instuctions();
}
else if (choice == 'n'){
system(CLEAR);
printf("Ok, let's play!\n");
}
else{
system(CLEAR);
printf("Invalid choice. Try again...\n");
init();
exit(0);
}
game(account);
exit(0);
}
void main(){
init();
}

View File

@@ -0,0 +1,26 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
float percent(int number, int total){
float percent;
percent = (float)number / (float)total * 100;
return percent;
}
int main(){
int dice1,dice2,times,rolls[13] = {0};
srand(time(NULL));
printf("This program simulates the rolling of a pair of dice\n");
printf("How many times do you want to roll the dice?(Higher the number longer the waiting time): ");
scanf("%d",&times);
for(int i = 0; i < times; i++){
dice1 = rand() % 6 + 1;
dice2 = rand() % 6 + 1;
rolls[dice1 + dice2]+=1;
}
printf("The number of times each sum was rolled is:\n");
for(int i = 2; i <= 12; i++){
printf("%d: rolled %d times, or %f%c of the times\n",i,rolls[i],percent(rolls[i],times),(char)37);
}
}

View File

@@ -902,7 +902,10 @@ class Game:
if len(command) == 0:
com = 6
else:
com = int(command)
try:
com = int(command)
except ValueError:
com = 6
if com < 0:
return