summaryrefslogtreecommitdiff
path: root/.stack-work/intero/intero15638-bM-STAGING.hs
diff options
context:
space:
mode:
Diffstat (limited to '.stack-work/intero/intero15638-bM-STAGING.hs')
-rw-r--r--.stack-work/intero/intero15638-bM-STAGING.hs132
1 files changed, 0 insertions, 132 deletions
diff --git a/.stack-work/intero/intero15638-bM-STAGING.hs b/.stack-work/intero/intero15638-bM-STAGING.hs
deleted file mode 100644
index ef7396b..0000000
--- a/.stack-work/intero/intero15638-bM-STAGING.hs
+++ /dev/null
@@ -1,132 +0,0 @@
1module Main where
2
3import Control.Lens
4import Linear.V2
5import Linear.V3
6import Data.Matrix
7--import Numeric.LinearAlgebra
8import System.Random
9import Foreign.Storable
10
11
12data Square = X -- Attacked
13 | Qu -- Queen
14 | O -- Open/available
15 deriving (Show, Eq)
16
17
18--board = V3 <$> [0..8] <*> [0..8] <*> [0]
19--board = [(r,c,X) | r <- [0..8], c <- [0..8] ]
20
21lo8 = [0..8] -- list of 8
22initBoard = matrix 8 8 $ \_ -> O
23
24placeQueen (r,c) b = placeQueen' $ markAttacked b
25 where
26 placeQueen' b = setElem Qu (r,c) b
27 markAttacked b = rowAttacked $ colAttacked $ diagAttacked b
28 fX = (\_ x -> X)
29 rowAttacked b = mapRow fX r b
30 colAttacked b = mapCol fX c b
31 diagAttacked b = let d = diag r c
32 attack ap ab = setElem X ap ab
33 attackall [x] = attack x b
34 attackall (x:xs) = attack x (attackall xs)
35 in attackall d
36-- in last $ map (\p -> setElem X p b) d
37-- in last $ scanr (\p -> setElem X p) b
38
39--solve b = placeQueen (nextAvail b) b
40
41nextAvail b = head [(x,y) | x <- [1..8], y <- [1..8], b ! (x,y) == O]
42
43-- solve b = placeQueen n
44-- where n = nextAvail b
45-- next = placeQueen n
46-- solve' =
47
48solve b =
49 where solve' b = (\n = placeQueen $ nextAvail b)
50
51
52--diag r c = [(x,y) | x <- [1..8], y <- [1..8], (abs x-y) == 1 ]
53diag r c = let rl = [1..r]
54 rr = [r..8]
55 cu = [1..c]
56 cd = [c..8]
57 in zip rl cu ++ zip rr cd ++
58 zip (reverse rl) cd ++ zip (reverse rr) cu
59
60
61
62
63-- diag (r,c) b =
64-- where l = (r-1,c-1)
65-- r = (r+1,c+1)
66-- lowbound = 1
67-- highbound = 8
68
69
70--initBoard = (8><8) $ repeat O
71
72--firstOpen b = take 1 [(r,c)| r <- [1..8], c <- [1..8], b ! (r,c) == O]
73
74-- firstOpen b = let
75-- elem x y = b ! (x, y)
76-- in map
77
78-- nextOpen b =
79
80-- solve = let board = initBoard
81
82--avail r c b =
83
84--rowOccupied r b = any (== Q) $ getRow r b
85
86
87
88-- diags p = let r = r p
89-- l = l p
90-- in p : inRange r
91-- where inRange x = x >= 1 && x <= 8
92-- inRange' (x,y) = inRange (x) && inRange (y)
93-- r x = (fst x + 1, snd x + 1)
94-- l x = (fst x - 1, snd x - 1)
95-- nexts x = diags' x
96-- diags' x = [(fst x - 1, snd x -1), (fst x + 1, snd x + 1)]
97-- -- down x = (fst x - 1, snd x - 1)
98-- -- down (r,c) = let d = (r-1,c-1) in if inRange d then d : down d else
99-- -- up (r,c) = let u = (r+1,c+1) in u : up u
100
101
102--mapDiag r c = undefined
103
104--placeAll = repeat 8 placeQueen
105
106winnable = undefined
107
108nextOpen board = undefined
109
110-- placeQueen r c =
111
112--b = getE
113
114--placeQueen r c b = b ^.
115
116-- rand = do
117-- g <- newStdGen
118-- print $ take 8 $ (randomRs (0, 8) g)
119
120
121-- try r c = let next b = placeQueen r c b
122-- in next initBoard
123
124-- try' p = let next b = p b
125-- in next initBoard
126
127
128--res = [ try x y | x <- lo8, y <- lo8 ]
129
130main :: IO ()
131main = do
132 putStrLn "Hi"