Dilwoar Hussain :: dee-bot.py (v12)

This bot has played 1740 games (710 wins / 77 draws / 953 losses).

Play against this bot as X or as O.

These bots have done best aganist dee-bot.py...

Bot P W D L Points Size From beginner One hit wonder Goldfish
Robert Seaman : : not_minimax.py (v25) 10 9 1 0 9 3501 False False True
Tom Campbell : : winblockprevent.py (v5) 10 9 0 1 8 321 False False True
Robert Howlett : : smart11.py (v1) 10 8 0 2 6 191 False False True
Jon Bannister : : anybot_r282.py (v5) 10 7 0 3 4 974 False False True
Séverin Hatt : : romuald_no_last_check.py (v1) 10 7 0 3 4 1598 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 dee-bot.py

The code

      
# This bot looks one move ahead, and if possible it will make a move to
# block its opponent winning.  Otherwise, it picks a move at random.

import copy
import random
from botany_connectfour import game

def get_next_move(board, token, move_list, state):
    available_moves = game.available_moves(board)

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

    for col in available_moves:
        board1 = copy.deepcopy(board)
        game.make_move(board1, col, other_token)
        if game.check_winner(board1) is not None:
            return col

    return next_best_move(board, move_list, available_moves)

def next_best_move(board, move_list, available_moves):
    
    last_move = next_best_move_based_on_last_move(move_list, available_moves)
    if last_move:
        return last_move
    
    if 3 in available_moves:
        return 3
    
    if 4 in available_moves:
        return 4

    if 2 in available_moves:
        return 2

    if 6 in available_moves:
        return 6
    
    if 5 in available_moves:
        return 5

    if 1 in available_moves:
        return 1
    
    return 0
    
def next_best_move_based_on_last_move(move_list, available_moves):
    last_move = get_my_last_move(move_list)
    if (last_move 
        and last_move in available_moves 
        and (last_move < 6 and (last_move + 1) in available_moves) 
        and (last_move > 0 and (last_move - 1) in available_moves)
    ):
        if ( (last_move - 1) == move_list[-1] ):
            return last_move + 1
        elif ( (last_move + 1) == move_list[-1] ):
            return last_move + 1
        else:
            possible_moves = [ last_move - 1, last_move + 1 ]
            return random.choice(possible_moves)
    else:
        return False

def get_my_last_move(move_list):
    if len(move_list) > 2:
        return move_list[-2]
    else:
        return False