<commit_before>/*
 * FXGL - JavaFX Game Library. The MIT License (MIT).
 * Copyright (c) AlmasB (<EMAIL>).
 * See LICENSE for details.
 */

package com.almasb.fxgl.ai.btree;

import com.almasb.fxgl.core.collection.Array;

/**
 * The behavior tree itself.
 *
 * @param <E> type of the blackboard object that tasks use to read or modify game state
 * @author implicit-invocation
 * @author davebaol
 */
public class BehaviorTree<E> extends Task<E> {

    private Task<E> rootTask;
    private E object;
    GuardEvaluator<E> guardEvaluator;

    private final Array<Listener<E>> listeners = new Array<>();

    /**
     * Note: this is needed for no-arg constructions.
     *
     * Creates a {@code BehaviorTree} with no root task and no blackboard object. Both the root task and the blackboard object must
     * be set before running this behavior tree, see {@link #addChild(Task) addChild()} and {@link #setEntity(Object) setObject()}
     * respectively.
     */
    public BehaviorTree() {
        this(null, null);
    }

    /**
     * Creates a behavior tree with a root task and no blackboard object. Both the root task and the blackboard object must be set
     * before running this behavior tree, see {@link #addChild(Task) addChild()} and {@link #setEntity(Object) setObject()}
     * respectively.
     *
     * @param rootTask the root task of this tree. It can be {@code null}.
     */
    public BehaviorTree(Task<E> rootTask) {
        this(rootTask, null);
    }

    /**
     * Creates a behavior tree with a root task and a blackboard object. Both the root task and the blackboard object must be set
     * before running this behavior tree, see {@link #addChild(Task) addChild()} and {@link #setEntity(Object) setObject()}
     * respectively.
     *
     * @param rootTask the root task of this tree. It can be {@code null}.
     * @param object   the blackboard. It can be {@code null}.
     */
    public BehaviorTree(Task<E> rootTask, E object) {
        this.rootTask = rootTask;
        this.object = object;
        this.tree = this;
        this.guardEvaluator = new GuardEvaluator<E>(this);
    }

    /**
     * Returns the blackboard object of this behavior tree.
     */
    @Override
    public E getEntity() {
        return object;
    }

    /**
     * Sets the blackboard object of this behavior tree.
     *
     * @param object the new blackboard
     */
    public void setEntity(E object) {
        this.object = object;
    }
<commit_msg>renamed blackboard object to entity<commit_after>/*
 * FXGL - JavaFX Game Library. The MIT License (MIT).
 * Copyright (c) AlmasB (<EMAIL>).
 * See LICENSE for details.
 */

package com.almasb.fxgl.ai.btree;

import com.almasb.fxgl.core.collection.Array;

/**
 * The behavior tree itself.
 *
 * @param <E> type of the blackboard object that tasks use to read or modify game state
 * @author implicit-invocation
 * @author davebaol
 */
public class BehaviorTree<E> extends Task<E> {

    private Task<E> rootTask;
    private E entity;
    GuardEvaluator<E> guardEvaluator;

    private final Array<Listener<E>> listeners = new Array<>();

    /**
     * Note: this is needed for no-arg constructions.
     *
     * Creates a {@code BehaviorTree} with no root task and no blackboard object. Both the root task and the blackboard object must
     * be set before running this behavior tree, see {@link #addChild(Task) addChild()} and {@link #setEntity(Object) setObject()}
     * respectively.
     */
    public BehaviorTree() {
        this(null, null);
    }

    /**
     * Creates a behavior tree with a root task and no blackboard object. Both the root task and the blackboard object must be set
     * before running this behavior tree, see {@link #addChild(Task) addChild()} and {@link #setEntity(Object) setObject()}
     * respectively.
     *
     * @param rootTask the root task of this tree. It can be {@code null}.
     */
    public BehaviorTree(Task<E> rootTask) {
        this(rootTask, null);
    }

    /**
     * Creates a behavior tree with a root task and a blackboard object. Both the root task and the blackboard object must be set
     * before running this behavior tree, see {@link #addChild(Task) addChild()} and {@link #setEntity(Object) setObject()}
     * respectively.
     *
     * @param rootTask the root task of this tree. It can be {@code null}.
     * @param entity   the blackboard. It can be {@code null}.
     */
    public BehaviorTree(Task<E> rootTask, E entity) {
        this.rootTask = rootTask;
        this.entity = entity;
        this.tree = this;
        this.guardEvaluator = new GuardEvaluator<E>(this);
    }

    /**
     * Returns the blackboard object of this behavior tree.
     */
    @Override
    public E getEntity() {
        return entity;
    }

    /**
     * Sets the blackboard object of this behavior tree.
     *
     * @param object the new blackboard
     */
    public void setEntity(E object) {
        this.entity = object;
    }

{'fraction_non_alphanumeric': 0.10272873194221509, 'fraction_numerical': 0.0, 'mean_word_length': 2.6844050258684407, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7488148', 'n_tokens_mistral': 1441, 'n_tokens_neox': 1420, 'n_words': 550}