-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2de2fb
commit 1c5917c
Showing
37 changed files
with
612 additions
and
102 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
packages/kitten-analysts/examples/a708b0ad-5f94-4466-8a2e-1d381117d0e0.json
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Operator } from "./GraphSolver.js"; | ||
|
||
export class GraphDotPrinter { | ||
print( | ||
node: Operator, | ||
seen = new Set<Operator>(), | ||
indent = 0, | ||
dotBuffer = new Array<string>(), | ||
): Array<string> { | ||
if (30 < indent) { | ||
throw new Error("graph too deep"); | ||
} | ||
|
||
if (seen.has(node)) { | ||
console.info(`${" ".repeat(indent)}${node.name} ↻ loops back into graph`); | ||
return dotBuffer; | ||
} | ||
|
||
seen.add(node); | ||
|
||
if (0 < node.requires.length && node.children.size === 0) { | ||
console.warn(`${" ".repeat(indent)}${node.name} 🗲 unsolved!`); | ||
return dotBuffer; | ||
} | ||
|
||
console.info(`${" ".repeat(indent)}${node.name}`); | ||
dotBuffer.push( | ||
`"${node.name}"${indent === 0 ? " [shape=circle, color=darkolivegreen3, style=filled]" : ""}`, | ||
); | ||
|
||
if (node.requires.length === 0) { | ||
return dotBuffer; | ||
} | ||
|
||
const requirements = new Set(node.requires); | ||
for (const child of node.children) { | ||
this.print(child, seen, indent + 1, dotBuffer); | ||
dotBuffer.push(`"${child.name}" -> "${node.name}"`); | ||
for (const solution of child.solves) { | ||
requirements.delete(solution); | ||
} | ||
} | ||
if (0 < requirements.size) { | ||
console.warn( | ||
`${" ".repeat(indent)}🗲 parent was left partially unsolved: ${[...requirements.values()].join(", ")}`, | ||
); | ||
} | ||
|
||
return dotBuffer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/kitten-engineers/source/operators/assign-geologist.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { PayloadBuildings } from "@kitten-science/kitten-analysts/KittenAnalysts.js"; | ||
import { EngineState } from "@kitten-science/kitten-scientists/Engine.js"; | ||
import { Game } from "@kitten-science/kitten-scientists/types/game.js"; | ||
import { TreeNode } from "@oliversalzburg/js-utils/data/tree.js"; | ||
import { Operator } from "../GraphSolver.js"; | ||
import { cdebug } from "../tools/Log.js"; | ||
|
||
export class AssignGeologist extends TreeNode<Operator> implements Operator { | ||
name = "assign geologist"; | ||
|
||
requires = ["kittens" as const, "archeology" as const, "geodesy" as const]; | ||
solves = ["coal" as const, "gold" as const]; | ||
|
||
ancestors = new Set<Operator>(); | ||
|
||
calculateCost() { | ||
return 0; | ||
} | ||
|
||
execute(_game: Game, state: EngineState, snapshots: { buildings: PayloadBuildings }) { | ||
cdebug( | ||
"Solar Revolution is currently at value:", | ||
snapshots.buildings.find(b => b.name === "solarRevolution")?.value, | ||
); | ||
return state; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/kitten-engineers/source/operators/assign-scholar.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { PayloadBuildings } from "@kitten-science/kitten-analysts/KittenAnalysts.js"; | ||
import { EngineState } from "@kitten-science/kitten-scientists/Engine.js"; | ||
import { Game } from "@kitten-science/kitten-scientists/types/game.js"; | ||
import { TreeNode } from "@oliversalzburg/js-utils/data/tree.js"; | ||
import { Operator } from "../GraphSolver.js"; | ||
|
||
export class AssignScholar extends TreeNode<Operator> implements Operator { | ||
name = "assign scholar"; | ||
|
||
requires = ["kittens" as const, "library" as const, "astrophysicists" as const]; | ||
solves = ["science" as const, "starchart" as const]; | ||
|
||
ancestors = new Set<Operator>(); | ||
|
||
calculateCost() { | ||
return 0; | ||
} | ||
|
||
execute(_game: Game, state: EngineState, _snapshots: { buildings: PayloadBuildings }) { | ||
return state; | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.