repo structure
This commit is contained in:
commit
8752db2d57
10
.drone.yml
Normal file
10
.drone.yml
Normal file
@ -0,0 +1,10 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: run_tournament
|
||||
image: "python:3.8"
|
||||
commands:
|
||||
- pip3 install -r requirements.txt
|
||||
- python3 tournament.py
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
.idea/
|
||||
venv/
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@ -0,0 +1 @@
|
||||
numpy
|
BIN
strat/__pycache__/main.cpython-38.pyc
Normal file
BIN
strat/__pycache__/main.cpython-38.pyc
Normal file
Binary file not shown.
BIN
strat/__pycache__/rand.cpython-38.pyc
Normal file
BIN
strat/__pycache__/rand.cpython-38.pyc
Normal file
Binary file not shown.
13
strat/main.py
Normal file
13
strat/main.py
Normal file
@ -0,0 +1,13 @@
|
||||
import numpy as np
|
||||
|
||||
|
||||
def decision(h1, h2):
|
||||
if len(h1) == 0:
|
||||
r = np.random.randint(2)
|
||||
return r
|
||||
else:
|
||||
avg = 1.0 * sum(h1) / len(h1)
|
||||
if avg <= 0.5:
|
||||
return 0
|
||||
else:
|
||||
return 1
|
13
strat/rand.py
Normal file
13
strat/rand.py
Normal file
@ -0,0 +1,13 @@
|
||||
import numpy as np
|
||||
|
||||
|
||||
def decision(h1, h2):
|
||||
if len(h2) == 0:
|
||||
r = np.random.randint(2)
|
||||
return r
|
||||
else:
|
||||
avg = 1.0 * sum(h2) / len(h2)
|
||||
if avg <= 0.5:
|
||||
return 0
|
||||
else:
|
||||
return 1
|
59
tournament.py
Normal file
59
tournament.py
Normal file
@ -0,0 +1,59 @@
|
||||
# Y8O353 +
|
||||
import os
|
||||
import sys
|
||||
import importlib
|
||||
|
||||
sys.path.append('strat')
|
||||
|
||||
|
||||
def gamet(u, v):
|
||||
mod1 = importlib.import_module(strats[u])
|
||||
mod2 = importlib.import_module(strats[v])
|
||||
[p1, p2] = [0, 0]
|
||||
for _ in range(1000):
|
||||
h1 = []
|
||||
h2 = []
|
||||
for __ in range(200):
|
||||
s1 = mod1.decision(h1, h2)
|
||||
s2 = mod2.decision(h2, h1)
|
||||
if s1 <= 0.5:
|
||||
s1 = 0
|
||||
else:
|
||||
s1 = 1
|
||||
if s2 <= 0.5:
|
||||
s2 = 0
|
||||
else:
|
||||
s2 = 1
|
||||
h1.append(s1)
|
||||
h2.append(s2)
|
||||
p1 += U[s1][s2]
|
||||
p2 += U[s2][s1]
|
||||
return [p1, p2]
|
||||
|
||||
|
||||
def tournm(S):
|
||||
for i in range(len(S)):
|
||||
for j in range(i + 1, len(S)):
|
||||
[p1, p2] = gamet(S[i], S[j])
|
||||
results[S[i]] += p1
|
||||
results[S[j]] += p2
|
||||
|
||||
|
||||
U = [[3, 0], [5, 1]]
|
||||
|
||||
strats = os.listdir("strat")
|
||||
strats = [x.split('.')[0] for x in strats if x.split('.')[-1] == "py"]
|
||||
n = len(strats)
|
||||
results = [0] * n
|
||||
A = range(n)
|
||||
|
||||
tournm(A)
|
||||
|
||||
print('Tournament begins')
|
||||
for i in A:
|
||||
print(strats[i] + '\t' + '\t', results[i])
|
||||
wA = A[0]
|
||||
for i in A:
|
||||
if results[i] > results[wA]:
|
||||
wA = i
|
||||
print('The winner is', strats[wA])
|
Loading…
Reference in New Issue
Block a user