diff --git a/README.md b/README.md index cc5308f..429f689 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,27 @@ # TEG_programistyczne -Zadania z teorii gier \ No newline at end of file +#### 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}$. + +--- diff --git a/wyplata.py b/wyplata.py new file mode 100644 index 0000000..6c092de --- /dev/null +++ b/wyplata.py @@ -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]] ))