module Game.TicTacToe3D.Vector3 where
import Data.List (unfoldr)
import Data.Vector (Vector)
import qualified Data.Vector as V
type Dim3 a b = a (a (a b))
type V3 a = Dim3 Vector a
type I3 = (Int, Int, Int)
base :: Int -> Int -> [Int]
base i n = unfoldr f n ++ repeat 0 where
f b = if b /= 0 then Just (pair b i) else Nothing where
pair n i = (n `mod` i, n `div` i)
i3 :: Int -> I3
i3 i = t $ base 3 i where t (x:y:z:_) = (x, y, z)
(!) :: V3 a -> I3 -> a
v ! (x, y, z) = v V.! x V.! y V.! z
(//) ::V3 a -> (I3, a) -> V3 a
v // ((x, y, z), n) = (setf x $ setf y $ setv z n) v where
setf i f y = setv i (f $ y V.! i) y
setv i m y = y V.// [(i, m)]
init :: Int -> (I3 -> a) -> V3 a
init i f =
V.generate i $ \x ->
V.generate i $ \y ->
V.generate i $ \z ->
f (x, y, z)