Пример #1
0
 public CutTree(int rectLength, int rectWidth, TypeOfCell kind, int index, DirectionOfCut dir, CutTree left, CutTree right)
 {
     this.Length = rectLength; this.Width = rectWidth; this.IndexOfPieceOrValueOfCut = index;
     this.Kind   = kind; this.CutDirection = dir;
     this.Left   = left;
     this.Right  = right;
 }
Пример #2
0
        private T _question(int from, int to, CutTree <T> node)
        {
            if (node.To == to && node.From == from)
            {
                return(node.Value);
            }

            bool goesLeft  = node.Left != null && from <= node.Left.To;
            bool goesRight = node.Right != null && to >= node.Right.From;

            T leftBranch  = default(T);
            T rightBranch = default(T);

            if (goesLeft)
            {
                leftBranch = _question(from, Math.Min(node.Left.To, to), node.Left);
            }
            if (goesRight)
            {
                rightBranch = _question(Math.Max(node.Right.From, from), to, node.Right);
            }

            if (goesLeft && !goesRight)
            {
                return(leftBranch);
            }
            if (!goesLeft && goesRight)
            {
                return(rightBranch);
            }

            return(leftBranch.MaxOfTwo(rightBranch));
        }
Пример #3
0
 public RangeMaxQueryTree(IList <T> source)
 {
     _tree = CutTree <T> .Build <T>(
         source,
         0, source.Count - 1,
         maxfunction
         );
 }
Пример #4
0
 internal CutTree(int rectLength, int rectWidth, SolutionCell cell, CutTree left, CutTree right)
 {
     this.Length = rectLength;
     this.Width  = rectWidth;
     this.Kind   = cell.Type;
     this.IndexOfPieceOrValueOfCut = cell.Index;
     this.CutDirection             = cell.DirOfCut;
     this.Left  = left;
     this.Right = right;
 }
Пример #5
0
 private void OnTriggerStay(Collider other)
 {
     if (r.toolsManagerScript.HasChildren() == false)
     {
         if (other.CompareTag("Trees"))
         {
             if (Input.GetButton("Fire1") && time > lastAttack)
             {
                 time = 0;
                 CutTree ct = other.GetComponent <CutTree>();
                 ct.Durability -= handDmg;
                 r.vitals.subtractHP(selfHarm);
                 GetComponent <AudioSource>().Play();
             }
         }
     }
 }
Пример #6
0
 public static Item CreateTreeLoot(CutTree.TreeType treeType,int amount)
 {
     Item Log = new Item();
     if (treeType == CutTree.TreeType.Oak)
     {
         Log.Name = "Oak Log";
         Log.Stackable = true;
         Log.ItemsInStack = amount;
         return Log;
     }
     else
     {
         Log.Name = "Oak Log";
         Log.Stackable = true;
         Log.ItemsInStack = amount;
         return Log;
     }
 }
Пример #7
0
        private void ShowSolution()
        {
            if (solution != null)
            {
                pieceDrawings.Clear();
                wasteDrawings.Clear();
                cutDrawings.Clear();

                textBox_PatternRep.Text    = solution[actual_solution_index].timesRepeated.ToString();
                textBox_cur_pattern.Text   = (actual_solution_index + 1).ToString() + "/" + solution.Length;
                button_prevPattern.Enabled = actual_solution_index > 0;
                button_nextPattern.Enabled = actual_solution_index < solution.Length - 1;
                CutTree tree = solution[actual_solution_index].cuts;
                CheckRootSize(tree);
                PaintCutPattern((0, 0), tree);
                pictureBox_sol.Refresh();
                ShowPieceCount();
            }
        }
