Skip to main content
added 19 characters in body
Source Link
toolic
  • 16.4k
  • 6
  • 29
  • 221

Layout

Lines like this:

if terminal(board): return utility(board), count+1

are typically split into 2 lines:

if terminal(board):
    return utility(board), count+1

The black program can be used to automatically format the code this way. black can also format the code to use consistent whitespace in lines like:

def maxvalue(board,alpha,beta,count):

This style is more common:

def maxvalue(board, alpha, beta, count):

Unused code

The ruff tool identifies this line as unused:

import time

It can be deleted.

Naming

The variable names vT, vret and v do not convey much meaning.

The PEP 8 style guide recommends snake_case for function and variable names. You have done so for some of the names, but others should also follow this convention. For example:

newboard would be new_board

minimax would be mini_max

The constant O (uppercase letter "o") is easily confused with the number zero (0). Consider renaming O as something like player_o, and the same for X.

Documentation

In addition to your function docstrings, PEP 8 also recommends adding a docstring at the top of the code summarizing its purpose and showing examples of how to call the functions.

Main guard

You can add a "main" guard at the bottom of the file so that you can show an example of how the code is run. This would go after the function definitions:

if __name__ == '__main__':
    # call some functions

Layout

Lines like this:

if terminal(board): return utility(board), count+1

are typically split into 2 lines:

if terminal(board):
    return utility(board), count+1

The black program can be used to automatically format the code this way. black can also use consistent whitespace in lines like:

def maxvalue(board,alpha,beta,count):

This style is more common:

def maxvalue(board, alpha, beta, count):

Unused code

The ruff tool identifies this line as unused:

import time

It can be deleted.

Naming

The variable names vT, vret and v do not convey much meaning.

The PEP 8 style guide recommends snake_case for function and variable names. You have done so for some of the names, but others should also follow this convention. For example:

newboard would be new_board

minimax would be mini_max

The constant O (uppercase letter "o") is easily confused with the number zero (0). Consider renaming O as something like player_o, and the same for X.

Documentation

In addition to your function docstrings, PEP 8 also recommends adding a docstring at the top of the code summarizing its purpose and showing examples of how to call the functions.

Main guard

You can add a "main" guard at the bottom of the file so that you can show an example of how the code is run. This would go after the function definitions:

if __name__ == '__main__':
    # call some functions

Layout

Lines like this:

if terminal(board): return utility(board), count+1

are typically split into 2 lines:

if terminal(board):
    return utility(board), count+1

The black program can be used to automatically format the code this way. black can also format the code to use consistent whitespace in lines like:

def maxvalue(board,alpha,beta,count):

This style is more common:

def maxvalue(board, alpha, beta, count):

Unused code

The ruff tool identifies this line as unused:

import time

It can be deleted.

Naming

The variable names vT, vret and v do not convey much meaning.

The PEP 8 style guide recommends snake_case for function and variable names. You have done so for some of the names, but others should also follow this convention. For example:

newboard would be new_board

minimax would be mini_max

The constant O (uppercase letter "o") is easily confused with the number zero (0). Consider renaming O as something like player_o, and the same for X.

Documentation

In addition to your function docstrings, PEP 8 also recommends adding a docstring at the top of the code summarizing its purpose and showing examples of how to call the functions.

Main guard

You can add a "main" guard at the bottom of the file so that you can show an example of how the code is run. This would go after the function definitions:

if __name__ == '__main__':
    # call some functions
Source Link
toolic
  • 16.4k
  • 6
  • 29
  • 221

Layout

Lines like this:

if terminal(board): return utility(board), count+1

are typically split into 2 lines:

if terminal(board):
    return utility(board), count+1

The black program can be used to automatically format the code this way. black can also use consistent whitespace in lines like:

def maxvalue(board,alpha,beta,count):

This style is more common:

def maxvalue(board, alpha, beta, count):

Unused code

The ruff tool identifies this line as unused:

import time

It can be deleted.

Naming

The variable names vT, vret and v do not convey much meaning.

The PEP 8 style guide recommends snake_case for function and variable names. You have done so for some of the names, but others should also follow this convention. For example:

newboard would be new_board

minimax would be mini_max

The constant O (uppercase letter "o") is easily confused with the number zero (0). Consider renaming O as something like player_o, and the same for X.

Documentation

In addition to your function docstrings, PEP 8 also recommends adding a docstring at the top of the code summarizing its purpose and showing examples of how to call the functions.

Main guard

You can add a "main" guard at the bottom of the file so that you can show an example of how the code is run. This would go after the function definitions:

if __name__ == '__main__':
    # call some functions