In: Computer Science
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
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.