Tom Campbell :: winblockprevent.py (v5)

This bot has played 1470 games (695 wins / 140 draws / 635 losses).

Play against this bot as X or as O.

These bots have done best aganist winblockprevent.py...

Bot P W D L Points Size From beginner One hit wonder Goldfish
Martijn Pieters : : zopatista.py (v9) 10 7 3 0 7 2649 False False False
Séverin Hatt : : romuald_no_last_check.py (v1) 10 8 0 2 6 1598 False False True
Robert Seaman : : not_minimax.py (v25) 10 7 1 2 5 3501 False False True
Jon Bannister : : anybot_r282.py (v5) 10 4 5 1 3 974 False False True
Robert Howlett : : smart11.py (v1) 10 4 3 3 1 191 False False True

...and these bots have done worst

Bot P W D L Points Size From beginner One hit wonder Goldfish
James Campbell : : horrible.py (v4) 10 0 0 10 -10 246 False False True
Ronan Murphy : : loser.py 10 0 0 10 -10 105 False False True
Luke Spademan : : lossingbot.py (v3) 10 0 0 10 -10 129 False False True
house : : opportunist.py 10 0 0 10 -10 None None None None
Peter Inglesby : : random.py 10 0 0 10 -10 26 False True True

All standings against winblockprevent.py

The code

      
import random
from botany_connectfour import game


def get_next_move(board, token, move_list):
    if len(move_list) < 5:
        return(3)

    available_moves = game.available_moves(board)

    if token == "X":
        other_token = "O"
    else:
        other_token = "X"

    groundblocks = []
    upperblocks = []

    for column in available_moves:
        for row in range(0, 6):
            if board[column][row] == ".":
                boardcopy = [l[:] for l in board]

                boardcopy[column][row] = token
                if game.check_winner(boardcopy) is not None:
                    return(column)
                boardcopy[column][row] = "."

                boardcopy[column][row] = other_token
                if game.check_winner(boardcopy) is not None:
                    groundblocks.append(column)
                boardcopy[column][row] = "."

                if row < 5:
                    boardcopy[column][row + 1] = other_token
                    if game.check_winner(boardcopy) is not None:
                        upperblocks.append(column)
                break

    if groundblocks != []:
        return(groundblocks[0])

    bettermoves = [x for x in available_moves if x not in upperblocks]
    if bettermoves != []:
        evenbettermoves = [x for x in bettermoves if x not in [0, 6]]
        if evenbettermoves != []:
            return(random.choice(evenbettermoves))
        return(random.choice(bettermoves))
    return(random.choice(available_moves))