@@ -11,7 +11,8 @@ import sc.shared.IMoveMistake
1111import sc.shared.MoveMistake
1212
1313object 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