6 module SimpleStrat
(simpleStrat
) where
13 simpleStrat
:: Strategy
14 simpleStrat
= defaultStrategy
{
15 sName
= "SimpleStrat",
16 sAuthor
= "Bertram Felgenhauer <int-e@gmx.de>",
18 "This strategy makes inferences from exposed cells and their immediate \
19 \neighbourhood, and picks a random cell if no inference can be made.\n\
20 \It should be equivalent to the PGMS Single Point Strategy.",
24 worker
:: Config
-> StdGen -> StrategyM
String
27 let actions
= scan cfg view
28 if null actions
then randomMove cfg view gen
>>= worker cfg
29 else sequence_ actions
>> worker cfg gen
31 randomMove
:: Config
-> View
-> StdGen -> StrategyM
StdGen
32 randomMove cfg
@Config
{ cSize
= Pos sX sY
} view gen
= let
33 (x
, gen
') = randomR (1, sX
) gen
34 (y
, gen
'') = randomR (1, sY
) gen
'
37 if view
! p
== Hidden
then move p
>> return gen
''
38 else randomMove cfg view gen
''
40 scan
:: Config
-> View
-> [StrategyM
()]
41 scan cfg view
= concat
43 |
(p
, Exposed num
) <- assocs view
,
44 let ns
= neighbours cfg p
45 ms
= [n | n
<- ns
, view
! n
== Marked
]
46 us
= [n | n
<- ns
, view
! n
== Hidden
]
47 moves | num
== length ms
= [move_ n | n
<- us
]
48 | num
== length ms
+ length us
= [mark n | n
<- us
]