File tree 1 file changed +32
-0
lines changed 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ def fictitious_play (payoff_matrix_A , payoff_matrix_B , iterations = 100 ):
2
+ n = payoff_matrix_A .shape [0 ]
3
+ m = payoff_matrix_A .shape [1 ]
4
+
5
+ # Initialize counts and strategies
6
+ counts_A = np .zeros (n )
7
+ counts_B = np .zeros (m )
8
+ strategy_A = np .ones (n ) / n
9
+ strategy_B = np .ones (m ) / m
10
+
11
+ for _ in range (iterations ):
12
+ # Update counts
13
+ counts_A += strategy_A
14
+ counts_B += strategy_B
15
+
16
+ # Calculate best responses
17
+ best_response_A = np .argmax (payoff_matrix_A @ strategy_B )
18
+ best_response_B = np .argmax (payoff_matrix_B .T @ strategy_A )
19
+
20
+ # Update strategies
21
+ strategy_A = np .zeros (n )
22
+ strategy_A [best_response_A ] = 1
23
+ strategy_B = np .zeros (m )
24
+ strategy_B [best_response_B ] = 1
25
+
26
+ return strategy_A , strategy_B
27
+
28
+ # Example usage
29
+ payoff_A = np .array ([[3 , 0 ], [5 , 1 ]])
30
+ payoff_B = np .array ([[2 , 4 ], [0 , 2 ]])
31
+ strategies = fictitious_play (payoff_A , payoff_B )
32
+ print ("Fictitious Play strategies:" , strategies )
You can’t perform that action at this time.
0 commit comments