New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

game_board

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

game_board

  • 0.0.2
  • Rubygems
  • Socket score

Version published
Maintainers
2
Created
Source

GameBoard

Authors: MrPowers, sandbochs

This class helps calculate the rows, columns, diagonals, and diagonals of a coordinate for nested array data structures. It is useful for games like Tic-Tac-Toe, Connect Four, Battleship, etc.

Getting Started

You can add GameBoard to your Gemfile with:

gem 'game_board'

Run the bundle command afterwards to install the gem.

Usage

Create a new 4x3 game board:

board = GameBoard.new(4,3)

Populate the game board with numbers:

cells = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
board.set_grid(cells)

Get or set a value at a coordinate (row_index, column_index):

board.get_cell(0,0) => 1
board.set_cell(0,0, 'X')
board.get_cell(0,0) => X 

Get the two diagonals at a coordinate:

board.coordinate_diagonals(2, 2) => [[1, 5, 9], [9, 11]]

Get all diagonals in the grid:

board.diagonals

Get a row or column:

board.row(1) => [4, 5, 6]
board.column(2) => [3, 6, 9, 12]

Get all rows or columns:

board.rows
board.columns

Print the board to console:

# Returns a string: "[1, 2, 3]\n[4, 5, 6]\n[7, 8, 9]\n[10, 11, 12]"
puts board.to_s

FAQs

Package last updated on 04 Dec 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc