Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 4.90 KB | None | 0 0
  1. module rock_paper_scissors
  2.  
  3. open System
  4.  
  5. let rec start_game acc wins =
  6.  
  7.             if acc > 0.0
  8.             then printf "Do you want to play again (Y/N) "
  9.                  let decision = Console.ReadLine()
  10.                  match decision with
  11.                      |"N" ->  printfn "\nThanks for playing. \nYou won %.1f percent of the time." (((wins:float) / (acc:float)) * 100.0)
  12.                      |"Y" ->  
  13.                      
  14.                                 printf "\nEnter your selection (0=Rock, 1=Paper, 2=Scissors): "
  15.    
  16.                                 let selection = Console.ReadLine()
  17.  
  18.  
  19.                                 let seed = Random ()
  20.                                 let cpuSelection = seed.Next(0,2)
  21.    
  22.                                 //printfn "%A cpu %A" selection cpuSelection
  23.                                 match selection with
  24.                                      |"0"-> printf "My selection is : 0 = Rock      "
  25.                                             if cpuSelection = 0
  26.                                             then printfn"Tie"
  27.                                                  start_game (acc + 1.0) (wins)
  28.                                             elif cpuSelection = 2
  29.                                             then printfn "You win"
  30.                                                  start_game (acc + 1.0) (wins + 1.0)
  31.                                             else printfn "You lose"
  32.                                                  start_game (acc + 1.0) (wins)
  33.  
  34.                                      |"1"-> printf "My selection is : 1 = Paper      "
  35.                                             if cpuSelection = 1
  36.                                             then printfn"tie"
  37.                                                  start_game (acc + 1.0) (wins)
  38.                                             elif cpuSelection = 0
  39.                                             then printfn "You win"
  40.                                                  start_game (acc + 1.0) (wins + 1.0)
  41.                                             else printfn "You lose"
  42.                                                  start_game (acc + 1.0) (wins)
  43.                                      |"2"-> printf "My selection is : 2 = Scissors     "
  44.                                             if cpuSelection = 2
  45.                                             then printfn"tie"
  46.                                                  start_game (acc + 1.0) (wins)
  47.                                             elif cpuSelection = 1
  48.                                             then printfn "You win"
  49.                                                  start_game (acc + 1.0) (wins + 1.0)
  50.                                             else printfn "You lose"
  51.                                                  start_game (acc + 1.0) (wins)
  52.                                      |_ ->  printf("dss")  
  53.                      |_ ->   printf ""
  54.             else
  55.                 printf "Enter your selection (0=Rock, 1=Paper, 2=Scissors): "
  56.    
  57.                 let selection = Console.ReadLine()
  58.  
  59.  
  60.                 let seed = Random ()
  61.                 let cpuSelection = seed.Next(0,2)
  62.    
  63.                 //printfn "%A cpu %A" selection cpuSelection
  64.                 match selection with
  65.                      |"0"-> printf "My selection is : 0 = Rock      "
  66.                             if cpuSelection = 0
  67.                             then printfn"Tie"
  68.                                  start_game (acc + 1.0) (wins)
  69.                             elif cpuSelection = 2
  70.                             then printfn "You win"
  71.                                  start_game (acc + 1.0) (wins + 1.0)
  72.                             else printfn "You lose"
  73.                                  start_game (acc + 1.0) (wins)
  74.  
  75.                      |"1"-> printf "My selection is : 1 = Paper      "
  76.                             if cpuSelection = 1
  77.                             then printfn"tie"
  78.                                  start_game (acc + 1.0) (wins)
  79.                             elif cpuSelection = 0
  80.                             then printfn "You win"
  81.                                  start_game (acc + 1.0) (wins + 1.0)
  82.                             else printfn "You lose"
  83.                                  start_game (acc + 1.0) (wins)
  84.                      |"2"-> printf "My selection is : 2 = Scissors     "
  85.                             if cpuSelection = 2
  86.                             then printfn"tie"
  87.                                  start_game (acc + 1.0) (wins)
  88.                             elif cpuSelection = 1
  89.                             then printfn "You win"
  90.                                  start_game (acc + 1.0) (wins + 1.0)
  91.                             else printfn "You lose"
  92.                                  start_game (acc + 1.0) (wins)
  93.                      |_ ->  printf("dss")
  94.  
  95.  
  96. start_game 0.0 0.0
  97. System.Console.ReadKey() |> ignore
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement