Markov

This program has been disqualified.


AuthorCabu
Submission date2012-07-31 12:56:55.190885
Rating5958
Matches played10
Win rate70.0

Source code:

import random

beat_dict = {'R': 'P', 'P': 'S', 'S': 'R'}

if input == '':
    opp_history = ''
    x = -1
else:
    opp_history += input

    length = min (len (opp_history) - 1, 100)
    while length > 0:
        # Search for the last longest chain
        x = opp_history[:-1].rfind (opp_history[-length:])
        if x >= 0:
            # If found: Pick what will be the next move and play against it
            output = beat_dict[opp_history[x + length]]
            break
        length -= 1

if x == -1:        
    output = random.choice (('R', 'P', 'S'))