예제 #1
0
파일: ais.py 프로젝트: asosnovsky/quarto
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
예제 #2
0
파일: ais.py 프로젝트: asosnovsky/quarto
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