Exemple #1
0
       # cDDCDspite,
       # dCDCDspite,
       # dDDCDspite,
       # cCDDCspite,
       # cDDDCspite,
       # dCDDCspite,
       # dDDDCspite,
       # cCDDDspite,
       # cDDDDspite,
       # dCDDDspite, # winning - 24
       # dDDDDspite  # winning - 25
       ]



games = Games(None, None, None, None)
# one generation
def getPayoffMatrix(lst, gameHere):
    payoffs = [[0.0 for j in range(len(lst))] for i in range(len(lst))]
    for i in range(len(lst)):
        for j in range(len(lst)):
            a1 = lst[i](gameHere)
            b1 = lst[j](gameHere)
            [scA, scB] = IteratedPD(a1, b1, gameHere)
            payoffs[i][j] = scA/gameHere.Iter_N
            # payoffs[j][i] = scB/gameHere.Iter_N
    return payoffs


# Create new directory to save the figures
now = datetime.datetime.now()
Exemple #2
0
    BoydSocialTitForTat,
    BoydTitForTat,
    # RLABitRandom,
    # RLAEGS,
    # RLAlwaysCooperate,
    # RLAlwaysDefects,
    # RLAlwaysRandom,
    # RLRandomTitForTat,
    # RLTitForTat,
    twoStageRLbased
]

results = {}
mresults = {}
sresults = {}
games = Games()


# tournament 1 - mvspt
def TournaMent(lst, gameHere):
    score = {}  # for overall score
    mscore = {}  # for material score
    sscore = {}  # for social score
    for i in range(len(lst)):
        if lst[i] not in score:
            score[lst[i]] = 0
        if lst[i] not in mscore:
            mscore[lst[i]] = 0
        if lst[i] not in sscore:
            sscore[lst[i]] = 0
        # score.append(float(0))
            # score[lst[j]] += scB
    sortedDic = sorted(score.items(), key=lambda score: score[1], reverse=True)
    print sortedDic, 'dic'
    for ele in score:
        if ele not in OverallScore:
            OverallScore[ele] = 0.0
        OverallScore[ele] += score[ele]
    winning = sortedDic[0][0]
    if winning not in results.keys():
        results[winning] =0
    results[winning] += 1


NN = 0
# games(learning rate, discount factor, game length, memory length for the RL agent)
games = Games(None, None, None, None) # game setting choice for parameter investigation
# 50 trials
while(NN < 50):
    # OverallScore = []
    RoundrobinTour(lst, games)
    NN += 1
    print NN
    print results # shows the winning strategy

for eleme in OverallScore:
    OverallScore[eleme] = OverallScore[eleme]/50.0

# print OverallScore
# sortedos = sorted(OverallScore.items(), key=lambda OverallScore: OverallScore[1], reverse=True)
# print sortedos