L-System/src/lsystem/Main.java

40 lines
1.4 KiB
Java
Raw Normal View History

2021-02-02 15:46:38 +01:00
package lsystem;
import lsystem.engine.Parser;
import lsystem.engine.Rewrite;
2021-02-02 15:46:38 +01:00
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
final Scanner scanner = new Scanner(System.in);
String axiom = null;
2021-02-02 16:07:08 +01:00
Parser parser = null;
final List<String> rules = new ArrayList<>();
2021-02-02 18:02:10 +01:00
int nbIterations = 0;
while(parser == null || !parser.isCorrect()) {
2021-02-02 16:07:08 +01:00
if(parser != null)
System.out.println("Vos règles ou votre axiome ne sont pas correctement écrites, veuillez recommencer");
System.out.println("Axiome: ");
axiom = scanner.next();
2021-02-02 16:07:08 +01:00
System.out.println("Règles: (\"finish\" quand vous avez fini): ");
while(rules.isEmpty() || !rules.get(rules.size() - 1).equals("finish")) {
rules.add(scanner.next());
}
rules.remove(rules.size() - 1);
System.out.println("Nombre d'itérations: ");
nbIterations = scanner.nextInt();
2021-02-02 18:02:10 +01:00
parser = new Parser(axiom, rules,nbIterations);
2021-02-02 15:46:38 +01:00
}
System.out.println("Réécriture, veuillez patientez...");
Rewrite rewriter = new Rewrite(axiom, parser.parseRules(), nbIterations);
final String word = rewriter.rewrite();
System.out.println(word);
2021-02-02 16:07:08 +01:00
scanner.close();
2021-02-02 15:46:38 +01:00
}
}