@@ -4,14 +4,14 @@ import com.thoughtworks.xstream.annotations.XStreamAlias
4
4
import sc.api.plugins.MutableTwoDBoard
5
5
import sc.api.plugins.RectangularBoard
6
6
import sc.api.plugins.Team
7
- import sc.api.plugins.deepCopy
8
- import sc.plugin2026.FieldState.OBSTRUCTED
9
7
import sc.plugin2026.util.*
10
8
import kotlin.math.floor
11
9
10
+ typealias FieldS = Field
11
+
12
12
/* * Spielbrett für Piranhas mit [PiranhaConstants.BOARD_LENGTH]² Feldern. */
13
13
@XStreamAlias(value = " board" )
14
- class Board (gameField : MutableTwoDBoard <Field > = randomFields()): RectangularBoard<Field >(gameField) {
14
+ class Board (gameField : MutableTwoDBoard <FieldS > = randomFields()): RectangularBoard<FieldS >(gameField) {
15
15
16
16
// TODO later
17
17
// override fun toString() =
@@ -29,12 +29,12 @@ class Board(gameField: MutableTwoDBoard<Field> = randomFields()): RectangularBoa
29
29
// }
30
30
31
31
override fun clone (): Board =
32
- Board (gameField.deepCopy() )
32
+ Board (Array ( gameField.size) { column -> this .gameField[column].clone() } )
33
33
34
34
companion object {
35
35
/* * Erstellt eine zufälliges Spielbrett. */
36
- private fun randomFields (): Array < Array < Field > > {
37
- val fields = generateFields { x, y -> Field (x, y) }
36
+ private fun randomFields (): MutableTwoDBoard < FieldS > {
37
+ val fields = generateFields { x, y -> FieldS (x, y) }
38
38
39
39
// Place Piranhas
40
40
for (index in 1 until PiranhaConstants .BOARD_LENGTH - 1 ) {
@@ -52,7 +52,7 @@ class Board(gameField: MutableTwoDBoard<Field> = randomFields()): RectangularBoa
52
52
for (i in 0 until PiranhaConstants .NUM_OBSTACLES ) {
53
53
val indexOfFieldToBlock = floor(Math .random() * blockableFields.size).toInt()
54
54
val selectedField = blockableFields[indexOfFieldToBlock]
55
- selectedField.state = OBSTRUCTED
55
+ selectedField.state = FieldState . OBSTRUCTED
56
56
blockableFields = blockableFields.filter { field ->
57
57
! (field.x == selectedField.x || field.y == selectedField.y ||
58
58
field.x - field.y == selectedField.x - selectedField.y ||
@@ -62,7 +62,7 @@ class Board(gameField: MutableTwoDBoard<Field> = randomFields()): RectangularBoa
62
62
return fields
63
63
}
64
64
65
- private fun generateFields (generator : (Int , Int ) -> Field ): Array <Array <Field >> {
65
+ private fun generateFields (generator : (Int , Int ) -> FieldS ): Array <Array <FieldS >> {
66
66
return Array (PiranhaConstants .BOARD_LENGTH ) { x ->
67
67
Array (PiranhaConstants .BOARD_LENGTH ) { y ->
68
68
generator(x, y)
0 commit comments