MarkovLast3Me&HimBothWays2

This program has been disqualified.


AuthorSmetalo
Submission date2012-07-28 13:51:41.996529
Rating7167
Matches played42
Win rate76.19

Source code:

import random
	
if input == "":	
	opp_moves=[]
	my_moves=[]	
	
	follows={}
	
	choices=['P', 'S', 'R']
	winner={'R': 'P', 'P': 'S', 'S': 'R'} 

	output=random.choice(choices)		
else:
	opp_moves.append(input)
	my_moves.append(output)	
    
	if len(opp_moves)<4:
	        output=random.choice(choices)   
	else:	
		lastMoves=opp_moves[len(opp_moves)/2:]      
		
		found=False      

		for i in range(1,len(lastMoves)*3/5):             
			found=True
			
			for j in range(len(lastMoves)-i):
				if lastMoves[j]!=lastMoves[j+i]: 
					found=False
					break
					
			if found==True:
				output=winner[lastMoves[len(lastMoves)-i]]
				break
				
		if found==False:			
			i=len(opp_moves)-4

			x=opp_moves[i]  
			y=opp_moves[i+1] 
			z=opp_moves[i+2]
			w=opp_moves[i+3]
			
			a=my_moves[i]
			b=my_moves[i+1]
			c=my_moves[i+2]
			d=my_moves[i+3]			
			
			t=(x,a,y,b,z,c)
			
			if t not in follows:
				follows[t]={}  
				follows[t][0]={} 
				follows[t][1]={}
			
			if d not in follows[t][0]:                 
				follows[t][0][d]=1
			else:
				follows[t][0][d]+=1                
        
			if w not in follows[t][1]:
				follows[t][1][w]=1
			else:
				follows[t][1][w]+=1     		
			
			his_last=opp_moves[-1]
			one_before_his_last=opp_moves[-2]
			two_before_his_last=opp_moves[-3]

			my_last=my_moves[-1]
			one_before_my_last=my_moves[-2]
			two_before_my_last=my_moves[-3]

			the_end=(two_before_his_last,two_before_my_last,one_before_his_last,one_before_my_last, his_last, my_last)
			
			if the_end in follows:
				maxim=0
				solution=-1
				
				stats=follows[the_end][0]
					
				for i in stats:
					current=stats[i]
					
					if current>maxim:
						maxim=current
						solution=i
						
				his_guess=solution		 
				
			
				maxim=0
				solution=-1
				
				stats=follows[the_end][1]				
					
				for i in stats:
					current=stats[i]
					
					if current>maxim:
						maxim=current
						solution=i
						
				my_guess=winner[solution]

				if his_guess==my_guess:				
					random.shuffle(choices)
									
					for x in choices:
						if x!=my_guess:
							output=x
							break
				else:
					output=my_guess
			else:
				output=random.choice(choices)