{ hunk ./hback.hs 14 +import Debug.Trace (trace) hunk ./hback.hs 68 +logFileName = "user_scores.db" hunk ./hback.hs 116 -gameScore v' a' = num / den +gameScore v' a' = trace (show num ++ " / " ++ show den) $ num / den hunk ./hback.hs 183 - visuals <- genStim imgList [] level (level + blockSize) - audios <- genStim sndList [] level (level + blockSize) + visuals <- genStim level (level + blockSize) imgList [] + audios <- genStim level (level + blockSize) sndList [] + trace (show visuals ++ "\n" ++ show audios) return () hunk ./hback.hs 192 - where - genStim :: Ord a => [a] -> [a] -> Int -> Int -> IO ([(a, Maybe Bool)]) - genStim lst hist n cnt - | cnt < 1 = return [] - | otherwise = do - c <- if (length hist < n) - then (randomElem lst Nothing) - else (randomElem lst (Just (head hist))) - lst' <- genStim lst (hist ++ [fst c]) n (cnt - 1) - return $ c : lst' + +-- |genStim level n elementsToChooseFrom accumulator +-- makes list n-elements long where for each elem: +-- 50% chance it returns same elem as (l items ago); else returns random elem from elems (equal probabilities) +genStim :: Ord a => Int -> Int -> [a] -> [(a, Maybe Bool)] -> IO ([(a, Maybe Bool)]) +genStim l n elems acc + | n < 1 = return $ reverse acc + | otherwise = do + r <- getStdRandom (randomR (0.0, 1.0)) :: IO Double + let mElem = fmap fst $ maybeNth l acc + let elems' = case mElem of + Just e -> remove e elems + Nothing -> elems + i <- getStdRandom (randomR (0, dec (length elems'))) + let acc' = chooseWithThreshold 0.5 r elems' i mElem + genStim l (dec n) elems (acc' : acc) + +chooseWithThreshold :: Double -> Double -> [a] -> Int -> Maybe a -> (a, Maybe Bool) +chooseWithThreshold _ _ [] index Nothing = error "chooseWithThreshold needs at minimum non-empty list or Just element" +chooseWithThreshold _ _ [] index (Just x) = (x, Nothing) +chooseWithThreshold _ _ xs index Nothing = (xs !! index, Nothing) +chooseWithThreshold t v xs index (Just x) + | t <= v = (x, Just True) + | otherwise = (xs !! index, Just False) hunk ./hback.hs 270 - renderImage (guiDrawArea gui) $ renderRect vZ - playSound aZ - toggleButtonSetActive (guiVButton gui) False hunk ./hback.hs 271 + toggleButtonSetActive (guiVButton gui) False + playSound aZ + renderImage (guiDrawArea gui) $ renderRect vZ hunk ./hback.hs 282 - return ((score vB' b1), (score aB' b2)) + return $ trace (show ((score vB' b1), (score aB' b2))) + ((score vB' b1), (score aB' b2)) hunk ./hback.hs 398 - bracket (openFile "user_score_history.db" AppendMode) hClose + bracket (openFile logFileName AppendMode) hClose hunk ./hback.hs 407 - bracket (openFile "user_score_history.db" AppendMode) hClose + bracket (openFile logFileName AppendMode) hClose hunk ./hback.hs 412 +remove :: Ord a => a -> [a] -> [a] +remove a = filter (/= a) + hunk ./hback.hs 416 -inc = (1+) +inc = (+1) + +dec :: Int -> Int +dec n = n - 1 + [_$_] +maybeNth :: Int -> [a] -> Maybe a +maybeNth n lst + | n < 1 = error "maybeNth: n < 1 not allowed" + | otherwise = let l = drop (dec n) lst + in if (null l) + then Nothing + else (Just (head l)) + [_$_] + hunk ./hback.hs 431 --- |randomElem lst c : 50% chance it returns c; else return random elem from lst (equal probabilities) -randomElem :: Ord a => [a] -> Maybe a -> IO (a, Maybe Bool) -randomElem lst c' = do - case c' of - Nothing -> aux lst Nothing - Just c -> do - x <- getStdRandom (randomR (0.0, 1.0)) :: IO Double - case (x <= 0.5) of - True -> return (c, Just True) - False -> aux (filter (c /=) lst) $ Just False - where - aux [] _ = error "randomElem: List should not be empty" - aux l v = do - y <- getStdRandom (randomR (1, length l)) - return $ (l !! (y - 1), v) }