#NEWLINE# def strategy( self , opponent ) : #NEWLINE# #INDENT# '\n        Begins by playing C, then plays D for mem_length rounds if the opponent\n        ever plays D twice in a row\n        ' #NEWLINE# if ( self . grudge_memory >= self . mem_length ) : #NEWLINE# #INDENT# self . grudge_memory = 0 #NEWLINE# self . grudged = False #NEWLINE# #UNINDENT# if ( len ( opponent . history ) < 2 ) : #NEWLINE# #INDENT# return C #NEWLINE# #UNINDENT# if self . grudged : #NEWLINE# #INDENT# self . grudge_memory += 1 #NEWLINE# return D #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not ( C in opponent . history [ ( - 2 ) : ] ) ) : #NEWLINE# #INDENT# self . grudged = True #NEWLINE# return D #NEWLINE# #UNINDENT# #UNINDENT# return C