repo structure

This commit is contained in:
Torma Kristóf 2020-09-11 00:27:55 +02:00
commit 8752db2d57
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
8 changed files with 98 additions and 0 deletions

10
.drone.yml Normal file
View 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
View File

@ -0,0 +1,2 @@
.idea/
venv/

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
numpy

Binary file not shown.

Binary file not shown.

13
strat/main.py Normal file
View 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
View 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
View 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])