James Campbell :: horrible.py (v4)

This bot has played 1570 games (19 wins / 0 draws / 1551 losses).

Play against this bot as X or as O.

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

Bot P W D L Points Size From beginner One hit wonder Goldfish
house : : anarchist.py 10 10 0 0 10 None None None None
house : : antagonist.py 10 10 0 0 10 None None None None
Jon Bannister : : anybot_r282.py (v5) 10 10 0 0 10 974 False False True
Dan Miller : : board_bot.py 10 10 0 0 10 596 False False False
Stefano Chiodino : : bot.py (v2) 10 10 0 0 10 183 False False True

...and these bots have done worst

Bot P W D L Points Size From beginner One hit wonder Goldfish
Matt Wheeler : : smol.py 10 10 0 0 10 77 False True True
Jordan Banting : : trololololol.py (v1) 10 10 0 0 10 402 False False True
Tom Campbell : : winblockprevent.py (v5) 10 10 0 0 10 321 False False True
Martijn Pieters : : zopatista.py (v9) 10 10 0 0 10 2649 False False False
Ronan Murphy : : loser.py 10 5 0 5 0 105 False False True

All standings against horrible.py

The code

      
import copy
import random
from botany_connectfour import game




def get_next_move(board, token):
    available_moves = game.available_moves(board)
    avoid_win = []
    avoid_block = []

    preference = [6, 0, 5, 1, 4, 2, 3]
    def choose_xtrm(pos_moves):
        choice = next((item for item in preference if item in pos_moves), None)
        return choice

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

    for col in available_moves:
        board1 = [l[:] for l in board]
        game.make_move(board1, col, other_token)
        if game.check_winner(board1) is not None:
            # available_moves.remove(col)
            avoid_block.append(col)
            continue

        board2 = [l[:] for l in board]
        game.make_move(board2, col, token)
        if game.check_winner(board2) is not None:
            # available_moves.remove(col)
            avoid_win.append(col)

    # print(avoid)
    better_moves = [i for i in available_moves if i not in avoid_win]
    even_better_moves = [i for i in better_moves if i not in avoid_block]

    if even_better_moves != []:
        return choose_xtrm(even_better_moves)
    elif better_moves != []:
        return choose_xtrm(better_moves)
    else:
        return choose_xtrm(available_moves)