boardgamers / gaia-engine

Javascript engine for project gaia
MIT License
13 stars 6 forks source link

Feds are incompleted and/or wrong. #194

Closed rzulian closed 3 years ago

rzulian commented 5 years ago

In this game the are proposed federations that are wrong, but there is one possible which is missing

nevlas federation 1x0,0x1,-1x2,-2x3,-2x4,-3x5,-2x5,-4x6 fed2.

init 2 whos_the_best
p1 faction nevlas
p2 faction bescods
nevlas build m 1x-2
bescods build m 2x0
bescods build m -1x3
nevlas build m 4x-1
bescods booster booster5
nevlas booster booster1
nevlas build ts 4x-1.
bescods charge 1pw
bescods build ts 2x0.
nevlas charge 2pw
nevlas build lab 4x-1. tech free3. up sci.
bescods charge 2pw
bescods special up-lowest. up nav.
nevlas build m 3x-3.
bescods special range+3. build m 4x2.
nevlas up sci.
bescods action power6. build m 3x3.
nevlas pass booster2
bescods build lab 2x0. tech nav. up nav.
nevlas charge 2pw
bescods special 4pw.
bescods spend 1q for 1o. build m 5x0.
nevlas charge 1pw
bescods pass booster1
nevlas income 2t
nevlas action power4.
bescods build ts 5x0.
nevlas charge 2pw
nevlas build ts 3x-3.
bescods special up-lowest. up sci.
nevlas build PI 3x-3.
bescods special 4pw.
nevlas action power5.
bescods spend 4pw for 4c. build lab 5x0. tech sci. up sci.
nevlas charge 2pw
nevlas up eco.
bescods pass booster5
nevlas up eco.
nevlas pass booster1
nevlas income 2pw. income 2pw. income 4pw
bescods special range+3. build m 4x-5.
nevlas charge 3pw
nevlas action power4.
bescods special 4pw.
nevlas action power3.
bescods action power5.
nevlas up eco.
bescods up sci.
nevlas spend 2t-a3 for 2k. up eco.
bescods special up-lowest. up eco.
nevlas action power7.
bescods pass booster6
nevlas pass booster5
nevlas income 4pw. income 4pw. income 2pw. income 2pw
bescods special 4pw.
nevlas action power4.
bescods action power3.
nevlas up nav.
bescods special up-lowest. up terra.
nevlas action power2. build m 1x0.
bescods charge 2pw
bescods build ts 4x-5.
nevlas charge 3pw
nevlas build ts 1x0.
bescods charge 2pw
bescods build lab 4x-5. tech free3. up terra.
nevlas charge 3pw
nevlas build lab 1x0. tech nav. up nav.
bescods charge 2pw
bescods up sci.
nevlas special 4pw.
bescods action power6. build m -1x1.
nevlas charge 2pw
nevlas action power1.
bescods build ts -1x1.
nevlas charge 2pw
nevlas up nav.
bescods burn 1. pass booster1
nevlas special range+3. build m -2x5.
bescods charge 1pw
nevlas build ts -2x5.
bescods charge 1pw
nevlas spend 6pw for 2o. pass booster2
nevlas income 2pw. income 4pw. income 4pw. income 2pw
bescods up terra.
nevlas action power4.
bescods action power3.
nevlas up nav.
bescods build m -2x2.
nevlas build ac2 1x0. tech free2. up terra.
bescods charge 2pw
bescods special 4pw.
nevlas action power6. build m 1x5.
bescods charge 1pw
bescods action power5.
nevlas action power2. build m -1x-3.
bescods special up-lowest. up int.
nevlas spend 4pw for 1q. build m 1x3.
bescods charge 1pw
bescods build m -3x4.
nevlas charge 2pw
nevlas burn 2. spend 4pw for 1q. build m -4x6.
bescods charge 1pw
bescods build PI 2x0.
nevlas decline 4pw
nevlas special 4pw.
bescods up terra.
nevlas special q.
bescods build m 2x5.
nevlas charge 1pw
nevlas pass booster6
bescods pass booster2
nevlas income 4pw. income 4pw. income 2pw
bescods income 4pw. income 1pw. income 1pw
nevlas action power3.
bescods federation 3x0,4x0 fed4.
nevlas burn 1. action power5.
bescods action power4.
coyotte508 commented 5 years ago

Screenshot of the missing federation:

image

coyotte508 commented 5 years ago

My guess is that the algorithm probably sees this federation instead:

image

Because it uses the same number of satellites and the new algorithm doesn't avoid new planets. Then this federation is deemed invalid (as a planet + a satellite can be dropped) and so the choice disappears altogether.

This can be fixed by showing in priority federatoins which don't touch existing planets.

Another way is by using the old algorithm for federation generation (which AVOIDS touching any other building than in the chosen combination), and apply this algorithm from checkAndGetFederationInfo:

    // Check if federation can be built with less satellites
    if (!flexible) {
      const allHexes = [...map.grid.values()].filter(hex => !excluded.has(hex));

      const workingGrid = new Grid(...allHexes.map(hex => new Hex(hex.q, hex.r)));
      const allGroups = [...this.buildingGroups(hexes.filter(hx => hx.belongsToFederationOf(this.player) || this.buildingValue(hx, {federation: true}) > 0), map).values()];
      const groups = uniq(allGroups);
      const convertedDestGroups = groups.map(destGroup => destGroup.map(hex => workingGrid.get(hex)));

      const tree = spanningTree(convertedDestGroups, workingGrid, info.satellites);

      if (tree) {
        const smallFederation = this.addAdjacentBuildings(tree.map(hex => map.grid.get(hex)), map);
        const info2 = this.federationInfo(smallFederation);
        assert(info2.satellites >= info.satellites, "The federation can be built with less satellites, for example: " + tree.join(","));
      }
    }

The downside is a sizable increase in computation time.