Generate random chess position: Difference between revisions

m
No edit summary
Line 561:
 
import System.Random (getStdRandom, randomR, Random, random)
import Data.Maybe (isJust)
import Data.List (find, sortBy)
import Data.Ord (comparing)
Line 597 ⟶ 596:
randomR (a, b) g =
case randomR (fromEnum a, fromEnum b) g of
(x, g'') -> (toEnum x, g'')
random g = randomR (minBound, maxBound) g
 
Line 603 ⟶ 602:
randomR (a, b) g =
case randomR (fromEnum a, fromEnum b) g of
(x, g'') -> (toEnum x, g'')
random g = randomR (minBound, maxBound) g
Line 624 ⟶ 623:
 
emptyBoard :: ChessBoard
emptyBoard = map (\p -> [(EmptySquare, p)) [(x,y)) | x <-['a'..'h'], y <- [1..8]]
 
replaceSquareByPos :: (Square, Pos) -> ChessBoard -> ChessBoard
replaceSquareByPos (s, p) = map (\t@(s'', p'') -> if p == p'' then (s, p) else (s'', p'')t)
 
isPosOccupied :: Pos -> ChessBoard -> Bool
Line 728 ⟶ 727:
placeRemaining :: ChessBoard -> IO ChessBoard
placeRemaining b = do
n <- num (sum $ map (\(_, c) -> c)snd remaining)
putStrLn $ "Taking " <> show n <> " more random positions after placing 2 kings and "
" more random positions after placing 2 kings and "
<> (show $ totalPawns b) <> " pawns. "
go remaining b n
Anonymous user