Bonus task #1

This commit is contained in:
Konrad Pierzyński 2019-10-15 17:52:06 +02:00
parent 517b7029d0
commit 87a6b5c85e
2 changed files with 39 additions and 1 deletions

View File

@ -1,3 +1,27 @@
# TEG_programistyczne
Zadania z teorii gier
#### Zadanie 1:
_wyplata.py_
Funkcja służy do obliczenia wypłaty danego gracza przy wybranej strategii i macierzy wypłat.
**Przykładowe użycie**:
Dla danej gry:
| | L | P |
| --- | ---- | ---- |
| G | 0,2 | 0,2 |
| S | 2,0 | -1,1 |
| D | -1,1 | 2,0 |
i dla danych strategii $\sigma_1$ = $\frac{1}{2}$G + $\frac{1}{2}$S i $\sigma_2$ = $\frac{1}{4}$L + $\frac{3}{4}$P wypłata gracza drugiego
```python
wyplata(2, [1/2,1/2,0], [1/4,3/4], [[0,0],[2,-1],[-1,2]], [[2,2],[0,1],[1,0]] )
```
wynosi 1$\frac{3}{8}$.
---

14
wyplata.py Normal file
View File

@ -0,0 +1,14 @@
def wyplata( player, strategy_one, strategy_two, pay_one, pay_two ):
if( len(strategy_one) != len(pay_one) ):
raise Exception("Wrong arguments")
if( sum(strategy_one) != 1 or sum(strategy_two) != 1 ):
raise Exception("Wrong arguments")
value = 0
for i in range(0,len(strategy_one)):
for k in range(0, len(strategy_two)):
value += strategy_one[i]*strategy_two[k] * (pay_one[i][k] if player == 1 else pay_two[i][k])
return value
#print(wyplata(2, [1/2,1/2,0], [1/4,3/4], [[0,0],[2,-1],[-1,2]], [[2,2],[0,1],[1,0]] ))