212k views
3 votes
Write a function that creates a one-dimensional game board composed of agents of two different types (0 and 1, X and O, stars and pluses... whatever you want where the agents are assigned to spots randomly with a 50% chance of being either type. Define the function so that it takes as inputs 1. The number of spots in the game board. Make it so that the default is set to 32. 2. A random seed that you will use to initialize the board (this will make it possible to test the reproducibility of your model). Also set a default seed value. Make sure your function returns your game board (Something to think about: which makes more sense to describe the game board, a list or a Numpy array? What are the tradeoffs?) Show that your function is behaving correctly by printing out the returned game board (Hint: There is more than one way to write this code· If you're having trouble coming up with your own method, you could consider trying to use np.random.choice(), but you'll have to read the documentation to figure out how to get the output you want.)

User Lakeia
by
4.6k points

1 Answer

5 votes

Answer:

Python code explained below

Step-by-step explanation:

import random #importing random library

def initialize_board(noOfSpot=32,seedIn=9):

#function with default spots set as 32

#default seed set as 9

random.seed(seedIn)

gameBoard = [] #initialising gameBoard list with empty values

for i in range(noOfSpot):

gameBoard.append(random.randint(0,1))

#adding values to gameBoard

return gameBoard

board =initialize_board(10,2)

print(board)

User Sanjay Kumar
by
4.2k points