Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fe7ea61

Browse files
committedOct 11, 2024·
Resolve merge conflicts
2 parents 4978277 + 8497aa5 commit fe7ea61

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed
 

‎game_theory/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Game Theory Algorithms
22

3-
This repository contains implementations of various algorithms related to game theory.
3+
This repository contains implementations of various algorithms related to game theory.
44

55
## Algorithms
66

‎game_theory/min_max.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ def __init__(self, scores: list[int]):
2626
self.tree_depth = int(math.log2(len(scores)))
2727

2828
def minimax(
29+
<<<<<<< HEAD
2930
self, current_depth: int = 0,
3031
node_index: int = 0, is_max_turn: bool = True
32+
=======
33+
self, current_depth: int = 0, node_index: int = 0, is_max_turn: bool = True
34+
>>>>>>> 8497aa531c8636d5735e3df3d7583d9c05a323b5
3135
) -> int:
3236
"""
3337
Recursive implementation of the minimax algorithm.
@@ -50,16 +54,19 @@ def minimax(
5054
if current_depth == self.tree_depth:
5155
return self.scores[node_index]
5256

57+
<<<<<<< HEAD
5358
# Recursive case
59+
=======
60+
>>>>>>> 8497aa531c8636d5735e3df3d7583d9c05a323b5
5461
if is_max_turn:
5562
return max(
5663
self.minimax(current_depth + 1, node_index * 2, False),
57-
self.minimax(current_depth + 1, node_index * 2 + 1, False)
64+
self.minimax(current_depth + 1, node_index * 2 + 1, False),
5865
)
5966
else:
6067
return min(
6168
self.minimax(current_depth + 1, node_index * 2, True),
62-
self.minimax(current_depth + 1, node_index * 2 + 1, True)
69+
self.minimax(current_depth + 1, node_index * 2 + 1, True),
6370
)
6471

6572
def find_optimal_value(self) -> int:
@@ -73,3 +80,16 @@ def find_optimal_value(self) -> int:
7380
"""
7481
return self.minimax()
7582

83+
<<<<<<< HEAD
84+
=======
85+
86+
if __name__ == "__main__":
87+
import doctest
88+
89+
doctest.testmod()
90+
91+
scores = [3, 5, 2, 9, 12, 5, 23, 23]
92+
game = MinMax(scores)
93+
optimal_value = game.find_optimal_value()
94+
print(f"The optimal value is: {optimal_value}")
95+
>>>>>>> 8497aa531c8636d5735e3df3d7583d9c05a323b5

0 commit comments

Comments
 (0)
Please sign in to comment.