search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

[C/C++ 演算法]- Craps賭博遊戲 – jashliao部落格

[C/C++ 演算法]- Craps賭博遊戲


剛才找資料時發現一個C/C++的教學網站,趕快發揮(C/P)的長才將它備份來,有需要的同好,歡迎來(C/P)一下^^。

拷貝來源:
http://openhome.cc/Gossip/AlgorithmGossip/
http://openhome.cc/Gossip/AlgorithmGossip/CrapsGame.htm

#include 
#include 
#include 
#define LOST 0
#define WON 1
#define CONTINUE 2

int dice();
int initialRoll(int);
int reRoll(int, int);
int main(void) {
srand(time(0));
int firstPoint = dice();
printf("玩家點數:[%d]\n", firstPoint);
int status = initialRoll(firstPoint);
while(status == CONTINUE) {
int point = dice();
printf("玩家點數:%d\n", point);
status = reRoll(firstPoint, point);
}
puts(status == WON ? "玩家勝" : "玩家輸");
return 0;
}
int dice() {
return (rand() % 6) + (rand() % 6) + 2;
}
int initialRoll(int firstPoint) {
switch(firstPoint) {
case 7: case 11:         return WON;
case 2: case 3: case 12: return LOST;
default:                 return CONTINUE;
}
}
int reRoll(int firstPoint, int point) {
return firstPoint == point ? WON : (7 == point ? LOST : CONTINUE);
}


熱門推薦

本文由 jashliaoeuwordpress 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