coding-horror / basic-computer-games

An updated version of the classic "Basic Computer Games" book, with well-written examples in a variety of common MEMORY SAFE, SCRIPTING programming languages. See https://coding-horror.github.io/basic-computer-games/
The Unlicense
10.84k stars 1.33k forks source link

A function never called in tictactoe2.py #801

Open Vaxick opened 2 years ago

Vaxick commented 2 years ago

Just watched the code of this specific file, and noticed that there is a function that is never called

def think(board, g, h, moves):

    if board[Space.MID_CENTER] is OccupiedBy.EMPTY:
        return Space.MID_CENTER

    if board[Space.MID_CENTER] is OccupiedBy.PLAYER:
        if (
            board[Space.TOP_CENTER] is OccupiedBy.PLAYER
            and board[Space.TOP_LEFT] is OccupiedBy.EMPTY
            or board[Space.MID_LEFT] is OccupiedBy.PLAYER
            and board[Space.TOP_LEFT] is OccupiedBy.EMPTY
        ):
            return Space.BOT_LEFT
        elif (
            board[Space.MID_RIGHT] is OccupiedBy.PLAYER
            and board[Space.BOT_RIGHT] is OccupiedBy.EMPTY
            or board[Space.BOT_CENTER] is OccupiedBy.PLAYER
            and board[Space.BOT_RIGHT] is OccupiedBy.EMPTY
        ):
            return Space.BOT_RIGHT

    if g == OccupiedBy.PLAYER:
        j = 3 * int((moves - 1) / 3)
        if move == j + 1:  # noqa: This definitely is a bug!
            k = 1
        if move == j + 2:  # noqa: This definitely is a bug!
            k = 2
        if move == j + 3:  # noqa: This definitely is a bug!
            k = 3
        return subthink(g, h, j, k)  # noqa: This definitely is a bug!

Isn't it better to just remove it?

coding-horror commented 1 year ago

If it's never called, I say we can remove it? Should this be in the porting notes?