<commit_before>{-# LANGUAGE RecordWildCards #-}

module ZTile where

import Data.List

-- Coord is (X, Y); this can represent both square and hex tiles; for hex tiles,
-- the third axis, Z, can be calculated on the fly using the X and Y values.
type Coord = (Int, Int)

data Direction
	= DXPlus
	| DXMinus
	| DYPlus
	| DYMinus
	deriving (Eq, Show)

class ZTile a where
	indices :: a -> [Coord]
	adjacent :: a -> Coord -> [Coord] -- adjacent edge-to-edge adjacent
	-- edge/point-to-edge/point; for square tiles, this routine check for the
	-- diagonal directions
	adjacent' :: a -> Coord -> [Coord]
	distance :: a -> Coord -> Coord -> Int
	contains :: a -> Coord -> Bool
	size :: a -> (Int, Int)

data Plane
	= FlatSq
	-- Hex tiles where perfect East/West movement is possible, but not for
	-- North/South.
	| FlatHex
	deriving (Eq, Show)

data PlaneGeom = PlaneGeom
	{ pgPlane :: Plane
	, pgSizeX :: Int
	, pgSizeY :: Int
	, pgTiles :: [Coord]
	} deriving (Eq)

instance Show PlaneGeom where
	show PlaneGeom{..}
		= "PlaneGeom { pgPlane = " ++ show pgPlane ++ ",\n"
		++ "pgSizeX = " ++ show pgSizeX ++ ",\n"
		++ "pgSizeY = " ++ show pgSizeY ++ ",\n"
		++ "pgTiles =\n" ++ showPlaneGeom ++ "\n}"
		where
		showPlaneGeom = intercalate "\n" . map showPGRow $ reverse [0..(pgSizeY - 1)]
		showPGRow yIdx = indent ++ (intersperse ' ' $ map (\_ -> 'x') [0..(pgSizeX - 1)])
			where
			indent = if odd yIdx
				then " "
				else ""

instance ZTile PlaneGeom where
	indices = pgTiles
	adjacent PlaneGeom{..} idx = filter (flip elem pgTiles) $ case pgPlane of
		FlatSq -> map (go idx)
			[ DXPlus
			, DXMinus
			, DYPlus
			, DYMinus
			]
		FlatHex -> map (go' idx)
			[ [DXPlus]
			, [DXMinus]
			, [DYPlus]
			, [DYMinus]
			, [DYPlus, DXMinus]
			, [DYMinus, DXPlus]
			]
	adjacent' pg@PlaneGeom{..} idx = case pgPlane of
		FlatSq -> filter (flip elem pgTiles) $ map (go' idx)
			[ [DXPlus]
			, [DXMinus]
			, [DYPlus]
			, [DYMinus]
			, [DXPlus, DYPlus]
			, [DXMinus, DYMinus]
			, [DYPlus, DXMinus]
			, [DYMinus, DXPlus]
			]
		FlatHex -> adjacent pg idx
	-- Distance between two squares along the grid, assuming no obstacles.
	distance PlaneGeom{..} (x1, y1) (x2, y2) = case pgPlane of
		FlatSq -> max (abs $ x2 - x1) (abs $ y2 - y1)
		FlatHex -> maximum
			[ abs $ x2 - x1
			, abs $ y2 - y1
			, abs $ z2 - z1
			]<commit_msg>fix comment<commit_after>{-# LANGUAGE RecordWildCards #-}

module ZTile where

import Data.List

-- Coord is (X, Y); this can represent both square and hex tiles; for hex tiles,
-- the third axis, Z, can be calculated on the fly using the X and Y values.
type Coord = (Int, Int)

data Direction
	= DXPlus
	| DXMinus
	| DYPlus
	| DYMinus
	deriving (Eq, Show)

class ZTile a where
	indices :: a -> [Coord]
	adjacent :: a -> Coord -> [Coord] -- adjacent edge-to-edge adjacent
	-- edge/point-to-edge/point; for square tiles, this routine check for the
	-- diagonal directions
	adjacent' :: a -> Coord -> [Coord]
	distance :: a -> Coord -> Coord -> Int
	contains :: a -> Coord -> Bool
	size :: a -> (Int, Int)

data Plane
	= FlatSq
	-- Hex tiles where perfect East/West movement is possible, but not for
	-- North/South.
	| FlatHex
	deriving (Eq, Show)

data PlaneGeom = PlaneGeom
	{ pgPlane :: Plane
	, pgSizeX :: Int
	, pgSizeY :: Int
	, pgTiles :: [Coord]
	} deriving (Eq)

instance Show PlaneGeom where
	show PlaneGeom{..}
		= "PlaneGeom { pgPlane = " ++ show pgPlane ++ ",\n"
		++ "pgSizeX = " ++ show pgSizeX ++ ",\n"
		++ "pgSizeY = " ++ show pgSizeY ++ ",\n"
		++ "pgTiles =\n" ++ showPlaneGeom ++ "\n}"
		where
		showPlaneGeom = intercalate "\n" . map showPGRow $ reverse [0..(pgSizeY - 1)]
		showPGRow yIdx = indent ++ (intersperse ' ' $ map (\_ -> 'x') [0..(pgSizeX - 1)])
			where
			indent = if odd yIdx
				then " "
				else ""

instance ZTile PlaneGeom where
	indices = pgTiles
	adjacent PlaneGeom{..} idx = filter (flip elem pgTiles) $ case pgPlane of
		FlatSq -> map (go idx)
			[ DXPlus
			, DXMinus
			, DYPlus
			, DYMinus
			]
		FlatHex -> map (go' idx)
			[ [DXPlus]
			, [DXMinus]
			, [DYPlus]
			, [DYMinus]
			, [DYPlus, DXMinus]
			, [DYMinus, DXPlus]
			]
	adjacent' pg@PlaneGeom{..} idx = case pgPlane of
		FlatSq -> filter (flip elem pgTiles) $ map (go' idx)
			[ [DXPlus]
			, [DXMinus]
			, [DYPlus]
			, [DYMinus]
			, [DXPlus, DYPlus]
			, [DXMinus, DYMinus]
			, [DYPlus, DXMinus]
			, [DYMinus, DXPlus]
			]
		FlatHex -> adjacent pg idx
	-- Distance between two squares (or hexes) along the grid, assuming no obstacles.
	distance PlaneGeom{..} (x1, y1) (x2, y2) = case pgPlane of
		FlatSq -> max (abs $ x2 - x1) (abs $ y2 - y1)
		FlatHex -> maximum
			[ abs $ x2 - x1
			, abs $ y2 - y1
			, abs $ z2 - z1
			]
{'fraction_non_alphanumeric': 0.1489407233040873, 'fraction_numerical': 0.007703830515728654, 'mean_word_length': 2.7036450079239303, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5150291', 'n_tokens_mistral': 2054, 'n_tokens_neox': 1839, 'n_words': 557}