Progress with factory generation from factory graph

This commit is contained in:
hal8174 2025-02-02 23:10:40 +01:00
parent 0ab97485bb
commit 0f8bf5000c
8 changed files with 613 additions and 81 deletions

View file

@ -1,6 +1,7 @@
use clap::Parser;
use factorio_blueprint::{BlueprintString, encode};
use factorio_blueprint_generator::assembly::assembly_line;
use factorio_blueprint_generator::assembly::{assembly_line, assembly_line_2_input};
use factorio_core::beltoptions::Beltspeed;
#[derive(Parser)]
struct Args {
@ -8,12 +9,22 @@ struct Args {
json: bool,
assembly_machines: usize,
recipe: String,
output_belt: Beltspeed,
input_belt: Vec<Beltspeed>,
}
fn main() {
let args = Args::parse();
let b = BlueprintString::Blueprint(
assembly_line(args.assembly_machines, args.recipe).to_blueprint(),
assembly_line_2_input(
args.assembly_machines,
args.recipe,
args.input_belt[0],
args.input_belt.get(1).copied(),
args.output_belt,
)
.0
.to_blueprint(),
);
if args.json {

View file

@ -1,6 +1,8 @@
use std::path::PathBuf;
use clap::Parser;
use factorio_blueprint::{BlueprintString, encode};
use factorio_blueprint_generator::factory::generate_factory;
use factorio_blueprint_generator::factory::{FactoryGraph, generate_factory};
use factorio_core::prelude::*;
use factorio_layout::{genetic_algorithm_v1::GeneticAlgorithm, valid_layout::ValidLayout};
use factorio_pathfinding::belt_finding::ConflictAvoidance;
@ -12,11 +14,18 @@ struct Args {
seed: u64,
#[arg(short, long)]
json: bool,
path: PathBuf,
}
fn main() {
let args = Args::parse();
let text = std::fs::File::open(&args.path).unwrap();
let factory_graph: FactoryGraph = serde_yaml::from_reader(text).unwrap();
dbg!(&factory_graph);
let l = ValidLayout {
max_tries: 10,
retries: 20,
@ -38,7 +47,9 @@ fn main() {
let mut rng = SmallRng::seed_from_u64(args.seed);
let b = BlueprintString::Blueprint(generate_factory(&l, &p, &mut rng).to_blueprint());
let b = BlueprintString::Blueprint(
generate_factory(&l, &p, factory_graph, &mut rng).to_blueprint(),
);
if args.json {
println!("{}", serde_json::to_string_pretty(&b).unwrap());