You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.2 KiB

module Strategy2 where
import Datatypes
import Test.QuickCheck (generate, elements)
import VM
import System.Random
pick :: Int -> [a] -> a
pick n vector = vector !! (n `mod` (length vector))
strat2 :: Game -> ([Command],Int)
strat2 game = if new_notes == GameOver
then (new_command : [], score new_game)
else (new_command : (fst $ strat2 new_game), snd $ strat2 new_game)
where
commands = [MoveSE, MoveSW, MoveE, MoveW, RotateClockwise, RotateCounterclockwise]
new_games = map (\cmd -> (step game cmd, cmd)) commands
ok_games = filter (is_ok.snd.fst) new_games
where is_ok (OK) = True
is_ok _ = False
locked_games = filter (is_locked.snd.fst) new_games
where is_locked (Lock _) = True
is_locked _ = False
over_games = filter (is_over.snd.fst) new_games
where is_over (GameOver) = True
is_over _ = False
((new_game,new_notes),new_command) = if (length ok_games) > 0
then pick 741 ok_games
else if (length locked_games) > 0
then pick 568 locked_games
else pick 412 over_games