Skip to content

Commit d24d827

Browse files
committed
docs(plugin26): document GameRuleLogic methods
1 parent 389ee94 commit d24d827

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

plugin2026/src/main/kotlin/sc/plugin2026/Move.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,24 @@ import com.thoughtworks.xstream.annotations.XStreamAlias
44
import sc.api.plugins.Coordinates
55
import sc.api.plugins.Direction
66
import sc.api.plugins.IMove
7+
import sc.plugin2026.util.GameRuleLogic
78

89
@XStreamAlias("move")
9-
/** Spielzug: Eine Bewegung eines Fisches. */
10+
/**
11+
* Spielzug: Eine Bewegung eines Fisches.
12+
*
13+
* Für weitere Funktionen siehe [GameRuleLogic].
14+
*/
1015
data class Move(
1116
/** Position des zu bewegenden Fisches. */
1217
val from: Coordinates,
1318
/** Bewegungsrichtung des Zugs. */
1419
val direction: Direction,
1520
): IMove {
1621

22+
/** Zugdistanz auf dem gegebenen [board]. Kann mit [direction] multipliziert werden um Zugvektor zu ermitteln. */
23+
fun getDistance(board: Board) = GameRuleLogic.movementDistance(board, this)
24+
1725
override fun toString(): String =
1826
"Schwimme von $from in Richtung $direction"
1927

plugin2026/src/main/kotlin/sc/plugin2026/util/GameRuleLogic.kt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import sc.shared.IMoveMistake
1111
import sc.shared.MoveMistake
1212

1313
object GameRuleLogic {
14-
/** Anzahl der Fische in der Bewegungsachse des Zuges. */
14+
/** Anzahl der Fische in der Bewegungsachse des Zuges.
15+
* @return wie viele Felder weit der Zug sein sollte */
1516
@JvmStatic
1617
fun movementDistance(board: Board, move: Move): Int {
1718
var count = 1
@@ -34,11 +35,12 @@ object GameRuleLogic {
3435
return count
3536
}
3637

38+
/** Berechnet die Zielkoordinaten des Zuges. */
3739
@JvmStatic
3840
fun targetCoordinates(board: Board, move: Move): Coordinates =
39-
move.from + move.direction.vector * movementDistance(board, move)
41+
move.from + move.direction * movementDistance(board, move)
4042

41-
/** Prüft ob ein Zug gültig ist.
43+
/** Prüft, ob ein Zug gültig ist.
4244
* @team null wenn der Zug valide ist, sonst ein entsprechender [IMoveMistake]. */
4345
@JvmStatic
4446
fun checkMove(board: Board, move: Move): IMoveMistake? {
@@ -72,6 +74,7 @@ object GameRuleLogic {
7274
}
7375
}
7476

77+
/** Valide Züge des Fisches auf dem Startfeld [pos]. */
7578
@JvmStatic
7679
fun possibleMovesFor(board: Board, pos: Coordinates): Collection<Move> {
7780
val moves: MutableList<Move> = ArrayList()
@@ -89,12 +92,13 @@ object GameRuleLogic {
8992
.map { direction -> Move(pos, direction)}
9093
.filter { move -> checkMove(board, move) == null }
9194

92-
private fun selectNeighbors(f: Coordinates, parentSet: Collection<Coordinates>): Collection<Coordinates> {
95+
/** @return the [Coordinates] from [parentSet] which are neighbors of [pos] */
96+
private fun selectNeighbors(pos: Coordinates, parentSet: Collection<Coordinates>): Collection<Coordinates> {
9397
val returnSet = ArrayList<Coordinates>(8)
9498
for(i in -1..1) {
9599
for(j in -1..1) {
96-
val x = f.x + i
97-
val y = f.y + j
100+
val x = pos.x + i
101+
val y = pos.y + j
98102
if(x < 0 || x >= PiranhaConstants.BOARD_LENGTH ||
99103
y < 0 || y >= PiranhaConstants.BOARD_LENGTH ||
100104
(i == 0 && j == 0)) continue
@@ -109,7 +113,7 @@ object GameRuleLogic {
109113
}
110114

111115
/** Called with a single fish in [swarm] and the [looseFishes] left,
112-
* recursively calling with neighbors added to [swarm] to find the whole swarm. */
116+
* recursively calling with neighbors added to [swarm] to find a whole swarm. */
113117
private fun getSwarm(looseFishes: Collection<Coordinates>, swarm: List<Coordinates>): List<Coordinates> {
114118
val swarmNeighbors =
115119
swarm.flatMap { selectNeighbors(it, looseFishes) }
@@ -121,6 +125,7 @@ object GameRuleLogic {
121125
return swarm
122126
}
123127

128+
/** Finds the most weighty swarm among a set of positions with weights. */
124129
@JvmStatic
125130
fun greatestSwarm(fieldsToCheck: Map<Coordinates, Int>): Map<Coordinates, Int>? {
126131
// Make a copy, so there will be no conflict with direct calls.
@@ -146,14 +151,17 @@ object GameRuleLogic {
146151
return maxSwarm
147152
}
148153

154+
/** @return Größe des schwersten Schwarms innerhalb der gegebenen Felder */
149155
@JvmStatic
150156
fun greatestSwarmSize(fields: Map<Coordinates, Int>): Int =
151157
greatestSwarm(fields)?.values?.sum() ?: -1
152158

159+
/** @return Größe des schwersten Schwarms von [team] */
153160
@JvmStatic
154161
fun greatestSwarmSize(board: Board, team: ITeam): Int =
155162
greatestSwarmSize(board.fieldsForTeam(team))
156163

164+
/** @return ob alle Fische des Teams zusammenhängend sind */
157165
@JvmStatic
158166
fun isSwarmConnected(board: Board, team: ITeam): Boolean {
159167
val fieldsWithFish = board.fieldsForTeam(team)

0 commit comments

Comments
 (0)