From 8752db2d57c185c51460d89a9c0fac4d2298a00e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Fri, 11 Sep 2020 00:27:55 +0200 Subject: [PATCH] repo structure --- .drone.yml | 10 +++++ .gitignore | 2 + requirements.txt | 1 + strat/__pycache__/main.cpython-38.pyc | Bin 0 -> 379 bytes strat/__pycache__/rand.cpython-38.pyc | Bin 0 -> 379 bytes strat/main.py | 13 ++++++ strat/rand.py | 13 ++++++ tournament.py | 59 ++++++++++++++++++++++++++ 8 files changed, 98 insertions(+) create mode 100644 .drone.yml create mode 100644 .gitignore create mode 100644 requirements.txt create mode 100644 strat/__pycache__/main.cpython-38.pyc create mode 100644 strat/__pycache__/rand.cpython-38.pyc create mode 100644 strat/main.py create mode 100644 strat/rand.py create mode 100644 tournament.py diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..8058c71 --- /dev/null +++ b/.drone.yml @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..238eac7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +venv/ \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..296d654 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +numpy \ No newline at end of file diff --git a/strat/__pycache__/main.cpython-38.pyc b/strat/__pycache__/main.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5c00a361448d389c5ebf9f29d0f417729ff39bc6 GIT binary patch literal 379 zcmYjNJx{|h5IujSM9?sGgFlc3ROX5z!Q7={@q(gWR6-LcvK^#K=>$InHuy`PkUC|9 zm5Fmzq@MNO`R<+W&c08QV;~!UsD~f&+YlTYr{IQQM??t7N>B_ridRq^*&I^YlLE6v zsQfoc7eTls*gGNz9lS7PD{jsmd*W{b`8(V2j?V#wlR+KrtIl8}I)QS<%p^>}hyXNc zFf)vL^*tSZg=Z|B;m1jnY?0NYK zCVatfVx7s{WtA2BqFMVG^F?8cT8FpTQzBqPI+BlAOl*dfNrj4ZTQzGFQM60#njO#y T2|k`wHMV7b9d@)~|5*G1Bb`ZE literal 0 HcmV?d00001 diff --git a/strat/__pycache__/rand.cpython-38.pyc b/strat/__pycache__/rand.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0a39a3d925d937c1916183c5a12af4ff3e1fc7fe GIT binary patch literal 379 zcmYjMJ5R$f5cb(li4cJ$8!U`jKrmMn3Fa;pOBNLMq7s@ok)0q_N+H7Hicj)Jw2q-hcr?(5BJU z0?itD(}Fs9u&_z*Ut z&fmzjHfzth_^es^5c7HAirVmB+#!*G1A1D<5E9!XiX_ShrmLEj4anPsHp6y^JAF8= PYV6AVif?p$f2jTd3n)ur literal 0 HcmV?d00001 diff --git a/strat/main.py b/strat/main.py new file mode 100644 index 0000000..4c12e11 --- /dev/null +++ b/strat/main.py @@ -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 diff --git a/strat/rand.py b/strat/rand.py new file mode 100644 index 0000000..7a5ee1d --- /dev/null +++ b/strat/rand.py @@ -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 diff --git a/tournament.py b/tournament.py new file mode 100644 index 0000000..cc43bf1 --- /dev/null +++ b/tournament.py @@ -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])