Skip to content

Commit

Permalink
fix(core): add orphan daemons to daemons of resolved sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
marcincichocki committed Oct 10, 2022
1 parent 70b501e commit a56cfd7
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/core/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from './common';
import { SequenceCompareStrategy } from './compare-strategy';
import {
Daemon,
generateSequences,
memoizedFindOverlap,
Sequence,
Expand Down Expand Up @@ -95,11 +96,30 @@ export class BreachProtocolResult implements Serializable {
return Math.max(...indexes);
}

private getResolvedSequenceParts(tValue: string) {
if (tValue !== this.sequence.tValue) {
// In rare cases, daemons can be solved by accident.
// This can happen when daemon is is delayed on a sequence break.
const pts = this.sequence.parts.map(({ tValue }) => tValue);

return this.game.rawData.daemons
.map((raw, index) => ({ dt: raw.map(fromHex).join(''), index }))
.filter(({ dt }) => !pts.includes(dt))
.filter(({ dt }) => tValue.includes(dt))
.map(({ dt, index }) => new Daemon(dt.split('').map(toHex), index))
.concat(this.sequence.parts);
}

return this.sequence.parts;
}

// Produces sequence from resolved path.
private getResolvedSequence() {
const value = this.resolvePath(this.path).map(toHex);
const tValue = this.resolvePath(this.path).join('');
const value = tValue.split('').map(toHex);
const parts = this.getResolvedSequenceParts(tValue);

return new Sequence(value, this.sequence.parts);
return new Sequence(value, parts);
}
}

Expand Down

0 comments on commit a56cfd7

Please sign in to comment.