Anonymous user
Generate random chess position: Difference between revisions
m
→{{header|Haskell}}
No edit summary |
|||
Line 561:
import System.Random (getStdRandom, randomR, Random, random)
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 =
replaceSquareByPos :: (Square, Pos) -> ChessBoard -> ChessBoard
replaceSquareByPos (s, p) = map (\t@(s'', p'') -> if p == p'' then (s, p) else
isPosOccupied :: Pos -> ChessBoard -> Bool
Line 728 ⟶ 727:
placeRemaining :: ChessBoard -> IO ChessBoard
placeRemaining b = do
n <- num (sum $ map
putStrLn $ "Taking " <> show n <>
" more random positions after placing 2 kings and "
<> (show $ totalPawns b) <> " pawns. "
go remaining b n
|