human
Optimal Strategy for a Game | Set 3 | Calculates the maximum score possible for P1 If only the bags from beg to ed were available.
Length of the game.
Which turn is being played.
Base case i . e last turn.
if it is P1 's turn.
if P2 's turn.
Player picks money from the left end.
Player picks money from the right end.
If it is player 1 's turn then  current picked score added to  his total. choose maximum of  the two scores as P1 tries to  maximize his score..
If player 2 ' s ▁ turn ▁ don ' t add current picked bag score to total . choose minimum of the two scores as P2 tries to minimize P1 's score..
Input array.
Function Calling"
How can the above be solved in Python?
assistant
#Here is code to optimal Strategy for a Game and the other steps required.
 def maxScore ( money , beg , ed ) :
	totalTurns = len ( money )
	turnsTillNow = beg + ( ( totalTurns - 1 ) - ed )
	if ( beg == ed ) :
		if ( turnsTillNow % 2 == 0 ) :
			return [ money [ beg ] , " L " ]
		else :
			return [ 0 , " L " ]
	scoreOne = maxScore ( money , beg + 1 , ed )
	scoreTwo = maxScore ( money , beg , ed - 1 )
	if ( turnsTillNow % 2 == 0 ) :
		if ( money [ beg ] + scoreOne [ 0 ] > money [ ed ] + scoreTwo [ 0 ] ) :
			return [ money [ beg ] + scoreOne [ 0 ] , " L " + scoreOne [ 1 ] ]
		else :
			return [ money [ ed ] + scoreTwo [ 0 ] , " R " + scoreTwo [ 1 ] ]
	else :
		if ( scoreOne [ 0 ] < scoreTwo [ 0 ] ) :
			return [ scoreOne [ 0 ] , " L " + scoreOne [ 1 ] ]
		else :
			return [ scoreTwo [ 0 ] , " R " + scoreTwo [ 1 ] ]
ar = [ 10 , 80 , 90 , 30 ]
arraySize = len ( ar )
bags = ar
ans = maxScore ( bags , 0 , arraySize - 1 )
print ( ans [ 0 ] , ans [ 1 ] )