MCPcopy
hub / github.com/FreezingMoon/AncientBeast / chooseHexForCurrentQuery

Method chooseHexForCurrentQuery

src/bot.ts:642–705  ·  view source on GitHub ↗
(hexes: Hex[])

Source from the content-addressed store, hash-verified

640 }
641
642 chooseHexForCurrentQuery(hexes: Hex[]) {
643 const activeCreature = this.game.activeCreature;
644 const action = this.pendingAction;
645 if (!activeCreature || !action) {
646 return undefined;
647 }
648
649 const candidates = this.getUniqueHexes(hexes).filter(Boolean);
650 if (candidates.length === 0) {
651 return undefined;
652 }
653
654 if (action.type === 'move') {
655 const filtered = candidates.filter(
656 (hex) => !(hex.x === activeCreature.x && hex.y === activeCreature.y),
657 );
658 const retreating = this.isRetreating(activeCreature);
659 const scored = filtered
660 .map((hex) => ({
661 hex,
662 score: this.scoreMoveHex(hex),
663 trapPenalty: this.getMovePathTrapPenalty(activeCreature, hex, { retreating }),
664 }))
665 .sort((left, right) => right.score - left.score);
666
667 const best = scored[0];
668 if (!best) {
669 return undefined;
670 }
671
672 if (this.shouldWaitInsteadOfRiskyMove(activeCreature, best, scored)) {
673 return undefined;
674 }
675
676 return best.hex;
677 }
678
679 if (action.type === 'summon') {
680 return this.pickBestHex(candidates, (hex) => this.scoreSummonHex(hex));
681 }
682
683 const scored = candidates
684 .map((hex) => ({
685 hex,
686 score: this.scoreAbilityHex(hex),
687 }))
688 .filter((entry) => Number.isFinite(entry.score))
689 .sort((left, right) => right.score - left.score);
690
691 const best = scored[0];
692 if (!best) {
693 return undefined;
694 }
695
696 if (action.type === 'ability') {
697 const strategy = this.getStrategyFor(activeCreature);
698 const minScore = strategy?.getAbilityMinScore?.(activeCreature, action.abilityIndex, this);
699 if (typeof minScore === 'number' && best.score < minScore) {

Callers 2

resolveQueryMethod · 0.95
bot.tsFile · 0.80

Calls 10

getUniqueHexesMethod · 0.95
isRetreatingMethod · 0.95
scoreMoveHexMethod · 0.95
pickBestHexMethod · 0.95
scoreSummonHexMethod · 0.95
scoreAbilityHexMethod · 0.95
getStrategyForMethod · 0.95
getAbilityMinScoreMethod · 0.80

Tested by

no test coverage detected