@@ -41,28 +41,22 @@ class Game(Model):
41
41
results = JSONField ()
42
42
43
43
class Meta :
44
- managed = False
44
+ abstract = True
45
45
46
46
47
- class Tournament (Model ):
47
+ class GameDefinition (Model ):
48
+ created = DateTimeField (auto_now_add = True , editable = False )
49
+ last_updated = DateTimeField (auto_now = True , editable = False )
50
+ turns = IntegerField ()
51
+ noise = FloatField ()
52
+ player_list = ManyToManyField ('InternalStrategy' )
48
53
49
- PENDING = 0
50
- RUNNING = 1
51
- SUCCESS = 2
52
- FAILED = 3
54
+ class Meta :
55
+ abstract = True
53
56
54
- STATUS_CHOICES = (
55
- (PENDING , 'PENDING' ),
56
- (RUNNING , 'RUNNING' ),
57
- (SUCCESS , 'SUCCESS' ),
58
- (FAILED , 'FAILED' ),
59
- )
60
57
61
- # Fields
62
- created = DateTimeField (auto_now_add = True , editable = False )
63
- last_updated = DateTimeField (auto_now = True , editable = False )
64
- status = IntegerField (choices = STATUS_CHOICES , default = PENDING )
65
- results = JSONField (null = True )
58
+ class Tournament (Game ):
59
+
66
60
definition = ForeignKey ('TournamentDefinition' )
67
61
68
62
def run (self , strategies ):
@@ -80,37 +74,14 @@ def run(self, strategies):
80
74
return results
81
75
82
76
83
- class TournamentDefinition (Model ):
84
- # Fields
77
+ class TournamentDefinition (GameDefinition ):
85
78
name = CharField (max_length = 255 )
86
- created = DateTimeField (auto_now_add = True , editable = False )
87
- last_updated = DateTimeField (auto_now = True , editable = False )
88
- turns = IntegerField ()
89
79
repetitions = IntegerField ()
90
- noise = FloatField ()
91
80
with_morality = BooleanField ()
92
- player_list = ManyToManyField ('InternalStrategy' )
93
81
94
82
95
- class Match (Model ):
83
+ class Match (Game ):
96
84
97
- PENDING = 0
98
- RUNNING = 1
99
- SUCCESS = 2
100
- FAILED = 3
101
-
102
- STATUS_CHOICES = (
103
- (PENDING , 'PENDING' ),
104
- (RUNNING , 'RUNNING' ),
105
- (SUCCESS , 'SUCCESS' ),
106
- (FAILED , 'FAILED' ),
107
- )
108
-
109
- # Fields
110
- created = DateTimeField (auto_now_add = True , editable = False )
111
- last_updated = DateTimeField (auto_now = True , editable = False )
112
- status = IntegerField (choices = STATUS_CHOICES , default = PENDING )
113
- results = JSONField (null = True )
114
85
definition = ForeignKey ('MatchDefinition' )
115
86
116
87
def run (self , strategies ):
@@ -125,33 +96,14 @@ def run(self, strategies):
125
96
return match
126
97
127
98
128
- class MatchDefinition (Model ):
129
- created = DateTimeField (auto_now_add = True , editable = False )
130
- last_updated = DateTimeField (auto_now = True , editable = False )
131
- turns = IntegerField ()
132
- noise = FloatField ()
133
- player_list = ManyToManyField ('InternalStrategy' )
99
+ class MatchDefinition (GameDefinition ):
134
100
101
+ class Meta :
102
+ managed = True
135
103
136
- class MoranProcess (Model ):
137
104
138
- PENDING = 0
139
- RUNNING = 1
140
- SUCCESS = 2
141
- FAILED = 3
105
+ class MoranProcess (Game ):
142
106
143
- STATUS_CHOICES = (
144
- (PENDING , 'PENDING' ),
145
- (RUNNING , 'RUNNING' ),
146
- (SUCCESS , 'SUCCESS' ),
147
- (FAILED , 'FAILED' ),
148
- )
149
-
150
- # Fields
151
- created = DateTimeField (auto_now_add = True , editable = False )
152
- last_updated = DateTimeField (auto_now = True , editable = False )
153
- status = IntegerField (choices = STATUS_CHOICES , default = PENDING )
154
- results = JSONField (null = True )
155
107
definition = ForeignKey ('MoranDefinition' )
156
108
157
109
def run (self , strategies ):
@@ -168,23 +120,19 @@ def run(self, strategies):
168
120
return mp
169
121
170
122
171
- class MoranDefinition (Model ):
172
- created = DateTimeField (auto_now_add = True , editable = False )
173
- last_updated = DateTimeField (auto_now = True , editable = False )
174
- turns = IntegerField ()
175
- noise = FloatField ()
123
+ class MoranDefinition (GameDefinition ):
176
124
mode = CharField (max_length = 2 )
177
- player_list = ManyToManyField ('InternalStrategy' )
178
125
179
126
180
127
class InternalStrategy (Model ):
128
+ """
129
+ This model is used to represent strategies in an internal
130
+ database table. Games reference this in a ManyToMany
131
+ to store the strategies in their player_list field. This is
132
+ necessary to facilitate normalization of the database.
133
+ """
181
134
id = TextField (primary_key = True )
182
135
created = DateTimeField (auto_now_add = True , editable = False )
183
136
last_updated = DateTimeField (auto_now = True , editable = False )
184
137
185
138
186
- class Result (Model ):
187
- created = DateTimeField (auto_now_add = True , editable = False )
188
- last_updated = DateTimeField (auto_now = True , editable = False )
189
- type = CharField (max_length = 255 )
190
- result = JSONField ()
0 commit comments