Generate random chess position: Difference between revisions

m
m (→‎{{header|REXX}}: added/changed comments and whitespace; split some compound statement DO groups.)
Line 685:
 
-- State functions
randomStatewithStateGen :: (StdGen -> (a, StdGen)) -> State BoardState a
randomStatewithStateGen f = do
currentState <- get
let gen1 = generator currentState
Line 696:
randomPos = do
boardState <- gets board
numchr <- randomStatewithStateGen (randomR (1'a', 8'h'))
chrnum <- randomStatewithStateGen (randomR ('a'1, 'h'8))
let pos = (chr, num)
if isPosOccupied pos boardState then
randomPos
else
pure pos
 
randomPiece :: State BoardState Square
randomPiece = ChessPiece <$> randomStatewithStateGen random <*> randomStatewithStateGen random
 
placeKings :: State BoardState ()
Line 720:
 
placePawns :: State BoardState ()
placePawns = randomStatewithStateGen (randomR (1, 16)) >>= go
where
go :: Int -> State BoardState ()
Line 727:
currentState <- get
pos <- randomPos
color <- randomStatewithStateGen random
let pawn = ChessPiece Pawn color
let currentBoard = board currentState
Line 745:
placeRemaining :: State BoardState ()
placeRemaining =
randomStatewithStateGen (randomR (5, sum $ fmap snd remaining)) >>= go remaining
where
remaining = filter (\case
Anonymous user