English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

In the game of craps,apass line bet proceeds as follows. Two six-sided dice are rolled;the first roll of the dice in a craps round is called the"come out roll."A comeout roll of 7 or 11 automatically wins, and a come out roll of 2,3, or 12 automati-cally loses. If 4,5,6,8,9, or 10 is rolled on the come out roll, that numberbecomes the point is rolled first, then the player wins the bet,If a 7 is rolled first,then the player loses.Write a program that simulates a game of craps using these rules without humaninput. Instead of asking for a wager, the program should calculate whether the playerwould win or lose.The program should simulate rolling the two dice and calculatethe sum.Add a loop so that the program plays 10,000 games.Add counters thatcount how many times the player wins, and how many times the player loses."At theend of the 10,000 games, compute the probability of winning [i.e., Wins/(Wins+Losses)] and output this value.Over the long run, who is going to win the most games,you or the house?Note.To generate a random number x , where 0x<=1,use x = Math.random();.For example, multiplying by 6 and converting to an integer results in an integer that is between 0 and 5.麻煩會的高手幫忙解答

2006-06-01 18:20:24 · 2 個解答 · 發問者 23歲九局下半 4 in 電腦與網際網路 程式設計

2 個解答

我先試翻一下題目,由於有關規則的第一段題意不清,因此我在網路上特別找了一下原始的規則,而翻譯上也與原文不盡相同,請包涵。 在雙骰子 (Craps)遊戲中,賭過關線(Pass Line Bets)的規則如下:在一個擲雙骰的回合中第一次擲骰子稱為擲現碼 (Come out roll)。如果玩家擲到點數 7 或 11,則贏這一回合;若擲到點數 2、3 或 12 則輸掉這一回合。若在擲現碼中點數為 4、5、6、8、9 或 10,則此點數就被標記起來做為評判勝負的標準,在之後擲骰子的點數中,若先出現與標記點數相同者,則玩家贏這一回合,若先擲出7點則玩家輸。 實作一個程式利用上述規則模擬雙骰子遊戲,但不需要使用者輸入。此程式僅計算玩家輸贏的次數,而非玩家所贏的賭注。程式必需模擬擲兩顆骰子並計算其加總,利用迴圈來跑 10,000 回合,使用計數器來記錄玩家輸贏的回合數。在跑了 10,000 回合後,算出玩家贏的機率 [贏的回合數 / (贏 + 輸的回合數)]並印出其值。在經過許多回合之後,是誰贏得大部份的回合數,玩家或莊家? 註記:要產生亂數值 x ( 0 <= x <= 1),請使用 x = Math.random()。例如,將 x 乘以 6 並轉成整數型態將產生一個介於 0 到 5 的整數。以下是我的解法,僅供參考。public class Craps { public static void main(String[] args) {  int win = 0, loss = 0, pt = 0, pt2 = 0;  for (int i = 0; i < 10000; i++) {   pt = (int)(Math.random() * 6) + 1; // Come out roll 的第一顆骰子   pt += (int)(Math.random() * 6) + 1; // Come out roll 的第二顆骰子   if (pt == 7 || pt == 11) { // 玩家在 Come out roll 贏的條件    win++;    continue;   } else if (pt == 2 || pt == 3 || pt == 12) { 玩家在 Come out roll 輸的條件    loss++;    continue;   } else { // Come out roll 點數設定後    while (true) {     pt2 = (int)(Math.random() * 6) + 1;     pt2 += (int)(Math.random() * 6) + 1;     if (pt2 == pt) { // 玩家擲出與設定點數相同時      win++;      break;     } else if (pt2 == 7) { // 玩家擲出 7 點      loss++;      break;     }    }   }  }    System.out.println("Player's probabililty of winning: " + (win / (float)(win + loss)));  if (win > loss) {   System.out.println("Player wins most of the rounds");  } else {   System.out.println("House wins most of the rounds");  } }}

2006-06-02 11:19:36 · answer #1 · answered by ? 7 · 0 0

●九州 娛樂 網站 http://ts777.cc
●●●運彩遊戲、真人遊戲、電子遊戲、對戰遊戲、對戰遊戲●●●

●新舊會員儲值就送500點

● 真人百家樂彩金等你拿

●線上影片直播、正妹圖、討論區免費註冊

歡迎免費體驗交流試玩!

●九州 娛樂 網站 http://ts777.cc

2015-02-24 13:23:03 · answer #2 · answered by ? 2 · 0 0

fedest.com, questions and answers