Game class updates
This commit is contained in:
parent
7cd4664974
commit
7d1f38e19c
9 changed files with 68 additions and 23 deletions
Binary file not shown.
|
@ -40,5 +40,15 @@ public class ElementGraph {
|
|||
}
|
||||
}
|
||||
|
||||
public int getTotalStrength(){
|
||||
int totalStrength = 0;
|
||||
|
||||
for (GraphElement element : elements) {
|
||||
totalStrength += element.getTotalStrength();
|
||||
}
|
||||
|
||||
return totalStrength;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -16,4 +16,8 @@ public class ElementLink {
|
|||
public Element getElement() {
|
||||
return element;
|
||||
}
|
||||
|
||||
public int getTotalStrength() {
|
||||
return value >= 0 ? value : 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,4 +32,12 @@ public class GraphElement {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getTotalStrength(){
|
||||
int strength = 0;
|
||||
for (ElementLink link : links) {
|
||||
strength += link.getTotalStrength();
|
||||
}
|
||||
return strength;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package it.arnaldo.unibs.tamagolem;
|
||||
|
||||
// Utility pair class
|
||||
public class Pair {
|
||||
private final Element first;
|
||||
private final Element second;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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,24 +45,33 @@ public class WorldBuilder {
|
|||
}
|
||||
|
||||
// sistema lineare per trovare le soluzioni che verificano l'equilibrio
|
||||
LinearSystem system = new LinearSystem(numElements, A, b);
|
||||
int[] solution = system.resolve();
|
||||
|
||||
// dalle soluzioni del sistema popolo il grafo
|
||||
ElementGraph world = new ElementGraph();
|
||||
for (Element e1 : selectedElements) {
|
||||
GraphElement graphElement = new GraphElement(e1);
|
||||
for (Element e2 : selectedElements) {
|
||||
if (e1 == e2) continue;
|
||||
int dir = linkDirections.get(e1).get(e2);
|
||||
int val = solution[pairIndex.get(Set.of(e1, e2))];
|
||||
graphElement.addLink(new ElementLink(dir * val, e2));
|
||||
try{
|
||||
LinearSystem system = new LinearSystem(numElements, A, b);
|
||||
int[] solution = system.resolve();
|
||||
|
||||
// dalle soluzioni del sistema popolo il grafo
|
||||
ElementGraph world = new ElementGraph();
|
||||
for (Element e1 : selectedElements) {
|
||||
GraphElement graphElement = new GraphElement(e1);
|
||||
for (Element e2 : selectedElements) {
|
||||
if (e1 == e2) continue;
|
||||
int dir = linkDirections.get(e1).get(e2);
|
||||
int val = solution[pairIndex.get(Set.of(e1, e2))];
|
||||
graphElement.addLink(new ElementLink(dir * val, e2));
|
||||
}
|
||||
world.addElement(graphElement);
|
||||
}
|
||||
world.addElement(graphElement);
|
||||
|
||||
world.printGraph();
|
||||
return world;
|
||||
}catch (Exception e){
|
||||
buildWorld();
|
||||
}
|
||||
|
||||
world.printGraph();
|
||||
return world;
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
private static Map<Element, Map<Element, Integer>> generateValidDirections(List<Element> elements) {
|
||||
|
|
Loading…
Add table
Reference in a new issue