Question

In: Computer Science

How do I assign the resulting numbers from row and column in this function: def PlacePlayer(board,player):...

How do I assign the resulting numbers from row and column in this function:

def PlacePlayer(board,player):
    row = DieRoller(1,6)
    col = DieRoller(1,6)
    board[row][col] = 'player'
    return board,player

To the player['row'] and player['col'] in this function in place of the 0s:

def GenPlayer(level):
  player = {}
  player['name'] = GenName()
  player['history'] = GenHistory() #history
  player['attack'] = DieRoller(3,6) + DieRoller(level,4)
  player['defense'] = DieRoller(3,6) + DieRoller(level,4)
  player['health'] = DieRoller(5,6) + DieRoller(level,4)
  player['row'] = 0
  player['col'] = 0

Solutions

Expert Solution

In the below function, you are returning 2 values. One is board and the second is player

def PlacePlayer(board,player):
    row = DieRoller(1,6)
    col = DieRoller(1,6)
    board[row][col] = 'player'
    return board,player

So i suggest you use enumerate and for loops to get the row and col from this method.

Placeplayer(board,player)[0] will give you board and Placeplayer(board,player)[1] will give you player

so basically check for the player in the board to get row and col. Follow the below code.

for x,y in enumerate(board): #here replace board with Placeplayer(board,player)[0]
    for p,q in enumerate(y):
        if q=='player':  #here replace player with Placeplayer(board,player)[1]
            player[row]=x  #here x is the row value
            player[col]=p  #here p is the col value
            break

#Please don't forget to upvote if you find the solution helpful. Feel free to ask doubts if any, in the comments section. Thank you.


Related Solutions

How do you split a pandas column with floating numbers on a symbol. For example: COLUMN...
How do you split a pandas column with floating numbers on a symbol. For example: COLUMN = Location ROW = 44.567892, -83.783937 Split the numbers into two separate columns based off of the comma. Meaning 44.567892 would be in its own column and -83.783937 would be in its own column. In python
I have a sequence of natural numbers. How can I get the height of the resulting...
I have a sequence of natural numbers. How can I get the height of the resulting tree/ c++(send code)
for input matrix a , write a function to return the element in row 2 column...
for input matrix a , write a function to return the element in row 2 column 3 of that matrix
How are the column space and the row space of a matrix A related to the...
How are the column space and the row space of a matrix A related to the column space and row space of its reduced row echelon form? How does this prove the column rank of A equals the row rank?
How do I select every row in pandas dataframe?
How do I select every row in pandas dataframe?
Write a function called ReturnOddEntries.m that accepts as input a column or row array (vector) and...
Write a function called ReturnOddEntries.m that accepts as input a column or row array (vector) and returns only the odd index entries. Do this by first setting the even entries to 0, and then removing the 0 entries by using a logical array. The first line of your code should read function p = ReturnOddEntries(p) For example, if you run in the command window p = ReturnOddEntries([1.2 7.1 8.4 -42 100.1 7 -2 4 6]), then you should get p...
Write a function script DirCos.m that takes a vector (any row or column array) as the...
Write a function script DirCos.m that takes a vector (any row or column array) as the argument and returns the direction cosines for that vector. This is for a MatLab script
write a function that return a list of row numbers in matrix with removing the wrong...
write a function that return a list of row numbers in matrix with removing the wrong value. Ex: remove_row( matrix, wro) if matrix = [[5,2,8],[6,7,20],[10,25,9]] wro= 20 then output will be [1,2] Do not use any built in functions.
Find the probability to randomly assign numbers from 1 to ? to ? people such that...
Find the probability to randomly assign numbers from 1 to ? to ? people such that exactly two people get the same number (2<?≤?)? Guidance: Start with numbering the people that have the same number and then number the rest.
How to find optimal row and optimal column in a nonstrictly determined game explain with at...
How to find optimal row and optimal column in a nonstrictly determined game explain with at least 2 examples (one must be at least 3x3 matrix) and how to find the value (in a determined game, I remember, the value is the saddle value). will rate positive if u make the cut.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT