diff options
Diffstat (limited to '.stack-work/intero/intero7513Owo-STAGING.hs')
-rw-r--r-- | .stack-work/intero/intero7513Owo-STAGING.hs | 152 |
1 files changed, 0 insertions, 152 deletions
diff --git a/.stack-work/intero/intero7513Owo-STAGING.hs b/.stack-work/intero/intero7513Owo-STAGING.hs deleted file mode 100644 index f3b0098..0000000 --- a/.stack-work/intero/intero7513Owo-STAGING.hs +++ /dev/null | |||
@@ -1,152 +0,0 @@ | |||
1 | module Main where | ||
2 | |||
3 | import Control.Lens | ||
4 | import Linear.V2 | ||
5 | import Linear.V3 | ||
6 | import Data.Matrix | ||
7 | --import Numeric.LinearAlgebra | ||
8 | import System.Random | ||
9 | import Foreign.Storable | ||
10 | |||
11 | |||
12 | data 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 | |||
21 | lo8 = [0..8] -- list of 8 | ||
22 | initBoard = matrix 8 8 $ \_ -> O | ||
23 | |||
24 | placeQueen (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 | |||
41 | nextAvail 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 | |||
48 | -- solve b = | ||
49 | -- where solve' b = (\n = placeQueen $ nextAvail b) | ||
50 | |||
51 | solve b = second | ||
52 | where first = placeQueen (nextAvail b) b | ||
53 | second = placeQueen (nextAvail first) first | ||
54 | |||
55 | solve' b = s (nA b) b | ||
56 | where s n b = placeQueen n b | ||
57 | nA b = nextAvail b | ||
58 | |||
59 | |||
60 | --diag r c = [(x,y) | x <- [1..8], y <- [1..8], (abs x-y) == 1 ] | ||
61 | diag r c = let rl = [1..r] | ||
62 | rr = [r..8] | ||
63 | cu = [1..c] | ||
64 | cd = [c..8] | ||
65 | in zip rl cu ++ zip rr cd ++ | ||
66 | zip (reverse rl) cd ++ zip (reverse rr) cu | ||
67 | |||
68 | diag' p = where | ||
69 | maxB = 8 | ||
70 | minB = 1 | ||
71 | u = (+1) | ||
72 | d = (-1) | ||
73 | r = u | ||
74 | l = d | ||
75 | ur = (u fst, r snd) | ||
76 | ul = (u fst, l snd) | ||
77 | dr = (d fst, r snd) | ||
78 | dl = (d fst, l snd) | ||
79 | |||
80 | |||
81 | |||
82 | |||
83 | -- diag (r,c) b = | ||
84 | -- where l = (r-1,c-1) | ||
85 | -- r = (r+1,c+1) | ||
86 | -- lowbound = 1 | ||
87 | -- highbound = 8 | ||
88 | |||
89 | |||
90 | --initBoard = (8><8) $ repeat O | ||
91 | |||
92 | --firstOpen b = take 1 [(r,c)| r <- [1..8], c <- [1..8], b ! (r,c) == O] | ||
93 | |||
94 | -- firstOpen b = let | ||
95 | -- elem x y = b ! (x, y) | ||
96 | -- in map | ||
97 | |||
98 | -- nextOpen b = | ||
99 | |||
100 | -- solve = let board = initBoard | ||
101 | |||
102 | --avail r c b = | ||
103 | |||
104 | --rowOccupied r b = any (== Q) $ getRow r b | ||
105 | |||
106 | |||
107 | |||
108 | -- diags p = let r = r p | ||
109 | -- l = l p | ||
110 | -- in p : inRange r | ||
111 | -- where inRange x = x >= 1 && x <= 8 | ||
112 | -- inRange' (x,y) = inRange (x) && inRange (y) | ||
113 | -- r x = (fst x + 1, snd x + 1) | ||
114 | -- l x = (fst x - 1, snd x - 1) | ||
115 | -- nexts x = diags' x | ||
116 | -- diags' x = [(fst x - 1, snd x -1), (fst x + 1, snd x + 1)] | ||
117 | -- -- down x = (fst x - 1, snd x - 1) | ||
118 | -- -- down (r,c) = let d = (r-1,c-1) in if inRange d then d : down d else | ||
119 | -- -- up (r,c) = let u = (r+1,c+1) in u : up u | ||
120 | |||
121 | |||
122 | --mapDiag r c = undefined | ||
123 | |||
124 | --placeAll = repeat 8 placeQueen | ||
125 | |||
126 | winnable = undefined | ||
127 | |||
128 | nextOpen board = undefined | ||
129 | |||
130 | -- placeQueen r c = | ||
131 | |||
132 | --b = getE | ||
133 | |||
134 | --placeQueen r c b = b ^. | ||
135 | |||
136 | -- rand = do | ||
137 | -- g <- newStdGen | ||
138 | -- print $ take 8 $ (randomRs (0, 8) g) | ||
139 | |||
140 | |||
141 | -- try r c = let next b = placeQueen r c b | ||
142 | -- in next initBoard | ||
143 | |||
144 | -- try' p = let next b = p b | ||
145 | -- in next initBoard | ||
146 | |||
147 | |||
148 | --res = [ try x y | x <- lo8, y <- lo8 ] | ||
149 | |||
150 | main :: IO () | ||
151 | main = do | ||
152 | putStrLn "Hi" | ||