Example #1
0
def ai_2(board: BoardState) -> BoardState:
    """This AI will always give a none-winable piece (if there is one) and will place randomly
    """
    cur_piece = board.cpiece
    if cur_piece is None:
        board.cpiece_id = choose_none_winable_piece(board)
    else:
        board[choice(list(board.open_spots))] = board.cpiece_id
        board.cpiece_id = choose_none_winable_piece(board)

    if (board.cpiece_id is None) and not board.is_full:
        board.cpiece_id, _ = choice(list(board.unused_game_pieces))
    return board
Example #2
0
def ai_3(board: BoardState) -> BoardState:
    """This AI will always give a none-winable piece (if there is one) and will only choose winable placements when possible
    """
    cur_piece = board.cpiece
    if cur_piece is not None:
        moved = False
        for (x, y) in board.open_spots:
            move = find_win_spot(cur_piece, board)
            if move:
                board[move] = board.cpiece_id
                moved = True
                break
        if not moved:
            board[choice(list(board.open_spots))] = board.cpiece_id
        board.cpiece_id = choose_none_winable_piece(board)
    else:
        board.cpiece_id = choose_none_winable_piece(board)

    if (board.cpiece_id is None) and not board.is_full:
        board.cpiece_id, _ = choice(list(board.unused_game_pieces))
    return board