3C科技 娛樂遊戲 美食旅遊 時尚美妝 親子育兒 生活休閒 金融理財 健康運動 寰宇綜合

Zi 字媒體

2017-07-25T20:27:27+00:00
加入好友
[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提供 原文連結

寫了 5860316篇文章,獲得 23313次喜歡
精彩推薦