Last active
August 29, 2015 14:22
-
-
Save macrat/dac3605c75297da44cac to your computer and use it in GitHub Desktop.
賭けじゃんけん。猛烈につまらないコードになった。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <time.h> | |
#include <stdbool.h> | |
#define FUNDS_INITIAL 50000 | |
#define MINIMAL_PREMIUM 100 | |
const char* HANDS[] = {"guu", "choki", "paa"}; | |
int inputInt(const int min, const int max) | |
{ | |
int result; | |
while(scanf("%d", &result) != 1 || result < min || max < result); | |
return result; | |
} | |
bool janken() | |
{ | |
int result, cpu, user=-1; | |
do{ | |
printf("please input your hand(0: %s, 1: %s, 2: %s): ", HANDS[0], HANDS[1], HANDS[2]); | |
user = inputInt(0, 2); | |
cpu = rand()%3; | |
printf("your hand: %s\ncomputer hand: %s\n", HANDS[user], HANDS[cpu]); | |
result = (user - cpu + 3)%3; | |
printf("%s\n", ((char*[]){"drow", "your win!!", "lose"})[result]); | |
}while(result == 0); | |
return result == 1; | |
} | |
void showFunds(const int funds) | |
{ | |
printf("your funds: $%d\n", funds); | |
} | |
int desidePremium(const int funds) | |
{ | |
printf("please deside premium(%d-%d): ", MINIMAL_PREMIUM, funds); | |
return inputInt(MINIMAL_PREMIUM, funds); | |
} | |
int main() | |
{ | |
int funds = FUNDS_INITIAL; | |
srand(time(NULL)); | |
while(funds > MINIMAL_PREMIUM) | |
{ | |
showFunds(funds); | |
int premium = desidePremium(funds); | |
if(janken()) | |
funds += premium; | |
else | |
funds -= premium; | |
printf("\n"); | |
} | |
printf("..................\n\nyou couldn't keep minimal premium...\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment