This commit is contained in:
Arthur 2021-02-02 18:02:10 +01:00
parent 664d3ed06d
commit 049e3aeda7
2 changed files with 40 additions and 5 deletions

View File

@ -1,7 +1,6 @@
package lsystem;
import lsystem.engine.parser.Parser;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
@ -11,6 +10,7 @@ public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Parser parser = null;
int nbIterations = 0;
while(parser == null || parser.isCorrect()) {
if(parser != null)
System.out.println("Vos règles ou votre axiome ne sont pas correctement écrites, veuillez recommencer");
@ -22,7 +22,7 @@ public class Main {
rules.add(scanner.next());
}
rules.remove(rules.size() - 1);
parser = new Parser(axiom, rules);
parser = new Parser(axiom, rules,nbIterations);
}
scanner.close();

View File

@ -6,15 +6,50 @@ public class Parser {
private final String axiom;
private final List<String> rules;
private final int nbIterations;
private String[] validStrings = {"]","[",".","+","-","X","Y","Z","x","y","z","0","1","2","3","4","5","6","7","8","9"};
public Parser(String axiom, List<String> rules) {
public Parser(String axiom, List<String> rules,int nbIterations) {
this.axiom = axiom;
this.rules = rules;
this.nbIterations = nbIterations;
}
public boolean isCorrect(){
return false;
return (rulesCorrect() || axiomCorrect());
}
private boolean axiomCorrect() {
return false;
}
public boolean rulesCorrect() {
for(String r : this.rules) {
String[] stringsplitted = r.split("");
String old = null;
int bracket = 0;
for (String rules : stringsplitted){
for(String string : validStrings){
if (rules == "[")
bracket += 1;
if(rules =="]")
bracket -=1;
if(old == "."){
for(int i = 0;i<10;i++){
if(rules == validStrings[i])
return false;
}
}
old = rules;
if(rules == string)
break;
if(string == "9" && rules != string)
return false;
}
}
if (bracket != 0)
return false;
}
return true;
}
}