Пример #8
0
        private void CheckRootSize(CutTree tree)
        {
            float verticalLength = 0;

            if (tree.Length < stockLength)
            {
                float verticalWidth = pictureBox_sol.Height;
                verticalLength = GetRelativeLength(stockLength - tree.Length);
                (float, float)verticalPoint = (GetRelativeLength(tree.Length), 0);

                wasteDrawings.Add(new WasteDrawing(verticalPoint, verticalLength, verticalWidth));
            }

            if (tree.Width < stockWidth)
            {
                float horizontalWidth  = GetRelativeWidth(stockWidth - tree.Width);
                float horizontalLength = pictureBox_sol.Width - verticalLength;
                (float, float)horizontalPoint = (0, GetRelativeWidth(tree.Width));

                wasteDrawings.Add(new WasteDrawing(horizontalPoint, horizontalLength, horizontalWidth));
            }
        }
    protected void Awake()
    {
        ttm = GetComponent <TargetTrackingManager>();
        base.Awake();

        actions = new List <Action>();
        startWS = new Ws();
        //set the worlds states for the start of the game
        startWS.SetVal(Wstates.KnowledgeOfTree, true);
        startWS.SetVal(Wstates.KnowledgeOfNails, true);
        startWS.SetVal(Wstates.KnowledgeOfHouse, true);
        startWS.SetVal(Wstates.KnowledgeOfTent, true);
        startWS.SetVal(Wstates.KnowledgeOfWeapon, true);


        // creating all of the actions that the AI will need to complete its neccassary goal. each action will be initilised with the name, cost, object and type of action.
        //Along with its preconditions and effects to the world state.

        //Action being created
        Action GetWood = new GetWood("GetWood", 1, this, TacticalStates.Goto);

        GetWood.SetPreCondition(Wstates.KnowledgeOfTree, true);
        GetWood.SetEffect(Wstates.LocatedAtTree, true);
        GetWood.destination = GameObject.FindGameObjectWithTag("Tree").transform;
        actions.Add(GetWood);
        //Action being created
        Action CutTree = new CutTree("CutTree", 1, this, TacticalStates.Goto);

        CutTree.SetPreCondition(Wstates.KnowledgeOfTree, true);
        CutTree.SetPreCondition(Wstates.LocatedAtTree, true);
        CutTree.SetEffect(Wstates.HasWood, true);
        CutTree.destination = GameObject.FindGameObjectWithTag("Tree").transform;
        actions.Add(CutTree);
        //Action being created
        Action getNails = new GetNails("GoToNails", 1, this, TacticalStates.Goto);

        getNails.SetPreCondition(Wstates.HasWood, true);
        getNails.SetPreCondition(Wstates.KnowledgeOfNails, true);
        getNails.SetEffect(Wstates.LocatedAtNails, true);
        getNails.destination = GameObject.FindGameObjectWithTag("Nails").transform;
        actions.Add(getNails);
        //Action being created
        Action pickUpNails = new PickupNails("Getting nails", 1, this, TacticalStates.Goto);

        pickUpNails.SetPreCondition(Wstates.KnowledgeOfNails, true);
        pickUpNails.SetPreCondition(Wstates.LocatedAtNails, true);
        pickUpNails.SetEffect(Wstates.HasNails, true);
        pickUpNails.destination = GameObject.FindGameObjectWithTag("Nails").transform;
        actions.Add(pickUpNails);
        //Action being created
        Action goHouse = new GoHouse("GoTo House", 1, this, TacticalStates.Goto);

        goHouse.SetPreCondition(Wstates.KnowledgeOfHouse, true);
        goHouse.SetPreCondition(Wstates.HasNails, true);
        goHouse.SetPreCondition(Wstates.HasWood, true);
        goHouse.SetEffect(Wstates.LocatedAtHouse, true);
        goHouse.destination = GameObject.FindGameObjectWithTag("house").transform;
        actions.Add(goHouse);
        //Action being created
        Action BuildHouse = new buildHouse("Build house", 1, this, TacticalStates.Goto);

        goHouse.SetPreCondition(Wstates.KnowledgeOfHouse, true);
        BuildHouse.SetPreCondition(Wstates.HasNails, true);
        BuildHouse.SetPreCondition(Wstates.HasWood, true);
        BuildHouse.SetPreCondition(Wstates.LocatedAtHouse, true);
        BuildHouse.SetEffect(Wstates.HouseIsBuilt, true);
        BuildHouse.destination = GameObject.FindGameObjectWithTag("house").transform;
        actions.Add(BuildHouse);
        //Action being created
        Action GoToTent = new GoToTent("Tent", 1, this, TacticalStates.Goto);

        GoToTent.SetPreCondition(Wstates.KnowledgeOfTent, true);
        GoToTent.SetPreCondition(Wstates.HouseIsBuilt, true);
        GoToTent.SetEffect(Wstates.LocatedAtTent, true);
        GoToTent.destination = GameObject.FindGameObjectWithTag("Tent").transform;
        actions.Add(GoToTent);
        //Action being created
        Action GoToWeapon = new GetWeapon("Weapon", 1, this, TacticalStates.Goto);

        GoToWeapon.SetPreCondition(Wstates.KnowledgeOfWeapon, true);
        GoToWeapon.SetPreCondition(Wstates.CanSeeBear, true);
        GoToWeapon.SetEffect(Wstates.HasWeapon, true);
        GoToWeapon.destination = GameObject.FindGameObjectWithTag("Weapon").transform;
        actions.Add(GoToWeapon);
        //Action being created
        Action GoBear = new GoToBear("GoBear", 1, this, TacticalStates.Goto);

        GoBear.SetPreCondition(Wstates.HasWeapon, true);
        GoBear.SetPreCondition(Wstates.CanSeeBear, true);
        GoBear.SetEffect(Wstates.LocatedAtBear, true);
        GoBear.destination = GameObject.FindGameObjectWithTag("Bear").transform;
        actions.Add(GoBear);
        //Action being created
        Action killBear = new KillBear("killing", 1, this, TacticalStates.Goto);

        killBear.SetPreCondition(Wstates.CanSeeBear, true);
        killBear.SetPreCondition(Wstates.LocatedAtBear, true);
        killBear.SetEffect(Wstates.BearDead, true);
        actions.Add(killBear);

        goals = new List <Goal>();

        //creating the goals for the AI, each goal will be initilised with a priotity and the world state conditions that will need to be met, for the AI to complete the goal
        //Goal being created
        Goal BuildGoal = new Goal(10);

        BuildGoal.condition.SetVal(Wstates.LocatedAtTree, true);
        BuildGoal.condition.SetVal(Wstates.HasWood, true);
        BuildGoal.condition.SetVal(Wstates.LocatedAtNails, true);
        BuildGoal.condition.SetVal(Wstates.HasNails, true);
        BuildGoal.condition.SetVal(Wstates.LocatedAtHouse, true);
        BuildGoal.condition.SetVal(Wstates.HouseIsBuilt, true);
        BuildGoal.condition.SetVal(Wstates.LocatedAtTent, true);
        goals.Add(BuildGoal);
        //Goal being created
        Goal KillBear = new Goal(9);

        KillBear.condition.SetVal(Wstates.CanSeeBear, true);
        KillBear.condition.SetVal(Wstates.HasWeapon, true);
        KillBear.condition.SetVal(Wstates.BearDead, true);
        goals.Add(KillBear);



        // Build the Finite State Machine
        tacticalStateMachine = new FSM <TacticalStates>(displayFSMTransitions);
        tacticalStateMachine.AddState(new Goto <TacticalStates>(TacticalStates.Goto, this, 0f));
        tacticalStateMachine.AddState(new Animate <TacticalStates>(TacticalStates.Animate, this, 0f));
        tacticalStateMachine.AddState(new UseSmartObject <TacticalStates>(TacticalStates.UseSmartObject, this, 0f));

        tacticalStateMachine.AddTransition(TacticalStates.Goto, TacticalStates.Animate);
        tacticalStateMachine.AddTransition(TacticalStates.Goto, TacticalStates.UseSmartObject);
        tacticalStateMachine.AddTransition(TacticalStates.Goto, TacticalStates.Goto);
        tacticalStateMachine.AddTransition(TacticalStates.Animate, TacticalStates.Goto);
        tacticalStateMachine.AddTransition(TacticalStates.Animate, TacticalStates.UseSmartObject);
        tacticalStateMachine.AddTransition(TacticalStates.Animate, TacticalStates.Animate);
        tacticalStateMachine.AddTransition(TacticalStates.UseSmartObject, TacticalStates.Goto);
        tacticalStateMachine.AddTransition(TacticalStates.UseSmartObject, TacticalStates.Animate);
        tacticalStateMachine.AddTransition(TacticalStates.UseSmartObject, TacticalStates.UseSmartObject);
    }
Пример #10
0
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     cutTree           = animator.GetComponent <CutTree>();
     cutTree.isCutting = true;
 }
Пример #11
0
 internal void SetCutsTree(CutTree tree)
 {
     this.cuts = tree;
 }