open System let RPS plr npc : int8 = match plr, npc with | 0 , 0 | 2 , 2 | 5 , 5 -> 0y // Draw | 0 , 2 | 2 , 5 | 5 , 0 -> 1y // Player wins | 0 , 5 | 5 , 2 | 2 , 0 -> 2y // NPC wins | 6 , _ -> -6y // Valid input from the player | _ -> 9y // Default case let Game : unit = let mutable local = 0 let mutable total = 0 let mutable again = ConsoleKey.Y while again = ConsoleKey.Y do local <- 0 printf "\n\n\t\t\tPLAYER\t\tNPC\t\tRESULT\n\n" for i in 1 .. 5 do printf " ROUND %d / 5 :\t\t" i let plr = match System.Console.ReadKey(true).Key with | ConsoleKey.NumPad0 | ConsoleKey.D0 | ConsoleKey.R -> Console.ForegroundColor <- ConsoleColor.Green printf "ROCK\t\t" 0 | ConsoleKey.NumPad2 | ConsoleKey.D2 | ConsoleKey.S -> Console.ForegroundColor <- ConsoleColor.Yellow printf "SCISSORS\t" 2 | ConsoleKey.NumPad5 | ConsoleKey.D5 | ConsoleKey.P -> Console.ForegroundColor <- ConsoleColor.Cyan printf "PAPER\t\t" 5 | _ -> Console.ForegroundColor <- ConsoleColor.DarkRed printf "???\t\t" 6 let npc = match (System.Random()).Next(0,3) with | 0 -> Console.ForegroundColor <- ConsoleColor.Green printf "ROCK\t\t" 0 | 1 -> Console.ForegroundColor <- ConsoleColor.Yellow printf "SCISSORS\t" 2 | _ -> Console.ForegroundColor <- ConsoleColor.Cyan printf "PAPER\t\t" 5 let dxs = match RPS plr npc with | 0y -> Console.ForegroundColor <- ConsoleColor.Cyan printf "TIE\n" +0 | 1y -> Console.ForegroundColor <- ConsoleColor.Green printf "WON\n" +1 | 2y -> Console.ForegroundColor <- ConsoleColor.Red printf "LOST\n" -1 | -6y -> Console.ForegroundColor <- ConsoleColor.DarkRed printf "???\n" -2 | _ -> -0 local <- local + dxs Console.ResetColor () match local with | _ when local > 0 -> total <- total + 1 | _ when local < 0 -> total <- total - 1 | _ -> () printf "\n >> YOUR TOTAL SCORE: %d\n" total printf "\n >> Do you want to play again ? (Y/N) " again <- Console.ReadKey(true).Key printf "\n\n - - - - - - - - - - - - - - - - - - - - - " printf "\n\n >> YOUR FINAL SCORE: %d " total () Console.ReadKey(true).Key |> ignore