WIP goal
This commit is contained in:
parent
13de38bac8
commit
ba24a0e430
4 changed files with 122 additions and 14 deletions
|
|
@ -22,10 +22,13 @@ public abstract class Player {
|
||||||
this.remainingTroops = 0;
|
this.remainingTroops = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRemainingTroops() {
|
/**
|
||||||
return this.remainingTroops;
|
* Creates a player
|
||||||
}
|
* @param playerType The type of player (human, AI, etc.)
|
||||||
|
* @param name The name of the player
|
||||||
|
* @param color The color of the player
|
||||||
|
* @return The new player
|
||||||
|
*/
|
||||||
public static Player createPlayer(Class<?> playerType, String name, Color color) {
|
public static Player createPlayer(Class<?> playerType, String name, Color color) {
|
||||||
if(!Player.class.isAssignableFrom(playerType))
|
if(!Player.class.isAssignableFrom(playerType))
|
||||||
throw new IllegalArgumentException("Not a player class");
|
throw new IllegalArgumentException("Not a player class");
|
||||||
|
|
@ -39,26 +42,54 @@ public abstract class Player {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the color of this player
|
||||||
|
* @param c
|
||||||
|
*/
|
||||||
public void setColor(Color c) {
|
public void setColor(Color c) {
|
||||||
this.color = c;
|
this.color = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the color of the player
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public Color getColor() {
|
public Color getColor() {
|
||||||
return this.color;
|
return this.color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the name of this player
|
||||||
|
* @return The name
|
||||||
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getRemainingTroops() {
|
||||||
|
return this.remainingTroops;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current points of this player
|
||||||
|
* @return The current points
|
||||||
|
*/
|
||||||
public int getPoints() {
|
public int getPoints() {
|
||||||
return points;
|
return points;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increases the score of this player
|
||||||
|
* @param points The number of points to add
|
||||||
|
*/
|
||||||
public void addPoints(int points) {
|
public void addPoints(int points) {
|
||||||
this.points += points;
|
this.points += points;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds troops to the player
|
||||||
|
* @param troops The number of troops to add
|
||||||
|
*/
|
||||||
public void addTroops(int troops) {
|
public void addTroops(int troops) {
|
||||||
if(troops < 0)
|
if(troops < 0)
|
||||||
return;
|
return;
|
||||||
|
|
@ -66,6 +97,10 @@ public abstract class Player {
|
||||||
this.remainingTroops += troops;
|
this.remainingTroops += troops;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes troops from this player
|
||||||
|
* @param troops The number of troops to remove
|
||||||
|
*/
|
||||||
public void removeTroops(int troops) {
|
public void removeTroops(int troops) {
|
||||||
if(this.remainingTroops - troops < 0 || troops < 0)
|
if(this.remainingTroops - troops < 0 || troops < 0)
|
||||||
return;
|
return;
|
||||||
|
|
@ -73,14 +108,27 @@ public abstract class Player {
|
||||||
this.remainingTroops -= troops;
|
this.remainingTroops -= troops;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the number of castles this player has
|
||||||
|
* @param game The game object
|
||||||
|
* @return The number of castles
|
||||||
|
*/
|
||||||
public int getNumRegions(Game game) {
|
public int getNumRegions(Game game) {
|
||||||
return this.getCastles(game).size();
|
return this.getCastles(game).size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all the castles that belong to the player
|
||||||
|
* @param game The game object
|
||||||
|
* @return A list of castles
|
||||||
|
*/
|
||||||
public List<Castle> getCastles(Game game) {
|
public List<Castle> getCastles(Game game) {
|
||||||
return game.getMap().getCastles().stream().filter(c -> c.getOwner() == this).collect(Collectors.toList());
|
return game.getMap().getCastles().stream().filter(c -> c.getOwner() == this).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets the player by resetting the troops and points
|
||||||
|
*/
|
||||||
public void reset() {
|
public void reset() {
|
||||||
this.remainingTroops = 0;
|
this.remainingTroops = 0;
|
||||||
this.points = 0;
|
this.points = 0;
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,70 @@
|
||||||
package game.goals;
|
package game.goals;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import game.Game;
|
||||||
import game.Goal;
|
import game.Goal;
|
||||||
import game.Player;
|
import game.Player;
|
||||||
|
import game.map.Castle;
|
||||||
|
|
||||||
public class CaptureTheFlagGoal extends Goal {
|
public class CaptureTheFlagGoal extends Goal {
|
||||||
|
|
||||||
|
final int ROUND_FOR_DISTRIBUTION = 2;
|
||||||
|
final int MIN_ROUND_FOR_WIN = 2;
|
||||||
|
|
||||||
|
List<Castle> flagCastles;
|
||||||
|
|
||||||
public CaptureTheFlagGoal() {
|
public CaptureTheFlagGoal() {
|
||||||
// TODO Auto-generated constructor stub
|
|
||||||
super("Capture the flag", "");
|
super("Capture the flag", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCompleted() {
|
public boolean isCompleted() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
Game game = this.getGame();
|
||||||
|
|
||||||
|
// As this function is called every round,
|
||||||
|
// let's check if we can set the flag castles
|
||||||
|
if (flagCastles == null && game.getRound() > ROUND_FOR_DISTRIBUTION) {
|
||||||
|
distributeFlagCastles();
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.getWinner() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Player getWinner() {
|
public Player getWinner() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
Game game = this.getGame();
|
||||||
|
|
||||||
|
if (game.getRound() < MIN_ROUND_FOR_WIN)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
// Check if all flag castles belong
|
||||||
|
// to exactly one player
|
||||||
|
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasLost(Player player) {
|
public boolean hasLost(Player player) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
if (isCompleted())
|
||||||
|
return player.equals(getWinner());
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Distribute the flag castles
|
||||||
|
*/
|
||||||
|
private void distributeFlagCastles() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package tests.student;
|
||||||
|
|
||||||
|
public class GraphAlgorithmTest {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
Der Algorithmus für die Bildung der Kanten ist folgender:
|
Der Algorithmus für die Bildung der Kanten ist folgender:
|
||||||
|
|
||||||
\begin{algorithm}
|
\begin{algorithm}
|
||||||
\caption{Bildung von Kanten}\label{euclid}
|
\caption{Bildung von Kanten}\label{generate}
|
||||||
\begin{algorithmic}[1]
|
\begin{algorithmic}[1]
|
||||||
\Procedure{generateEdges}{}
|
\Procedure{generateEdges}{}
|
||||||
\If{nodes is empty} return \EndIf
|
\If{nodes is empty} return \EndIf
|
||||||
|
|
@ -73,7 +73,7 @@ Der Algorithmus, der prüft, ob alle Knoten erreichbar sind, ist
|
||||||
folgender:
|
folgender:
|
||||||
|
|
||||||
\begin{algorithm}
|
\begin{algorithm}
|
||||||
\caption{Erreichbarkeit aller Knoten}\label{euclid}
|
\caption{Erreichbarkeit aller Knoten}\label{connected}
|
||||||
\begin{algorithmic}[1]
|
\begin{algorithmic}[1]
|
||||||
\Procedure{allNodesConnected}{}
|
\Procedure{allNodesConnected}{}
|
||||||
\State $\textit{firstNode} \gets \text{first element of }\textit{nodes}$
|
\State $\textit{firstNode} \gets \text{first element of }\textit{nodes}$
|
||||||
|
|
@ -128,7 +128,7 @@ werden der ArrayDeque \texttt{nextVisitNodes} hinzugefügt.
|
||||||
\subsubsection{Teil (a)}
|
\subsubsection{Teil (a)}
|
||||||
|
|
||||||
\begin{algorithm}
|
\begin{algorithm}
|
||||||
\caption{Berechnung der Distanzen}\label{euclid}
|
\caption{Berechnung der Distanzen}\label{path}
|
||||||
\begin{algorithmic}[1]
|
\begin{algorithmic}[1]
|
||||||
\Procedure{run}{}
|
\Procedure{run}{}
|
||||||
\State $v \gets$ getSmallestNode()
|
\State $v \gets$ getSmallestNode()
|
||||||
|
|
@ -151,7 +151,7 @@ werden der ArrayDeque \texttt{nextVisitNodes} hinzugefügt.
|
||||||
\end{algorithm}
|
\end{algorithm}
|
||||||
|
|
||||||
|
|
||||||
$$O(n) = $$
|
$$O(n)$$
|
||||||
|
|
||||||
$n$ soll in diesem Fall die Anzahl an Knoten wiedergeben.
|
$n$ soll in diesem Fall die Anzahl an Knoten wiedergeben.
|
||||||
|
|
||||||
|
|
@ -161,6 +161,13 @@ Durchgehen der Liste jedes Element einzeln abgearbeitet
|
||||||
werden. In der Funktion \texttt{getSmallestNode()} ist
|
werden. In der Funktion \texttt{getSmallestNode()} ist
|
||||||
dies der Fall.
|
dies der Fall.
|
||||||
|
|
||||||
|
Das bedeutet, dass bei jeder Aufruf von \texttt{getSmallestNode()}
|
||||||
|
eine Komplexität von $O(n)$ hat, wenn $n$ die Anzahl
|
||||||
|
der Knoten darstellt.
|
||||||
|
|
||||||
|
Bei jeder Iteration des Algorithmus wird zuerst der
|
||||||
|
Knoten mit dem kleinsten Wert gesucht.
|
||||||
|
|
||||||
\subsubsection{Teil (b)}
|
\subsubsection{Teil (b)}
|
||||||
|
|
||||||
Anstelle einer \texttt{LinkedList} braucht man eine
|
Anstelle einer \texttt{LinkedList} braucht man eine
|
||||||
|
|
@ -174,7 +181,7 @@ Elemente beim Einfügen bereits sortiert, sodass der
|
||||||
Zugriff auf das (in diesem Fall) kleinste Element
|
Zugriff auf das (in diesem Fall) kleinste Element
|
||||||
in $O(1)$, also konstanter Zeit, gemacht werden kann.
|
in $O(1)$, also konstanter Zeit, gemacht werden kann.
|
||||||
|
|
||||||
$$O(n) = $$
|
$$O(n)$$
|
||||||
|
|
||||||
\subsubsection{Teil (c)}
|
\subsubsection{Teil (c)}
|
||||||
|
|
||||||
|
|
@ -199,6 +206,15 @@ Für alle abgearbeiteten Knoten gilt:
|
||||||
|
|
||||||
\subsection{Missionen}
|
\subsection{Missionen}
|
||||||
|
|
||||||
|
\subsubsection{Begrenzte Rundenanzahl}
|
||||||
|
|
||||||
|
\subsubsection{Capture the Flag}
|
||||||
|
|
||||||
|
In dieser Mission werden wichtige Burgen, sogenannte
|
||||||
|
Flags, gleichmäßig auf die Spieler verteilt. Es ist das
|
||||||
|
Ziel, zuerst vor allen anderen Spielern alle diese Burgen
|
||||||
|
zu erobern.
|
||||||
|
|
||||||
\subsection{Joker}
|
\subsection{Joker}
|
||||||
|
|
||||||
\end{document}
|
\end{document}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue