Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (*
  2. * Angel T. Vazquez
  3. * 841-12-9051  
  4. *
  5. *Rock paper scissor games in f#
  6. *)
  7. module rock_paper_scissors
  8.  
  9. open System
  10.  
  11. let rec start_game acc wins =
  12.    
  13.         //Main loop of the game
  14.             if acc > 0.0
  15.             then printf "Do you want to play again (Y/N) "
  16.                  let decision = Console.ReadLine()
  17.                  match decision with
  18.                      |"N" ->  printfn "\nThanks for playing. \nYou won %.1f percent of the time." (((wins:float) / (acc:float)) * 100.0)
  19.                      |"Y" ->  
  20.                      
  21.                                 printf "\nEnter your selection (0=Rock, 1=Paper, 2=Scissors): " //Asks for user selection
  22.    
  23.                                 let selection = Console.ReadLine()
  24.  
  25.                 //Creates a random number between zero and two
  26.                                 let seed = Random ()
  27.                                 let cpuSelection = seed.Next(0,2)
  28.    
  29.                                 //Matches user selection with cpuselection
  30.                 //To determine winner
  31.                                 match selection with
  32.                                      |"0"-> printf "My selection is : 0 = Rock      "
  33.                                             if cpuSelection = 0
  34.                                             then printfn"Tie"
  35.                                                  start_game (acc + 1.0) (wins)
  36.                                             elif cpuSelection = 2
  37.                                             then printfn "You win"
  38.                                                  start_game (acc + 1.0) (wins + 1.0)
  39.                                             else printfn "You lose"
  40.                                                  start_game (acc + 1.0) (wins)
  41.  
  42.                                      |"1"-> printf "My selection is : 1 = Paper      "
  43.                                             if cpuSelection = 1
  44.                                             then printfn"tie"
  45.                                                  start_game (acc + 1.0) (wins)
  46.                                             elif cpuSelection = 0
  47.                                             then printfn "You win"
  48.                                                  start_game (acc + 1.0) (wins + 1.0)
  49.                                             else printfn "You lose"
  50.                                                  start_game (acc + 1.0) (wins)
  51.                                      |"2"-> printf "My selection is : 2 = Scissors     "
  52.                                             if cpuSelection = 2
  53.                                             then printfn"tie"
  54.                                                  start_game (acc + 1.0) (wins)
  55.                                             elif cpuSelection = 1
  56.                                             then printfn "You win"
  57.                                                  start_game (acc + 1.0) (wins + 1.0)
  58.                                             else printfn "You lose"
  59.                                                  start_game (acc + 1.0) (wins)
  60.                                      |_ ->  printf("dss")  
  61.                      |_ ->   printf ""
  62.             //When the game is just strating
  63.             else
  64.                 printf "Enter your selection (0=Rock, 1=Paper, 2=Scissors): "
  65.    
  66.                 let selection = Console.ReadLine()
  67.  
  68.  
  69.                 let seed = Random ()
  70.                 let cpuSelection = seed.Next(0,2)
  71.    
  72.                 //Matches user selection with cpu selection to determine winner
  73.                 match selection with
  74.                      |"0"-> printf "My selection is : 0 = Rock      "
  75.                             if cpuSelection = 0
  76.                             then printfn"Tie"
  77.                                  start_game (acc + 1.0) (wins)
  78.                             elif cpuSelection = 2
  79.                             then printfn "You win"
  80.                                  start_game (acc + 1.0) (wins + 1.0)
  81.                             else printfn "You lose"
  82.                                  start_game (acc + 1.0) (wins)
  83.  
  84.                      |"1"-> printf "My selection is : 1 = Paper      "
  85.                             if cpuSelection = 1
  86.                             then printfn"tie"
  87.                                  start_game (acc + 1.0) (wins)
  88.                             elif cpuSelection = 0
  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.                      |"2"-> printf "My selection is : 2 = Scissors     "
  94.                             if cpuSelection = 2
  95.                             then printfn"tie"
  96.                                  start_game (acc + 1.0) (wins)
  97.                             elif cpuSelection = 1
  98.                             then printfn "You win"
  99.                                  start_game (acc + 1.0) (wins + 1.0)
  100.                             else printfn "You lose"
  101.                                  start_game (acc + 1.0) (wins)
  102.                      |_ ->  printf("dss")
  103.  
  104.  
  105. start_game 0.0 0.0
  106. System.Console.ReadKey() |> ignore
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement