-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
minimax #947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
minimax #947
Conversation
minimax algorithm is used for game like tic tac toe. It traces the path and selects the optimal move.
Minimax is used in decision making and game theory to find the optimal move for a player, when your opponent also plays optimally. It is widely used in games like Tic-Tac-Toe, Chess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aditiagarwal34550 Thanks for this cool contribution. This file must go into one of the directories so please rename the file above and add one of the current directory names and a / before the beginning of the filename. Nice work!
minimax.py
Outdated
|
||
def minimax (Depth, nodeIndex, isMax, scores, height): | ||
|
||
if (Depth == height): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These () are not needed and not helpful.
minimax.py
Outdated
if (isMax): | ||
return max(minimax(Depth + 1, nodeIndex * 2, False, scores, height), minimax(Depth + 1, nodeIndex * 2 + 1, False, scores, height)) | ||
return min(minimax(Depth + 1, nodeIndex * 2, True, scores, height), minimax(Depth + 1, nodeIndex * 2 + 1, True, scores, height)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Insert `if name == 'main': and then indent all other lines below it. This allows us to run tests without running your code.
minimax.py
Outdated
return scores[nodeIndex] | ||
|
||
if (isMax): | ||
return max(minimax(Depth + 1, nodeIndex * 2, False, scores, height), minimax(Depth + 1, nodeIndex * 2 + 1, False, scores, height)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines are too long to be read on GitHub without scrolling left and right so put the whole return value in () and then wrap the lines after the comma to improve readability.
minimax.py
Outdated
if (Depth == height): | ||
return scores[nodeIndex] | ||
|
||
if (isMax): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These () are not needed and not helpful.
…nd the optimal move for a player, assuming that your opponent also plays optimally
Minimax Algorithm
@cclauss Thank You for the code review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done! Please consider adding doctests in a future pull request. Thanks.
* minimax.py minimax algorithm is used for game like tic tac toe. It traces the path and selects the optimal move. * minimax.py Minimax is used in decision making and game theory to find the optimal move for a player, when your opponent also plays optimally. It is widely used in games like Tic-Tac-Toe, Chess. * Delete minimax.py * Update minimax.py * Minimax is a backtracking algorithm that is used in game theory to find the optimal move for a player, assuming that your opponent also plays optimally
No description provided.