forked from ehauckdo/AIWoof
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtextMetrics.py
152 lines (96 loc) · 4.35 KB
/
textMetrics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from toolbox import *
import math
# These functions are here to create behavioural metrics based on the way other agents talk.
# Are they hostile towards us ? Do they seem to be capable of complex thoughts ?
# An enemy that is both hostile and complex is dangerous !
def updateTextMetrics(tracker):
#Evaluate behavioural metrics based on the way agent talk
for id in tracker.profiles:
profile = tracker.profiles[id]
wolves = tracker.getTeamId('WEREWOLF')
humans = tracker.getTeamId('HUMAN')
everybody = tracker.getAllId()
hostilityPatterns = generateHostilityPatterns(tracker, profile, wolves, humans, everybody, tracker.profiles[tracker.myId])
profile["hostility"] = calculateHostility(tracker, profile, hostilityPatterns)
profile["complexity"] = calculateComplexity(profile)
def calculateHostility(tracker, profile, patterns):
#Evaluates an hostility metric towards our agent
#... by recognizing hostile or protectives patterns
if profile['isMe'] :
return 0
else:
hostility = 0
talks = profile['talkHistory']
for talk in talks:
for pattern in patterns:
text = talk['text']
day = int(talk['day'])
occurences = text.count(pattern)
weight = patterns[pattern]
hostility += occurences*weight*day
hostility = 20/(1+math.exp(-hostility/200))
return hostility
def calculateComplexity(profile):
#Evaluates the complexity of an agent...
#... by counting the number of brackets used :D
texts = getAllTexts(profile)
maxComplexity = 0
for text in texts:
score = text.count("(")
maxComplexity = max(score, maxComplexity)
complexity = maxComplexity+1
return complexity
def generateHostilityPatterns(tracker, profile, wolves, humans, everybody, me):
#Generate patterns we identify as being hostile or cooperative
#If a player says something that matches a pattern, we add to their hostility metric the corresponding score
myName = formatAgentName(me['id'])
myRole = me['role']
myTeam = me['team']
profileName = formatAgentName(profile['id'])
profileTeam = profile['team']
patterns = {}
if myTeam == "WEREWOLF":
for id in wolves:
wolf = formatAgentName(id)
patterns['ESTIMATE '+wolf+' WEREWOLF'] = 10
patterns['COMINGOUT '+wolf+' WEREWOLF'] = 10
patterns['DIVINED '+wolf+' WEREWOLF'] = 30
patterns['ESTIMATE '+wolf+' POSSESSED'] = 10
patterns['COMINGOUT '+wolf+' POSSESSED'] = 10
patterns['ESTIMATE '+wolf+' VILLAGER'] = -10
patterns['COMINGOUT '+wolf+' VILLAGER'] = -10
patterns['ESTIMATE '+wolf+' HUMAN'] = -10
patterns['COMINGOUT '+wolf+' HUMAN'] = -10
patterns['DIVINED '+wolf+' HUMAN'] = -40 #Someone saying it divined us as HUMAN is lying to protect us
patterns['VOTE '+wolf] = 15
elif myTeam == "HUMAN":
#Coming out as a WEREWOLF is a POSSESSED technique, at a time where killing wolves is more important
patterns['COMINGOUT '+profileName+' WEREWOLF'] = -10
for id in humans:
human = formatAgentName(id)
patterns['VOTE '+human] = 5
patterns['ESTIMATE '+human+' WEREWOLF'] = 5
if myRole == 'SEER':
patterns['COMINGOUT '+profileName+' SEER'] = 30
if myRole == 'MEDIUM':
patterns['COMINGOUT '+profileName+' MEDIUM'] = 30
patterns['ESTIMATE '+myName+' WEREWOLF'] = 10
patterns['COMINGOUT '+myName+' WEREWOLF'] = 10
patterns['DIVINED '+myName+' WEREWOLF'] = 15
patterns['ESTIMATE '+myName+' POSSESSED'] = 10
patterns['COMINGOUT '+myName+' POSSESSED'] = 10
patterns['ESTIMATE '+myName+' VILLAGER'] = -10
patterns['COMINGOUT '+myName+' VILLAGER'] = -10
patterns['ESTIMATE '+myName+' HUMAN'] = -10
patterns['COMINGOUT '+myName+' HUMAN'] = -10
patterns['ESTIMATE '+myName+' MEDIUM'] = -10
patterns['COMINGOUT '+myName+' MEDIUM'] = -10
patterns['ESTIMATE '+myName+' BODYGUARD'] = -10
patterns['COMINGOUT '+myName+' BODYGUARD'] = -10
patterns['VOTE '+myName] = 25
return patterns
def getAllTexts(profile):
txts = []
for talk in profile['talkHistory']:
txts.append(talk["text"])
return txts