I am trying to create a 2d array in Go:
board := make([][]string, m)
for i := range board {
board[i] = make([]string, n)
}
However, given the verbosity of that, I am wondering if there is a better or more succinct way to handle this problem (either to generate dynamic arrays, or a different/idiomatic data-structure to handle such board-game like data)?
Background:
- this is for a board game
- the dimensions of the board are not known until a user starts playing (so, say, MxN).
- I want to store an arbitrary character (or a single char string) in each cell. In my TicTacToe game that will be the 'X' or an 'O' (or any other character the user chooses).
makeindeed creates slices. Would you mind expanding on your suggestion (perhaps as an answer) by showing how append can be used in this case.runes instead ofstrings if you will only store 1 character.