commit 8752db2d57c185c51460d89a9c0fac4d2298a00e Author: Torma Kristóf Date: Fri Sep 11 00:27:55 2020 +0200 repo structure 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 0000000..5c00a36 Binary files /dev/null and b/strat/__pycache__/main.cpython-38.pyc differ diff --git a/strat/__pycache__/rand.cpython-38.pyc b/strat/__pycache__/rand.cpython-38.pyc new file mode 100644 index 0000000..0a39a3d Binary files /dev/null and b/strat/__pycache__/rand.cpython-38.pyc differ 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])