@gamepark/rules-api
Version:
API to implement the rules of a board game
21 lines • 681 B
JavaScript
/**
* This strategy attributes the first gap in a sequence, and leaves a gap when an item is removed.
* Use for river-type mechanisms for instance.
*/
export class FillGapStrategy {
axis;
constructor(axis = 'x') {
this.axis = axis;
}
addItem(material, item) {
if (item.location[this.axis] === undefined) {
const items = material.sort(item => item.location[this.axis]).getItems();
let position = 0;
while (items[position]?.location[this.axis] === position) {
position++;
}
item.location[this.axis] = position;
}
}
}
//# sourceMappingURL=FillGapStrategy.js.map