0.0
Low commit activity in last 3 years
No release in over a year
Classes that help interpret and operation on the state of a grid of squares with pieces on them.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.1.4
~> 5.14.0
~> 13.0.1
 Project Readme

BoardGameGrid

Data structure and logic for a board game grid. Provides classes that help interpret and operation on the state of a grid of squares with pieces on them.

Installation

Add this line to your application's Gemfile:

gem 'board_game_grid'

And then execute:

$ bundle

Or install it yourself as:

$ gem install board_game_grid

Usage

The primary class is the square set, which can be initialised from an array of hashes:

  square_set = BoardGameGrid::SquareSet.new(squares: [
    {id: 1, x: 2, y: 3, piece: nil},
    {id: 2, x: 4, y: 6, piece: {player_number: 1} }
  ])

or an array of squares:

  square_set = BoardGameGrid::SquareSet.new(squares: [
    BoardGameGrid::Square.new({id: 1, x: 2, y: 3, piece: nil}),
    BoardGameGrid::Square.new({id: 2, x: 4, y: 6, piece: {player_number: 1}) }
  ])

A square set has some enumerable functionality and common enumerable methods can be called on it (e.g. map, all?, include?, size, +, -)

Most methods that would return an array of squares will return a square set object.

Querying methods such as orthogonal and diagonal, which returns a square set containing squares orthogonal or diagonal to an origin square are available.

Other querying methods include the where method which takes a hash of attribute/values to filter down the set.

  square_set.where(x: 1, y: 2, piece: {player_number: 1})

More details are available in the documentation on rubydoc.info

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/mrlhumphreys/board_game_grid. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the BoardGameGrid project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.