Game class updates

This commit is contained in:
L3o15 2025-05-13 17:02:45 +02:00
parent 7cd4664974
commit 7d1f38e19c
9 changed files with 68 additions and 23 deletions

View file

@ -40,5 +40,15 @@ public class ElementGraph {
}
}
public int getTotalStrength(){
int totalStrength = 0;
for (GraphElement element : elements) {
totalStrength += element.getTotalStrength();
}
return totalStrength;
}
}

View file

@ -16,4 +16,8 @@ public class ElementLink {
public Element getElement() {
return element;
}
public int getTotalStrength() {
return value >= 0 ? value : 0;
}
}

View file

@ -25,15 +25,25 @@ public class Game {
public void start() {
int numberOfElements = worldBalance.getElements().size();
int numberOfStones = Math.round((float) ((numberOfElements + 1)/3.0)) + 1;
int numberOfTamaGolems = Math.round((float) ((numberOfElements - 1) * (numberOfElements - 2) / (2 * numberOfStones)));
int totalNumberOfStones = Math.round((float) ((2 * numberOfTamaGolems * numberOfStones) / numberOfElements)) * numberOfElements;
int numberOfStones = (int) Math.ceil((numberOfElements + 1) / 3.0);
numberOfStones += 1;
int numberOfTamaGolems = (int) Math.ceil(((numberOfElements - 1) * (numberOfElements - 2)) / (2.0 * numberOfStones));
int totalNumberOfStones = (int) Math.ceil((2.0 * numberOfTamaGolems * numberOfStones) / numberOfElements) * numberOfElements;
int numberOfStonesPerElement = totalNumberOfStones / numberOfElements;
// deve essere uguale alla somma della potenza di tutti gli elementi
int totalPower = 0;
int lifePoints = (int)(Math.random() * 11) + 5;
int totalPower = worldBalance.getTotalStrength();
int lifePoints = totalPower;
System.out.println("Game started between " + player1.getName() + " and " + player2.getName());
System.out.println("Number of stones: " + numberOfStones);
System.out.println("Number of elements: " + numberOfElements);
System.out.println("Number of TamaGolems: " + numberOfTamaGolems);
System.out.println("Total number of stones: " + totalNumberOfStones);
System.out.println("Total number of stones for each element: " + numberOfStonesPerElement);
System.out.println("Total power: " + totalPower);
System.out.println("Life points: " + lifePoints);
}
}

View file

@ -32,4 +32,12 @@ public class GraphElement {
}
return 0;
}
public int getTotalStrength(){
int strength = 0;
for (ElementLink link : links) {
strength += link.getTotalStrength();
}
return strength;
}
}

View file

@ -30,7 +30,7 @@ public class LinearSystem {
int[] solutions;
Random rand = new Random();
int tries = 100000000;
int tries = 1000000;
while (tries-- > 0) {
int[] lambdaValues = new int[indipendentVariables];
for (int i = 0; i < indipendentVariables; i++) {

View file

@ -1,6 +1,5 @@
package it.arnaldo.unibs.tamagolem;
// Utility pair class
public class Pair {
private final Element first;
private final Element second;

View file

@ -5,7 +5,9 @@ import java.util.*;
public class TamaGolemMain {
public static void main(String[] args) {
System.out.println("TamaGolem");
WorldBuilder.buildWorld();
Game game = new Game(new Player("Zazz"), new Player("zazz2"), WorldBuilder.buildWorld());
game.start();
}
}

View file

@ -6,15 +6,18 @@ public class WorldBuilder {
public static ElementGraph buildWorld() {
Element[] allElements = Element.values();
int numElements = (int)(Math.random() * 10);
int numElements = (int)(Math.random() * 8) + 3;
List<Element> selectedElements = new ArrayList<>(Arrays.asList(allElements));
Collections.shuffle(selectedElements);
selectedElements = selectedElements.subList(0, numElements);
// Mappa delle direzioni tra elementi (1 = attacca, -1 = subisce)
Map<Element, Map<Element, Integer>> linkDirections = generateValidDirections(selectedElements);
// Mappa indice per ogni coppia (non ordinata) di elementi
Map<Set<Element>, Integer> pairIndex = new HashMap<>();
int index = 0;
@ -42,6 +45,8 @@ public class WorldBuilder {
}
// sistema lineare per trovare le soluzioni che verificano l'equilibrio
try{
LinearSystem system = new LinearSystem(numElements, A, b);
int[] solution = system.resolve();
@ -60,6 +65,13 @@ public class WorldBuilder {
world.printGraph();
return world;
}catch (Exception e){
buildWorld();
}
return null;
}
private static Map<Element, Map<Element, Integer>> generateValidDirections(List<Element> elements) {