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
class Board: def __init__(self): self.pieces = [[None for i in range(8)] for j in range(8)] def...
class Board: def __init__(self): self.pieces = [[None for i in range(8)] for j in range(8)] def __str__(self): s = "" for j in range(7, -1, -1): #for each row for i in range(8): # for each column if self.pieces[j][i] is None: # if self.pieces[j][i] is None s += "." # populate the row with '.' val for each column else: s += self.pieces [j][i].get_symbol() s += "\n" #after each row add a new line return s # return after iterating...
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.
def sum_gt_avg(num_list): Implement a function that returns the sum of the numbers in num_list that have...
def sum_gt_avg(num_list): Implement a function that returns the sum of the numbers in num_list that have a value greater than the average value in the list. • Parameters: num_list is a list of numbers (mixed integers and floats) • Examples: sum_gt_avg([1,2,3,4,5]) → 9 # 4+5 sum_gt_avg([1,2,3,-4,5]) → 10 # 2+3+5 sum_gt_avg([-1,-2,-3,-4,-5]) → -3 # -1-2 in python
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT