From cbe440bb0adbfbccfdbbcedb29bf9408c0596866 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 29 May 2019 20:06:05 -0400 Subject: Initial repository; needs clean up but it's working so let's not lose it --- .stack-work/intero/intero7513Owo-STAGING.hs | 152 ++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 .stack-work/intero/intero7513Owo-STAGING.hs (limited to '.stack-work/intero/intero7513Owo-STAGING.hs') diff --git a/.stack-work/intero/intero7513Owo-STAGING.hs b/.stack-work/intero/intero7513Owo-STAGING.hs new file mode 100644 index 0000000..f3b0098 --- /dev/null +++ b/.stack-work/intero/intero7513Owo-STAGING.hs @@ -0,0 +1,152 @@ +module Main where + +import Control.Lens +import Linear.V2 +import Linear.V3 +import Data.Matrix +--import Numeric.LinearAlgebra +import System.Random +import Foreign.Storable + + +data Square = X -- Attacked + | Qu -- Queen + | O -- Open/available + deriving (Show, Eq) + + +--board = V3 <$> [0..8] <*> [0..8] <*> [0] +--board = [(r,c,X) | r <- [0..8], c <- [0..8] ] + +lo8 = [0..8] -- list of 8 +initBoard = matrix 8 8 $ \_ -> O + +placeQueen (r,c) b = placeQueen' $ markAttacked b + where + placeQueen' b = setElem Qu (r,c) b + markAttacked b = rowAttacked $ colAttacked $ diagAttacked b + fX = (\_ x -> X) + rowAttacked b = mapRow fX r b + colAttacked b = mapCol fX c b + diagAttacked b = let d = diag r c + attack ap ab = setElem X ap ab + attackall [x] = attack x b + attackall (x:xs) = attack x (attackall xs) + in attackall d +-- in last $ map (\p -> setElem X p b) d +-- in last $ scanr (\p -> setElem X p) b + +--solve b = placeQueen (nextAvail b) b + +nextAvail b = head [(x,y) | x <- [1..8], y <- [1..8], b ! (x,y) == O] + +-- solve b = placeQueen n +-- where n = nextAvail b +-- next = placeQueen n +-- solve' = + +-- solve b = +-- where solve' b = (\n = placeQueen $ nextAvail b) + +solve b = second + where first = placeQueen (nextAvail b) b + second = placeQueen (nextAvail first) first + +solve' b = s (nA b) b + where s n b = placeQueen n b + nA b = nextAvail b + + +--diag r c = [(x,y) | x <- [1..8], y <- [1..8], (abs x-y) == 1 ] +diag r c = let rl = [1..r] + rr = [r..8] + cu = [1..c] + cd = [c..8] + in zip rl cu ++ zip rr cd ++ + zip (reverse rl) cd ++ zip (reverse rr) cu + +diag' p = where + maxB = 8 + minB = 1 + u = (+1) + d = (-1) + r = u + l = d + ur = (u fst, r snd) + ul = (u fst, l snd) + dr = (d fst, r snd) + dl = (d fst, l snd) + + + + +-- diag (r,c) b = +-- where l = (r-1,c-1) +-- r = (r+1,c+1) +-- lowbound = 1 +-- highbound = 8 + + +--initBoard = (8><8) $ repeat O + +--firstOpen b = take 1 [(r,c)| r <- [1..8], c <- [1..8], b ! (r,c) == O] + +-- firstOpen b = let +-- elem x y = b ! (x, y) +-- in map + +-- nextOpen b = + +-- solve = let board = initBoard + +--avail r c b = + +--rowOccupied r b = any (== Q) $ getRow r b + + + +-- diags p = let r = r p +-- l = l p +-- in p : inRange r +-- where inRange x = x >= 1 && x <= 8 +-- inRange' (x,y) = inRange (x) && inRange (y) +-- r x = (fst x + 1, snd x + 1) +-- l x = (fst x - 1, snd x - 1) +-- nexts x = diags' x +-- diags' x = [(fst x - 1, snd x -1), (fst x + 1, snd x + 1)] +-- -- down x = (fst x - 1, snd x - 1) +-- -- down (r,c) = let d = (r-1,c-1) in if inRange d then d : down d else +-- -- up (r,c) = let u = (r+1,c+1) in u : up u + + +--mapDiag r c = undefined + +--placeAll = repeat 8 placeQueen + +winnable = undefined + +nextOpen board = undefined + +-- placeQueen r c = + +--b = getE + +--placeQueen r c b = b ^. + +-- rand = do +-- g <- newStdGen +-- print $ take 8 $ (randomRs (0, 8) g) + + +-- try r c = let next b = placeQueen r c b +-- in next initBoard + +-- try' p = let next b = p b +-- in next initBoard + + +--res = [ try x y | x <- lo8, y <- lo8 ] + +main :: IO () +main = do + putStrLn "Hi" -- cgit v1.2.3