forked from RepoMirrors/baritone
cleanup and combine single parent priority allocation
This commit is contained in:
parent
9642950b54
commit
e7a09c34ea
|
@ -17,7 +17,7 @@
|
|||
|
||||
package tenor;
|
||||
|
||||
public interface IQuantizedParentTaskRelationship<T extends ITask> extends ITaskRelationshipBase<QuantizedTaskNode, T>, IParentTaskRelationship {
|
||||
public interface IQuantizedParentTaskRelationship<T extends ITask> extends ITaskRelationshipBase<IQuantizedTaskNode, T>, IParentTaskRelationship {
|
||||
|
||||
IQuantityRelationship cost();
|
||||
}
|
||||
|
|
|
@ -22,5 +22,27 @@ package tenor;
|
|||
* @since 10/30/2018
|
||||
*/
|
||||
public interface IQuantizedTaskNode extends ITaskNodeBase<IQuantizedChildTaskRelationship, IQuantizedParentTaskRelationship>, IQuantizedTask {
|
||||
// if the child task were able to provide this amount, how much priority would that be?
|
||||
double priorityAllocatedTo(IQuantizedParentTaskRelationship child, int quantity);
|
||||
|
||||
default int quantityExecutingInto(QuantizedToSingularTaskRelationship child) {
|
||||
if (type() != DependencyType.SERIAL) {
|
||||
throw new UnsupportedOperationException(this + " " + child);
|
||||
}
|
||||
// need to calculate from scratch
|
||||
int ind = childTasks().indexOf(child);
|
||||
if (ind <= 0) {
|
||||
throw new IllegalStateException(childTasks() + "");
|
||||
}
|
||||
int minQuantity = -1;
|
||||
for (int i = 0; i < childTasks().indexOf(child); i++) {
|
||||
IQuantizedChildTaskRelationship relationship = (IQuantizedChildTaskRelationship) childTasks().get(i);
|
||||
IClaimProvider claim = (IClaimProvider) relationship.childTask();
|
||||
int amt = claim.quantityCompletedForParent(relationship);
|
||||
if (minQuantity == -1 || amt < minQuantity) {
|
||||
minQuantity = amt;
|
||||
}
|
||||
}
|
||||
return minQuantity;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package tenor;
|
||||
|
||||
public interface ISingleParentPriorityAllocator extends IQuantizedTask {
|
||||
@Override
|
||||
default IQuantityRelationship priority() {
|
||||
if (parentTasks().size() != 1) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return parentTasks().get(0)::allocatedPriority;
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
package tenor;
|
||||
|
||||
public interface ISingularParentTaskRelationship<T extends ITask> extends ITaskRelationshipBase<SingularTaskNode, T>, IParentTaskRelationship {
|
||||
public interface ISingularParentTaskRelationship<T extends ITask> extends ITaskRelationshipBase<ISingularTaskNode, T>, IParentTaskRelationship {
|
||||
|
||||
double cost();
|
||||
}
|
||||
|
|
|
@ -17,33 +17,9 @@
|
|||
|
||||
package tenor;
|
||||
|
||||
public abstract class QuantizedTaskNode extends TaskNode<IQuantizedChildTaskRelationship, IQuantizedParentTaskRelationship> implements IQuantizedTask {
|
||||
public abstract class QuantizedTaskNode extends TaskNode<IQuantizedChildTaskRelationship, IQuantizedParentTaskRelationship> implements IQuantizedTaskNode {
|
||||
|
||||
public QuantizedTaskNode(DependencyType type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
// if the child task were able to provide this amount, how much priority would that be?
|
||||
public abstract double priorityAllocatedTo(IQuantizedParentTaskRelationship child, int quantity);
|
||||
|
||||
public int quantityExecutingInto(QuantizedToSingularTaskRelationship child) {
|
||||
if (type() != DependencyType.SERIAL) {
|
||||
throw new UnsupportedOperationException(this + " " + child);
|
||||
}
|
||||
// need to calculate from scratch
|
||||
int ind = childTasks().indexOf(child);
|
||||
if (ind <= 0) {
|
||||
throw new IllegalStateException(childTasks() + "");
|
||||
}
|
||||
int minQuantity = -1;
|
||||
for (int i = 0; i < childTasks().indexOf(child); i++) {
|
||||
IQuantizedChildTaskRelationship relationship = (IQuantizedChildTaskRelationship) childTasks().get(i);
|
||||
IClaimProvider claim = (IClaimProvider) relationship.childTask();
|
||||
int amt = claim.quantityCompletedForParent(relationship);
|
||||
if (minQuantity == -1 || amt < minQuantity) {
|
||||
minQuantity = amt;
|
||||
}
|
||||
}
|
||||
return minQuantity;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,10 +18,10 @@
|
|||
package tenor;
|
||||
|
||||
public class QuantizedToQuantizedTaskRelationship
|
||||
extends TaskRelationship<QuantizedTaskNode, IQuantizedTask>
|
||||
implements IQuantizedChildTaskRelationship<QuantizedTaskNode>, IQuantizedParentTaskRelationship<IQuantizedTask> {
|
||||
extends TaskRelationship<IQuantizedTaskNode, IQuantizedTask>
|
||||
implements IQuantizedChildTaskRelationship<IQuantizedTaskNode>, IQuantizedParentTaskRelationship<IQuantizedTask> {
|
||||
|
||||
public QuantizedToQuantizedTaskRelationship(QuantizedTaskNode parent, IQuantizedTask child, DependencyType type) {
|
||||
public QuantizedToQuantizedTaskRelationship(IQuantizedTaskNode parent, IQuantizedTask child, DependencyType type) {
|
||||
super(parent, child, type);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,10 +18,10 @@
|
|||
package tenor;
|
||||
|
||||
public class QuantizedToSingularTaskRelationship
|
||||
extends TaskRelationship<QuantizedTaskNode, ISingularTask>
|
||||
implements ISingularChildTaskRelationship<QuantizedTaskNode>, IQuantizedParentTaskRelationship<ISingularTask> {
|
||||
extends TaskRelationship<IQuantizedTaskNode, ISingularTask>
|
||||
implements ISingularChildTaskRelationship<IQuantizedTaskNode>, IQuantizedParentTaskRelationship<ISingularTask> {
|
||||
|
||||
public QuantizedToSingularTaskRelationship(QuantizedTaskNode parent, ISingularTask child, DependencyType type) {
|
||||
public QuantizedToSingularTaskRelationship(IQuantizedTaskNode parent, ISingularTask child, DependencyType type) {
|
||||
super(parent, child, type);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,12 +18,12 @@
|
|||
package tenor;
|
||||
|
||||
public class SingularToQuantizedTaskRelationship
|
||||
extends TaskRelationship<SingularTaskNode, IQuantizedTask>
|
||||
implements IQuantizedChildTaskRelationship<SingularTaskNode>, ISingularParentTaskRelationship<IQuantizedTask> {
|
||||
extends TaskRelationship<ISingularTaskNode, IQuantizedTask>
|
||||
implements IQuantizedChildTaskRelationship<ISingularTaskNode>, ISingularParentTaskRelationship<IQuantizedTask> {
|
||||
|
||||
public int quantityRequired;
|
||||
|
||||
public SingularToQuantizedTaskRelationship(SingularTaskNode parent, IQuantizedTask child, DependencyType type, int quantityRequired) {
|
||||
public SingularToQuantizedTaskRelationship(ISingularTaskNode parent, IQuantizedTask child, DependencyType type, int quantityRequired) {
|
||||
super(parent, child, type);
|
||||
this.quantityRequired = quantityRequired;
|
||||
}
|
||||
|
|
|
@ -18,10 +18,10 @@
|
|||
package tenor;
|
||||
|
||||
public class SingularToSingularTaskRelationship
|
||||
extends TaskRelationship<SingularTaskNode, ISingularTask>
|
||||
implements ISingularChildTaskRelationship<SingularTaskNode>, ISingularParentTaskRelationship<ISingularTask> {
|
||||
extends TaskRelationship<ISingularTaskNode, ISingularTask>
|
||||
implements ISingularChildTaskRelationship<ISingularTaskNode>, ISingularParentTaskRelationship<ISingularTask> {
|
||||
|
||||
public SingularToSingularTaskRelationship(SingularTaskNode parent, ISingularTask child, DependencyType type) {
|
||||
public SingularToSingularTaskRelationship(ISingularTaskNode parent, ISingularTask child, DependencyType type) {
|
||||
super(parent, child, type);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ package tenor.game;
|
|||
|
||||
import tenor.*;
|
||||
|
||||
public class AquireCraftingItems extends QuantizedTaskNode implements IClaimProvider {
|
||||
public class AquireCraftingItems extends QuantizedTaskNode implements IClaimProvider, ISingleParentPriorityAllocator {
|
||||
|
||||
final CraftingTask parent;
|
||||
|
||||
|
@ -41,11 +41,6 @@ public class AquireCraftingItems extends QuantizedTaskNode implements IClaimProv
|
|||
return priority().value(actualQuantity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQuantityRelationship priority() {
|
||||
return parentTasks().get(0)::allocatedPriority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQuantityRelationship cost() {
|
||||
return x -> {
|
||||
|
|
|
@ -18,14 +18,11 @@
|
|||
package tenor.game;
|
||||
|
||||
import net.minecraft.util.Tuple;
|
||||
import tenor.DependencyType;
|
||||
import tenor.IQuantityRelationship;
|
||||
import tenor.IQuantizedParentTaskRelationship;
|
||||
import tenor.QuantizedTaskNode;
|
||||
import tenor.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CraftingTask extends QuantizedTaskNode {
|
||||
public class CraftingTask extends QuantizedTaskNode implements ISingleParentPriorityAllocator {
|
||||
|
||||
int outputQuantity;
|
||||
List<Tuple<AquireItemTask, Integer>> recipe;
|
||||
|
@ -52,14 +49,10 @@ public class CraftingTask extends QuantizedTaskNode {
|
|||
public IQuantityRelationship cost() {
|
||||
return x -> {
|
||||
int actualQuantity = (int) Math.ceil(x * 1.0D / outputQuantity);
|
||||
return inputs.cost().value(actualQuantity);
|
||||
return inputs.cost().value(actualQuantity) + step2.cost() + step3.cost();
|
||||
};
|
||||
}
|
||||
|
||||
public IQuantityRelationship priority() {
|
||||
return parentTasks().get(0)::allocatedPriority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double priorityAllocatedTo(IQuantizedParentTaskRelationship child, int quantity) {
|
||||
// how much priority would we give this child if they could provide us this quantity?
|
||||
|
|
|
@ -18,16 +18,20 @@
|
|||
package tenor.game;
|
||||
|
||||
import tenor.IQuantityRelationship;
|
||||
import tenor.ISingleParentPriorityAllocator;
|
||||
import tenor.QuantizedTaskLeaf;
|
||||
|
||||
public class MineTask extends QuantizedTaskLeaf {
|
||||
@Override
|
||||
public IQuantityRelationship priority() {
|
||||
return null;
|
||||
public class MineTask extends QuantizedTaskLeaf implements ISingleParentPriorityAllocator {
|
||||
|
||||
final AquireItemTask parent;
|
||||
|
||||
public MineTask(AquireItemTask parent) {
|
||||
this.parent = parent;
|
||||
addParent(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQuantityRelationship cost() {
|
||||
return null;
|
||||
return x -> x * 324232;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue