Skip to content

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

Merged
merged 6 commits into from
Jul 7, 2019
Merged

Conversation

aditiagarwal34550
Copy link
Member

No description provided.

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.
@aditiagarwal34550 aditiagarwal34550 changed the title Dynamic programming minimax Jul 3, 2019
Copy link
Member

@cclauss cclauss left a 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):
Copy link
Member

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))

Copy link
Member

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))
Copy link
Member

@cclauss cclauss Jul 6, 2019

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):
Copy link
Member

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
@aditiagarwal34550
Copy link
Member Author

@cclauss Thank You for the code review.
All changes are done.
Please review the changes.
Thanks.

Copy link
Member

@cclauss cclauss left a 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.

@cclauss cclauss merged commit 4ff2a9d into TheAlgorithms:master Jul 7, 2019
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants