Determining Tile Contents

Hey, and thanks for reading in advance.

I randomly got a spurious burst of lopsided inspiration to try and literally make Battleship the board game on Roblox. So far, I’ve created a functioning tile selector and the grid/grid markers adjust automatically to fit a given area.


It kind of sucks that Player 2 is forced to read the markers from the opposite direction, but I can think of something to alleviate that later. What I’m wondering how I’ll accomplish now is exactly how to determine how to store information on each tile - is there a ship in that tile? For which player? Does that tile contain a destroyed section of a ship? Is every single tile of the ship destroyed?

I already have a module for obtaining tile neighbors and tiles reachable in X number of steps (I can post this if necessary) but does anyone have any feedback on the simplest mechanisms I could employ to store tile information? Would a dictionary with vectors as keys do the trick?

For clarification, I plan on having the entire grid flip (visually) when turns alternate, switching between your board (shows tiles you’ve fired on and where successful hits were declared) and the opponent’s board (shows your ships and where the opponent has declared successful hits).

Do you have a module which stores the information of the tiles at the moment? Trying to understand if you are unsure how to access said module’s information or if you are asking how to best create a module to store said information.

Have an array of arrays (multi-dimensional array) represent the grid’s contents.

Here’s an example chess board.

local ChessBoard = {
	{"WhiteCastle", "WhiteKnight", "WhiteBishop", "WhiteKing", "WhiteQueen", "WhiteBishop", "WhiteKnight", "WhiteCastle"},
	table.create(8, "WhitePawn"),
	table.create(8, ""),
	table.create(8, ""),
	table.create(8, ""),
	table.create(8, ""),
	table.create(8, "BlackPawn"),
	{"BlackCastle", "BlackKnight", "BlackBishop", "BlackKing", "BlackQueen", "BlackBishop", "BlackKnight", "BlackCastle"}

for _, Row in ipairs(ChessBoard) do
	print(table.concat(Row, " "))