Haskell Games

Computer builds, hardware and software discussion or troubleshooting, including peripherals. Essentially a general place to talk about desktop computers.
Locked
Anonymous

Haskell Games

Post by Anonymous »

Hey guys,
i'm looking for a basic game written in haskell ie. rock paper scissors or high low if anyone had any links to somewhere i could get it or if anyone could post anything it would be great help!!

thanks

Archived topic from Iceteks, old topic ID:3329, old post ID:26987
wtd
Posts: 157
Joined: Sat Sep 25, 2004 7:21 pm

Haskell Games

Post by wtd »

A basic guess the number game in Haskell.

Code: Select all

module Main where

import System
import Random
import IO

makeGuesses :: Int -> Int -> IO ()
makeGuesses _ 0 = return ()
makeGuesses correctAnswer nGuessesRemaining =
   do
      putStr "Your guess? "
      hFlush stdout
      input <- getLine
      let guess = read input
      case compare guess correctAnswer of
         LT -> do
            putStrLn "Too low!"
            makeGuesses correctAnswer (nGuessesRemaining - 1)
         EQ -> do
            putStrLn "Correct!"
            return ()
         GT -> do
            putStrLn "Too high!"
            makeGuesses correctAnswer (nGuessesRemaining - 1)

main :: IO ()
main = do
   (maxNumberS:nGuessesS:_) <- getArgs
   let (maxNumber, nGuesses) = map read (maxNumberS, nGuessesS)
   correctAnswer <- randomRIO (0, maxNumber)
   makeGuesses correctAnswer nGuesses[code] 

[color=#888888][size=85]Archived topic from Iceteks,  old topic ID:3329, old post ID:26988[/size][/color]
Locked