How can I resolve this code challenge? -


your challenge implement game described here. description refers picking number, means computer should pick random number between 1 , 10.

the computer picks 1 number dealer, , picks 2 numbers player. these numbers displayed player.

the player can ask computer pick more numbers player, 1 @ time, if sum of numbers goes on 21 have lost game.

once player happy set of numbers, computer pick numbers dealer until sum of numbers 16 or higher.

if dealer's numbers sum more 21, player wins game. otherwise, highest-scoring set of numbers wins game.

basically, don't know if understand question correctly. think problem questionable.

as player cannot predict future pick , cannot revert last pick, stop-pick time when player happy? can know dealer's price on 16, if initial pick below 16, chooses pick more numbers. after numbers sum on 16, how do? if aggressive, continue pick. or if conservative, stop , happy.

so problem questionable!!


updated: i'm sure misunderstand problem. need let player himself determine if happy. thought code should intelligently him. that's impossible. input in code now.

import java.io.bufferedreader; import java.io.inputstreamreader; import java.util.random;  public class playgame {      private random random = new random();     bufferedreader br = new bufferedreader(new inputstreamreader(system.in));     private int dealer_sum = 0;     private int player_sum = 0;      private static final string won = "won";     private static final string lost = "lost";     private static final string = "even";      public static void main(string[] args) throws exception  {         string result = new playgame().play();         system.out.println("-----final result------");         system.out.println(result);     }      public string play() throws exception {         system.out.println("-----inital round------");         dealer_pick();         player_pick();         player_pick();          system.out.println("-----player round------");          while(true) {             system.out.println("are happy now? ");             if("n".equals(br.readline())) {                 player_pick();                 if(player_sum > 21) return lost;                 continue;             }             break;         }          if(player_sum > 21) return lost;          system.out.println("-----dealer round------");         while(dealer_sum < 16) {             dealer_pick();         }          if(dealer_sum > 21) return won;         if(player_sum == dealer_sum) return even;         return (player_sum > dealer_sum) ? won : lost;     }      private int player_pick() {         int num = pick();         player_sum += num;         system.out.println("player: " + num + " => " + player_sum);          return num;     }      private void dealer_pick() {         int num = pick();         dealer_sum += num;         system.out.println("dealer: " + num + " => " + dealer_sum);     }      private int pick() {         return random.nextint(10) + 1;     } } 


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -