World building to max 6 elements

This commit is contained in:
L3o15 2025-05-12 19:16:28 +02:00
parent 8fe0d0e323
commit 3f77488b69
3 changed files with 25 additions and 29 deletions

View file

@ -34,7 +34,7 @@ public class LinearSystem {
while (tries-- > 0) { while (tries-- > 0) {
int[] lambdaValues = new int[indipendentVariables]; int[] lambdaValues = new int[indipendentVariables];
for (int i = 0; i < indipendentVariables; i++) { for (int i = 0; i < indipendentVariables; i++) {
lambdaValues[i] = (rand.nextInt(n) + 1); // valori tra 1 e 9 lambdaValues[i] = (rand.nextInt(m) + 1); // valori tra 1 e 9
} }
solutions = constructSolution(extendedMatrix, lambdaValues, rank); solutions = constructSolution(extendedMatrix, lambdaValues, rank);
@ -45,14 +45,10 @@ public class LinearSystem {
} }
private boolean validNumbers(int[] x) { private boolean validNumbers(int[] x) {
boolean positive = false;
boolean negative = false;
for (int xi : x) { for (int xi : x) {
if (xi > 0) positive = true; if (xi <= 0) return false;
else if (xi < 0) negative = true;
if (xi == 0) return false;
} }
return positive && negative; return true;
} }
private int[] constructSolution(int[][] extendedMatrix, int[] parameters, int rank) { private int[] constructSolution(int[][] extendedMatrix, int[] parameters, int rank) {

View file

@ -8,7 +8,7 @@ public class WorldBuilder {
Random rand = new Random(); Random rand = new Random();
// da cambiare il numero a 8 // da cambiare il numero a 8
//int numElements = 3 + rand.nextInt(8); //int numElements = 3 + rand.nextInt(8);
int numElements = 5; int numElements = 6;
List<Element> selectedElements = new ArrayList<>(Arrays.asList(allElements)); List<Element> selectedElements = new ArrayList<>(Arrays.asList(allElements));
Collections.shuffle(selectedElements); Collections.shuffle(selectedElements);
selectedElements = selectedElements.subList(0, numElements); selectedElements = selectedElements.subList(0, numElements);
@ -23,7 +23,7 @@ public class WorldBuilder {
if (el == followingElement) { if (el == followingElement) {
links.put(el, 1); links.put(el, 1);
} else if (el != element) { } else if (el != element) {
links.put(el, 1); links.put(el, 0);
} }
} }
@ -37,24 +37,24 @@ public class WorldBuilder {
continue; continue;
} }
// // controllo anche prima per evitare che magari da un estrazione si vada a togliere // controllo anche prima per evitare che magari da un estrazione si vada a togliere
// if (elementLinks.get(el) == 1){ if (elementLinks.get(el) == 1){
// linkDirections.get(el).put(element, -1); linkDirections.get(el).put(element, -1);
// } }
//
// if (elementLinks.get(el) == 0) { if (elementLinks.get(el) == 0) {
// if (Math.random() < 0.5) { if (Math.random() < 0.5) {
// linkDirections.get(el).put(element, 1); linkDirections.get(el).put(element, 1);
// } else { } else {
// linkDirections.get(el).put(element, -1); linkDirections.get(el).put(element, -1);
// } }
// } }
//
// if (elementLinks.get(el) == 1){ if (elementLinks.get(el) == 1){
// linkDirections.get(el).put(element, -1); linkDirections.get(el).put(element, -1);
// } else { } else {
// linkDirections.get(el).put(element, 1); linkDirections.get(el).put(element, 1);
// } }
} }
} }
@ -114,8 +114,8 @@ public class WorldBuilder {
if (el == element) { if (el == element) {
continue; continue;
} }
//int direction = linkDirections.get(element).get(el); int direction = linkDirections.get(element).get(el);
graphElement.addLink(new ElementLink(solution[getIndex(element, el, pairIndex)], el)); graphElement.addLink(new ElementLink(solution[getIndex(element, el, pairIndex)] * direction, el));
} }
world.addElement(graphElement); world.addElement(graphElement);
} }