Skip to content

Commit 8497aa5

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 143b434 commit 8497aa5

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

game_theory/README.md

+1-1
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

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import math
22

3+
34
class MinMax:
45
"""
56
A class to represent a game using the Minimax algorithm.
@@ -28,7 +29,7 @@ class MinMax:
2829
def __init__(self, scores: list[int]) -> None:
2930
"""
3031
Initialize the MinMax game with a list of scores.
31-
32+
3233
Parameters:
3334
----------
3435
scores : list[int]
@@ -37,10 +38,12 @@ def __init__(self, scores: list[int]) -> None:
3738
self.scores = scores
3839
self.tree_depth = int(math.log2(len(scores)))
3940

40-
def minimax(self, current_depth: int = 0, node_index: int = 0, is_max_turn: bool = True) -> int:
41+
def minimax(
42+
self, current_depth: int = 0, node_index: int = 0, is_max_turn: bool = True
43+
) -> int:
4144
"""
4245
Recursive implementation of the minimax algorithm.
43-
46+
4447
Parameters:
4548
----------
4649
current_depth : int
@@ -64,22 +67,22 @@ def minimax(self, current_depth: int = 0, node_index: int = 0, is_max_turn: bool
6467

6568
if current_depth == self.tree_depth:
6669
return self.scores[node_index]
67-
70+
6871
if is_max_turn:
6972
return max(
7073
self.minimax(current_depth + 1, node_index * 2, False),
71-
self.minimax(current_depth + 1, node_index * 2 + 1, False)
74+
self.minimax(current_depth + 1, node_index * 2 + 1, False),
7275
)
7376
else:
7477
return min(
7578
self.minimax(current_depth + 1, node_index * 2, True),
76-
self.minimax(current_depth + 1, node_index * 2 + 1, True)
79+
self.minimax(current_depth + 1, node_index * 2 + 1, True),
7780
)
7881

7982
def find_optimal_value(self) -> int:
8083
"""
8184
Find and return the optimal value for the maximizing player.
82-
85+
8386
Returns:
8487
-------
8588
int
@@ -93,8 +96,10 @@ def find_optimal_value(self) -> int:
9396
"""
9497
return self.minimax()
9598

99+
96100
if __name__ == "__main__":
97101
import doctest
102+
98103
doctest.testmod()
99104

100105
scores = [3, 5, 2, 9, 12, 5, 23, 23]

0 commit comments

Comments
 (0)