Improve ready task selection
This commit is contained in:
parent
c14ce042d8
commit
3c118341d3
@ -18,7 +18,7 @@ export function calcHeroResource(requirements: ReadonlyArray<Resources>): HeroRe
|
|||||||
|
|
||||||
function getFirstRequirement(requirements: ReadonlyArray<Resources>): Resources {
|
function getFirstRequirement(requirements: ReadonlyArray<Resources>): Resources {
|
||||||
for (let required of requirements) {
|
for (let required of requirements) {
|
||||||
if (required.lt(Resources.zero())) {
|
if (required.anyLower(Resources.zero())) {
|
||||||
return required;
|
return required;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,14 +85,20 @@ export class Resources implements ResourcesInterface {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
lt(other: ResourcesInterface): boolean {
|
anyLower(other: ResourcesInterface): boolean {
|
||||||
return this.lumber < other.lumber || this.clay < other.clay || this.iron < other.iron || this.crop < other.crop;
|
return this.lumber < other.lumber || this.clay < other.clay || this.iron < other.iron || this.crop < other.crop;
|
||||||
}
|
}
|
||||||
|
|
||||||
gt(other: ResourcesInterface): boolean {
|
allGreater(other: ResourcesInterface): boolean {
|
||||||
return this.lumber > other.lumber && this.clay > other.clay && this.iron > other.iron && this.crop > other.crop;
|
return this.lumber > other.lumber && this.clay > other.clay && this.iron > other.iron && this.crop > other.crop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
allGreaterOrEqual(other: ResourcesInterface): boolean {
|
||||||
|
return (
|
||||||
|
this.lumber >= other.lumber && this.clay >= other.clay && this.iron >= other.iron && this.crop >= other.crop
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
min(other: ResourcesInterface): Resources {
|
min(other: ResourcesInterface): Resources {
|
||||||
return new Resources(
|
return new Resources(
|
||||||
Math.min(this.lumber, other.lumber),
|
Math.min(this.lumber, other.lumber),
|
||||||
|
@ -83,7 +83,11 @@ export class VillageTaskCollection {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _.first(firstReadyGroup.tasks);
|
const maxCapacity = Resources.fromStorage(this.storage.getResourceStorage());
|
||||||
|
|
||||||
|
return firstReadyGroup.tasks.find(
|
||||||
|
t => !t.args.resources || maxCapacity.allGreaterOrEqual(Resources.fromObject(t.args.resources))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
postponeTask(taskId: TaskId, seconds: number) {
|
postponeTask(taskId: TaskId, seconds: number) {
|
||||||
|
@ -7,25 +7,25 @@ describe('Resources', function() {
|
|||||||
it('Can compare with lt', function() {
|
it('Can compare with lt', function() {
|
||||||
const x = new Resources(0, 0, 0, 0);
|
const x = new Resources(0, 0, 0, 0);
|
||||||
const y = new Resources(5, 5, 5, 5);
|
const y = new Resources(5, 5, 5, 5);
|
||||||
expect(x.lt(y)).is.true;
|
expect(x.anyLower(y)).is.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Can compare with lt (mixed)', function() {
|
it('Can compare with lt (mixed)', function() {
|
||||||
const x = new Resources(20, 20, 5, 20);
|
const x = new Resources(20, 20, 5, 20);
|
||||||
const y = new Resources(10, 10, 10, 10);
|
const y = new Resources(10, 10, 10, 10);
|
||||||
expect(x.lt(y)).is.true;
|
expect(x.anyLower(y)).is.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Can compare with gt', function() {
|
it('Can compare with gt', function() {
|
||||||
const x = new Resources(5, 5, 5, 5);
|
const x = new Resources(5, 5, 5, 5);
|
||||||
const y = new Resources(0, 0, 0, 0);
|
const y = new Resources(0, 0, 0, 0);
|
||||||
expect(x.gt(y)).is.true;
|
expect(x.allGreater(y)).is.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Can compare with gt (mixed)', function() {
|
it('Can compare with gt (mixed)', function() {
|
||||||
const x = new Resources(30, 30, 10, 30);
|
const x = new Resources(30, 30, 10, 30);
|
||||||
const y = new Resources(20, 20, 20, 20);
|
const y = new Resources(20, 20, 20, 20);
|
||||||
expect(x.gt(y)).is.false;
|
expect(x.allGreater(y)).is.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Can up to 1', function() {
|
it('Can up to 1', function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user