Skip to content

Commit 5549eea

Browse files
committed
fix(plugin): test amber from tower and fix oversights
1 parent a5f3a8d commit 5549eea

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

plugin/src/main/sc/plugin2022/Coordinates.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ data class Coordinates(
1111
@XStreamAsAttribute val x: Int,
1212
@XStreamAsAttribute val y: Int) {
1313

14-
override fun toString(): String = "[$x, $y]"
14+
override fun toString(): String = "[$x|$y]"
1515

1616
/** Addiere den [Vector] auf die [Coordinates] auf. */
1717
operator fun plus(vector: Vector): Coordinates {

plugin/src/main/sc/plugin2022/Piece.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ data class Piece(
3535
get() = type.possibleMoves.map { it.copy(dy = it.dy * team.direction) }
3636

3737
val isAmber
38-
get() = count > 3
38+
get() = count >= 3
3939

4040
fun capture(other: Piece) {
4141
count += other.count
@@ -50,9 +50,9 @@ data class Piece(
5050
@OptIn(ExperimentalStdlibApi::class)
5151
fun fromString(string: String): Piece {
5252
val type = string.first()
53-
return Piece(PieceType.values().first { it.char == type },
53+
return Piece(PieceType.values().first { it.char.equals(type, true) },
5454
if(type.isLowerCase()) Team.TWO else Team.ONE,
55-
string.last().digitToIntOrNull() ?: 0)
55+
string.last().digitToIntOrNull() ?: 1)
5656
}
5757
}
5858
}

plugin/src/test/sc/plugin2022/BoardTest.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
88
import io.kotest.matchers.maps.shouldBeEmpty
99
import io.kotest.matchers.maps.shouldHaveSize
1010
import io.kotest.matchers.maps.shouldNotBeEmpty
11+
import io.kotest.matchers.nulls.shouldBeNull
1112
import io.kotest.matchers.shouldBe
1213
import io.kotest.matchers.string.shouldHaveLineCount
1314
import io.kotest.matchers.string.shouldNotContain
@@ -72,7 +73,7 @@ class BoardTest: FunSpec({
7273
test("from position") {
7374
val moewe = Piece(Moewe, Team.ONE)
7475
val board = Board(mutableMapOf(coords to moewe))
75-
board.movePiece(Move(coords, coords.copy(y = 7))) shouldBe null
76+
board.movePiece(Move(coords, coords.copy(y = 7))).shouldBeNull()
7677
board.shouldBeEmpty()
7778
}
7879
test("not from Robbe in position") {
@@ -81,9 +82,20 @@ class BoardTest: FunSpec({
8182
board.movePiece(Move(coords, Coordinates(2, 7))) shouldBe robbe
8283
board.shouldNotBeEmpty()
8384
}
84-
test("from tower") {
85-
val tower = Piece(Herzmuschel, Team.ONE, 2)
86-
val board = Board(mutableMapOf())
85+
context("from tower") {
86+
val board = makeBoard(0 y 1 to "M", 0 y 0 to "S2", 1 y 0 to "m", 1 y 1 to "r")
87+
test("not onto own") {
88+
shouldThrow<InvalidMoveException> {
89+
board.movePiece(Move(0 y 0, 0 y 1))
90+
}.mistake shouldBe MoveMistake.DESTINATION_BLOCKED
91+
}
92+
test("move tower") {
93+
board.movePiece(Move(0 y 0, 1 y 1)).shouldBeNull()
94+
}
95+
test("move onto tower") {
96+
// TODO that should be a double amber
97+
board.movePiece(Move(1 y 0, 0 y 0)).shouldBeNull()
98+
}
8799
}
88100
}
89101
}

0 commit comments

Comments
 (0)