A
A
Alecxandrys2017-03-14 10:36:14
JavaScript
Alecxandrys, 2017-03-14 10:36:14

How to approach the implementation of this mechanism?

Good afternoon,
There is an array of objects created using a similar constructor:

function Squad(options)
{
    this.name=options.name || 'Unnamed';
    this.description=options.description || "This is one of unidentified warrior";

    this.commander=options.commander || false;
    this.cost=options.cost || 0;
    this.rules=options.rules || null;

    this.weaponSkill=options.weaponSkill || 0;
    this.ballisticSkill=options.ballisticSkill || 0;
    this.strength=options.strength || 0;
    this.toughness=options.toughness || 0;
    this.initiative=options.initiative || 0;
    this.speed=options.speed || 0;
    this.wound=options.wound || 0;
    this.attackCount=options.attackCount || 0;
    this.leadership=options.leadership || 0;
    this.armorSave=options.armorSave || 0;

    this.invulnerable=options.invulnerable|| 7;

    this.availableWeapon=options.availableWeapon || null;
    this.meleeWeapon=null;
    this.rangeWeapon=null;
}

Accordingly, there is an array of these units, each with its own characteristics, rules and price, as well as weapons that will be taken from the list available.
The question is how to write an algorithm that will form an assembly according to certain rules that can be set.
Something similar can be done with a knowledge base, but there are restrictions on the language and I'm not sure that the task is fully covered.
How to approach the solution of the problem, what tools can be used?
PS
For example:
now the array has 3 types of units: scout (only light weapons and ranged, cheap and fast), tactical (power armor, slightly slower, melee and ranged combat, weapon variability) and devastators (slightly more expensive than tactical, slightly slower than it, spectrum weapons are almost like hers, but they use them more efficiently, they don’t know how to close combat).
Let's assume that the price of the entire army is limited to 100 points. That price is 8 Scouts, 5 Tacticals, or 4 Devastators, all with basic weapons. Accordingly, by setting the rules, I would like to determine that for a given price it is necessary to select an army with maximum firepower at maximum range (for example). or the maximum in size, or which can take the maximum units of additional heavy weapons

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Interface, 2017-03-14
@Alecxandrys

Very similar to the backpack problem: https://en.wikipedia.org/wiki/%D0%97%D0%B0%D0%B4%D...

K
Kovalsky, 2017-12-25
@vita_yy

The delete operator exists to remove the properties of an object; your example only works because you don't use the keywords (var, let) to declare the test variable , and so it becomes a property of the window object .
"delete deletes a variable" is of course not true, delete does not delete variables, except that by variables you mean such cases: variables declared without keywords, that is, window properties .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question