Book Image

Haskell Data Analysis Cookbook

By : Nishant Shukla
Book Image

Haskell Data Analysis Cookbook

By: Nishant Shukla

Overview of this book

Table of Contents (19 chapters)
Haskell Data Analysis Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Working with hexagonal and square grid networks


Sometimes, the graph we're dealing with has a strict structure, such as a hexagonal or square grid. Many video games use a hexagonal grid layout to facilitate diagonal movement because moving diagonally in a square grid complicates the values of the traveled distance. On the other hand, square grid structures are often used within graphs to traverse pixels for image manipulation algorithms such as flood fill.

There is a very useful library in the Haskell package listing to deal with such topologies. We can obtain the indices of a grid to traverse the world, which is essentially a path embedded in a graph. For each grid index, we can query the library to find the neighboring indices, effectively using grids as a graph.

Getting started

Review the package documentation located at https://github.com/mhwombat/grid/wiki.

Install the grid package using cabal:

$ cabal install grid

How to do it...

In a new file, which we will name Main.hs, insert the following...