@@ -11,7 +11,8 @@ import sc.shared.IMoveMistake
11
11
import sc.shared.MoveMistake
12
12
13
13
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 */
15
16
@JvmStatic
16
17
fun movementDistance (board : Board , move : Move ): Int {
17
18
var count = 1
@@ -34,11 +35,12 @@ object GameRuleLogic {
34
35
return count
35
36
}
36
37
38
+ /* * Berechnet die Zielkoordinaten des Zuges. */
37
39
@JvmStatic
38
40
fun targetCoordinates (board : Board , move : Move ): Coordinates =
39
- move.from + move.direction.vector * movementDistance(board, move)
41
+ move.from + move.direction * movementDistance(board, move)
40
42
41
- /* * Prüft ob ein Zug gültig ist.
43
+ /* * Prüft, ob ein Zug gültig ist.
42
44
* @team null wenn der Zug valide ist, sonst ein entsprechender [IMoveMistake]. */
43
45
@JvmStatic
44
46
fun checkMove (board : Board , move : Move ): IMoveMistake ? {
@@ -72,6 +74,7 @@ object GameRuleLogic {
72
74
}
73
75
}
74
76
77
+ /* * Valide Züge des Fisches auf dem Startfeld [pos]. */
75
78
@JvmStatic
76
79
fun possibleMovesFor (board : Board , pos : Coordinates ): Collection <Move > {
77
80
val moves: MutableList <Move > = ArrayList ()
@@ -89,12 +92,13 @@ object GameRuleLogic {
89
92
.map { direction -> Move (pos, direction)}
90
93
.filter { move -> checkMove(board, move) == null }
91
94
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 > {
93
97
val returnSet = ArrayList <Coordinates >(8 )
94
98
for (i in - 1 .. 1 ) {
95
99
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
98
102
if (x < 0 || x >= PiranhaConstants .BOARD_LENGTH ||
99
103
y < 0 || y >= PiranhaConstants .BOARD_LENGTH ||
100
104
(i == 0 && j == 0 )) continue
@@ -109,7 +113,7 @@ object GameRuleLogic {
109
113
}
110
114
111
115
/* * 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. */
113
117
private fun getSwarm (looseFishes : Collection <Coordinates >, swarm : List <Coordinates >): List <Coordinates > {
114
118
val swarmNeighbors =
115
119
swarm.flatMap { selectNeighbors(it, looseFishes) }
@@ -121,6 +125,7 @@ object GameRuleLogic {
121
125
return swarm
122
126
}
123
127
128
+ /* * Finds the most weighty swarm among a set of positions with weights. */
124
129
@JvmStatic
125
130
fun greatestSwarm (fieldsToCheck : Map <Coordinates , Int >): Map <Coordinates , Int >? {
126
131
// Make a copy, so there will be no conflict with direct calls.
@@ -146,14 +151,17 @@ object GameRuleLogic {
146
151
return maxSwarm
147
152
}
148
153
154
+ /* * @return Größe des schwersten Schwarms innerhalb der gegebenen Felder */
149
155
@JvmStatic
150
156
fun greatestSwarmSize (fields : Map <Coordinates , Int >): Int =
151
157
greatestSwarm(fields)?.values?.sum() ? : - 1
152
158
159
+ /* * @return Größe des schwersten Schwarms von [team] */
153
160
@JvmStatic
154
161
fun greatestSwarmSize (board : Board , team : ITeam ): Int =
155
162
greatestSwarmSize(board.fieldsForTeam(team))
156
163
164
+ /* * @return ob alle Fische des Teams zusammenhängend sind */
157
165
@JvmStatic
158
166
fun isSwarmConnected (board : Board , team : ITeam ): Boolean {
159
167
val fieldsWithFish = board.fieldsForTeam(team)
0 commit comments