player creation and some fixes
This commit is contained in:
parent
7822ad1258
commit
b18d2619fa
14 changed files with 57 additions and 10 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -4,6 +4,7 @@ public class Game {
|
|||
private final Player player1;
|
||||
private final Player player2;
|
||||
private final ElementGraph worldBalance;
|
||||
private boolean restart = false;
|
||||
|
||||
public Game(Player player1, Player player2, ElementGraph worldBalance) {
|
||||
this.player1 = player1;
|
||||
|
@ -23,27 +24,45 @@ public class Game {
|
|||
return worldBalance;
|
||||
}
|
||||
|
||||
public boolean isRestart() {
|
||||
return restart;
|
||||
}
|
||||
|
||||
public void setRestart(boolean restart) {
|
||||
this.restart = restart;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
// N
|
||||
int numberOfElements = worldBalance.getElements().size();
|
||||
int numberOfStones = (int) Math.ceil((numberOfElements + 1) / 3.0);
|
||||
numberOfStones += 1;
|
||||
|
||||
// P
|
||||
int numberOfStones = (int) Math.ceil((numberOfElements + 1) / 3.0) + 1;
|
||||
|
||||
// G
|
||||
int numberOfTamaGolems = (int) Math.ceil(((numberOfElements - 1) * (numberOfElements - 2)) / (2.0 * numberOfStones));
|
||||
int totalNumberOfStones = (int) Math.ceil((2.0 * numberOfTamaGolems * numberOfStones) / numberOfElements) * numberOfElements;
|
||||
|
||||
// S
|
||||
int totalNumberOfStones = (int) Math.ceil((2.0 * numberOfTamaGolems * numberOfStones));
|
||||
|
||||
// Stones for each element
|
||||
int numberOfStonesPerElement = totalNumberOfStones / numberOfElements;
|
||||
|
||||
|
||||
// deve essere uguale alla somma della potenza di tutti gli elementi
|
||||
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("Number of TamaGolems for every player: " + 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);
|
||||
System.out.println("Life points: " + totalPower);
|
||||
System.out.println("Press R to create a new game");
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ public class LinearSystem {
|
|||
|
||||
public int[] resolve() {
|
||||
int[][] extendedMatrix = new int[n][m + 1];
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
System.arraycopy(A[i], 0, extendedMatrix[i], 0, m);
|
||||
extendedMatrix[i][m] = b[i];
|
||||
|
@ -48,6 +49,7 @@ public class LinearSystem {
|
|||
for (int xi : x) {
|
||||
if (xi <= 0) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -123,6 +125,7 @@ public class LinearSystem {
|
|||
|
||||
row++;
|
||||
}
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package it.arnaldo.unibs.tamagolem;
|
|||
public class Pair {
|
||||
private final Element first;
|
||||
private final Element second;
|
||||
|
||||
Pair(Element first, Element second) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
|
|
|
@ -4,9 +4,28 @@ import java.util.*;
|
|||
|
||||
public class TamaGolemMain {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("TamaGolem");
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
Game game = new Game(new Player("Zazz"), new Player("zazz2"), WorldBuilder.buildWorld());
|
||||
System.out.println("TamaGolem");
|
||||
System.out.println("""
|
||||
|
||||
Player 1:
|
||||
Choose your name
|
||||
|
||||
""");
|
||||
|
||||
Player p1 = new Player(sc.nextLine());
|
||||
|
||||
System.out.println("""
|
||||
|
||||
Player 2:
|
||||
Choose your name
|
||||
|
||||
""");
|
||||
|
||||
Player p2 = new Player(sc.nextLine());
|
||||
|
||||
Game game = new Game(p1, p2, WorldBuilder.buildWorld());
|
||||
|
||||
game.start();
|
||||
}
|
||||
|
|
|
@ -5,11 +5,14 @@ import java.util.*;
|
|||
public class WorldBuilder {
|
||||
|
||||
public static ElementGraph buildWorld() {
|
||||
// genero un numero casuale che mi dice quanti elementi prendo
|
||||
Element[] allElements = Element.values();
|
||||
int numElements = (int)(Math.random() * 8) + 3;
|
||||
|
||||
List<Element> selectedElements = new ArrayList<>(Arrays.asList(allElements));
|
||||
Collections.shuffle(selectedElements);
|
||||
|
||||
// seleziono la sublist di lunghezza numElements
|
||||
selectedElements = selectedElements.subList(0, numElements);
|
||||
|
||||
|
||||
|
@ -46,7 +49,7 @@ public class WorldBuilder {
|
|||
|
||||
// sistema lineare per trovare le soluzioni che verificano l'equilibrio
|
||||
|
||||
try{
|
||||
try {
|
||||
LinearSystem system = new LinearSystem(numElements, A, b);
|
||||
int[] solution = system.resolve();
|
||||
|
||||
|
@ -65,7 +68,8 @@ public class WorldBuilder {
|
|||
|
||||
world.printGraph();
|
||||
return world;
|
||||
}catch (Exception e){
|
||||
|
||||
}catch (Exception e){
|
||||
buildWorld();
|
||||
}
|
||||
|
||||
|
@ -133,6 +137,7 @@ public class WorldBuilder {
|
|||
}
|
||||
|
||||
} while (!valid);
|
||||
|
||||
return linkDirections;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue