- #1
gpax42
- 25
- 0
Not sure if anyone here is familiar with MATLAB programming. I am supposed to create a structured array (resembling a game board) that acts as a predator/prey simulator. The user needs to specify the size of the game board. Within the gameboard I am supposed to represent a couple of different animals. Zebras, represented with a 'Z' should occupy 10% of the gameboard, giraffes represented with a 'G' occupy another 10%, hyenas represented with an 'H' occupy 5%, and there will be 1 lion represented with an 'L'. Unoccupied spaces will be represented with a hyphen.
this is what I've come up with so far. I tried making the board filled with hyphens, and then replacing them by specifying different animals for random locations within the board. There might be an easier way to do this using vectorization and not for loops. I am also confused about how I should make each animal occupy random locations that amount to a certain percent of the gameboard. How can I do this randomly without having the same locations within the array specified twice? Once agian, vectorization might offer an easier means to doing this, I am just not sure how.
Any help you can offer will be greatly appreciated!
function board = makeBoard(rows,cols)
for rowIndex = 1:rows
for colIndex = 1:cols
board(rowIndex,colIndex).type = '-';
end
end
%creates a structured array with hyphens at each location
this is what I've come up with so far. I tried making the board filled with hyphens, and then replacing them by specifying different animals for random locations within the board. There might be an easier way to do this using vectorization and not for loops. I am also confused about how I should make each animal occupy random locations that amount to a certain percent of the gameboard. How can I do this randomly without having the same locations within the array specified twice? Once agian, vectorization might offer an easier means to doing this, I am just not sure how.
Any help you can offer will be greatly appreciated!
function board = makeBoard(rows,cols)
for rowIndex = 1:rows
for colIndex = 1:cols
board(rowIndex,colIndex).type = '-';
end
end
%creates a structured array with hyphens at each location