-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayerloader.py
40 lines (30 loc) · 944 Bytes
/
playerloader.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
# Import players files
import glob
import imp
import os
import Players
class PlayerWrapper:
def __init__(self, player):
self.ai = player
self.stats = {}
self.reset_stats()
def reset_stats(self):
self.stats["Win"] = 0
self.stats["Draw"] = 0
self.stats["Loss"] = 0
self.stats["For"] = 0
self.stats["Against"] = 0
self.stats["Moves"] = 0
def score(self):
return self.stats["Win"] * 3 + self.stats["Draw"] * 1\
+ self.stats["Loss"] * 0
def import_players():
list_files = glob.glob("Players/*.py")
players_files = [('./' + f, f.replace(os.sep, '.')[:-3])
for f in list_files
if "__init__" not in f]
listPlayers = []
for fname, mname in players_files:
mod = imp.load_source(mname, fname)
listPlayers.append(PlayerWrapper(mod.getPlayer()))
return listPlayers