File tree Expand file tree Collapse file tree 3 files changed +22
-2
lines changed
main/kotlin/sc/plugin2024
test/kotlin/sc/plugin2024
sdk/src/main/server-api/sc/api/plugins Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,18 @@ data class Board(
26
26
val logger: Logger = LoggerFactory .getLogger(this ::class .java)
27
27
}
28
28
29
+ /* * Size of the map. */
30
+ val bounds
31
+ get() = segments.fold(Pair (0 to 0 , 0 to 0 )) { acc, segment ->
32
+ val center = segment.center
33
+ val x = center.x / 2
34
+ Pair (acc.first.first.coerceAtMost(x) to acc.first.second.coerceAtLeast(x),
35
+ acc.second.first.coerceAtMost(center.r) to acc.second.second.coerceAtLeast(center.r))
36
+ }
37
+
38
+ val rectangleSize: Coordinates
39
+ get() = bounds.let { Coordinates (it.first.second - it.first.first + 5 , it.second.second - it.second.first + 5 ) }
40
+
29
41
override fun clone (): Board = Board (this .segments.clone(), visibleSegments)
30
42
31
43
internal fun getNextDirection () =
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import io.kotest.matchers.ints.*
7
7
import io.kotest.matchers.nulls.*
8
8
import io.kotest.matchers.string.*
9
9
import io.kotest.matchers.types.*
10
+ import sc.api.plugins.Coordinates
10
11
import sc.api.plugins.CubeCoordinates
11
12
import sc.api.plugins.CubeDirection
12
13
import sc.api.plugins.Team
@@ -59,12 +60,17 @@ class BoardTest: FunSpec({
59
60
}
60
61
}
61
62
63
+ test("board bounds") {
64
+ Board (listOf(Segment .empty())).rectangleSize shouldBe Coordinates (5, 5)
65
+ Board (listOf(Segment .empty(CubeCoordinates (4,0)))).rectangleSize shouldBe Coordinates (9, 5)
66
+ Board (listOf(Segment .empty(CubeCoordinates (4,4)))).rectangleSize shouldBe Coordinates (11, 9)
67
+ }
68
+
62
69
val board = Board ()
63
70
test("segmentIndex") {
64
71
board.segmentIndex(CubeCoordinates .ORIGIN ) shouldBe 0
65
72
board.segmentIndex(CubeCoordinates (4, 0, -4)) shouldBe 1
66
73
board.segmentIndex(CubeCoordinates (0, -3, 3)) shouldBe -1
67
-
68
74
}
69
75
70
76
test("segmentDistance") {
Original file line number Diff line number Diff line change @@ -4,7 +4,6 @@ import com.thoughtworks.xstream.annotations.XStreamAsAttribute
4
4
import sc.framework.PublicCloneable
5
5
import kotlin.math.absoluteValue
6
6
import kotlin.math.sign
7
- import kotlin.random.Random
8
7
9
8
/* *
10
9
* Two-dimensional coordinates tracking each axis.
@@ -32,6 +31,9 @@ data class CubeCoordinates
32
31
val coordinates: IntArray
33
32
get() = intArrayOf(q, r, s)
34
33
34
+ val x: Int
35
+ get() = q * 2 + r
36
+
35
37
operator fun times (count : Int ): CubeCoordinates =
36
38
CubeCoordinates (q * count, r * count)
37
39
You can’t perform that action at this time.
0 commit comments