Skip to content

Commit db8f59a

Browse files
committed
refactor(plugin): swap x and y coordinates
Thus the teams will be pitted left against right rather than top vs bottom.
1 parent 28fbf4e commit db8f59a

File tree

4 files changed

+22
-25
lines changed

4 files changed

+22
-25
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ data class Board(
4545
* @return number of ambers */
4646
fun checkAmber(position: Coordinates): Int =
4747
piecePositions[position]?.let { piece ->
48-
arrayOf(piece.isAmber, piece.type.isLight && position.y == piece.team.opponent().startLine)
48+
arrayOf(piece.isAmber, piece.type.isLight && position.x == piece.team.opponent().startLine)
4949
.sumBy { if (it) 1 else 0 }
5050
.also { if (it > 0) piecePositions.remove(position) }
5151
} ?: 0
@@ -116,8 +116,8 @@ data class Board(
116116
}
117117

118118
@JvmStatic
119-
fun createField(team: ITeam, x: Int, type: PieceType) =
120-
Coordinates(if (team.index == 0) x else boardrange.last - x, team.startLine) to Piece(type, team)
119+
fun createField(team: ITeam, y: Int, type: PieceType) =
120+
Coordinates(team.startLine, if (team.index == 0) y else boardrange.last - y) to Piece(type, team)
121121
}
122122
}
123123

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import sc.api.plugins.Team
77

88
enum class PieceType(val char: Char, vararg val possibleMoves: Vector) {
99
/** Bewegt sich nur diagonal vorwärts. */
10-
Herzmuschel('H', Vector(1, 1), Vector(-1, 1)),
10+
Herzmuschel('H', Vector(1, 1), Vector(1, -1)),
1111
/** Bewegt sich nur auf Nachbarfelder. */
1212
Moewe('M', *Vector.cardinals),
1313
/** Bewegt sich diagonal oder vorwärts. */
14-
Seestern('S', *Vector.diagonals, Vector(0, 1)),
14+
Seestern('S', *Vector.diagonals, Vector(1, 0)),
1515
/** Wie ein Springer im Schach. Einzige nicht-Leichtfigur */
1616
Robbe('R', *Vector.diagonals.flatMap { listOf(it.copy(dx = it.dx * 2), it.copy(dy = it.dy * 2)) }.toTypedArray());
1717

@@ -32,7 +32,7 @@ data class Piece(
3232
@XStreamAsAttribute val count: Int = 1,
3333
) {
3434
val possibleMoves
35-
get() = type.possibleMoves.map { it.copy(dy = it.dy * team.direction) }
35+
get() = type.possibleMoves.map { it.copy(dx = it.dx * team.direction) }
3636

3737
val isAmber
3838
get() = count >= 3

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

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import io.kotest.matchers.maps.shouldBeEmpty
99
import io.kotest.matchers.maps.shouldHaveSize
1010
import io.kotest.matchers.shouldBe
1111
import io.kotest.matchers.string.shouldHaveLineCount
12-
import io.kotest.matchers.string.shouldNotContain
12+
import io.kotest.matchers.string.shouldMatch
1313
import sc.api.plugins.Team
1414
import sc.plugin2022.PieceType.*
1515
import sc.plugin2022.util.Constants
@@ -22,7 +22,7 @@ class BoardTest: FunSpec({
2222
test("does not misplace pieces") {
2323
generatedBoard shouldHaveSize Constants.BOARD_SIZE * 2
2424
generatedBoard.keys.forAll {
25-
it.y shouldBeOneOf listOf(0, Constants.BOARD_SIZE - 1)
25+
it.x shouldBeOneOf listOf(0, Constants.BOARD_SIZE - 1)
2626
}
2727
generatedBoard.values shouldContainExactlyInAnyOrder values().flatMap { type ->
2828
Team.values().map { team ->
@@ -33,13 +33,10 @@ class BoardTest: FunSpec({
3333
test("is stringified apropriately") {
3434
val string = generatedBoard.toString()
3535
string shouldHaveLineCount 8
36+
val lineRegex = Regex("\\w\\w------------\\w\\w")
3637
val lines = string.lines()
37-
lines.first() shouldNotContain "-"
38-
lines.last() shouldNotContain "-"
39-
lines.first().reversed().toLowerCase() shouldBe lines.last()
40-
lines.subList(1, 7).forAll {
41-
it shouldBe "----------------"
42-
}
38+
lines.forAll { it shouldMatch lineRegex }
39+
lines.joinToString("") { it.substring(0, 2).toLowerCase() }.reversed() shouldBe lines.joinToString("") { it.takeLast(2) }
4340
}
4441
test("clones well") {
4542
val board = makeBoard(0 y 0 to "R", 1 y 2 to "m")
@@ -72,33 +69,33 @@ class BoardTest: FunSpec({
7269
context("amber") {
7370
context("from position") {
7471
test("not when reaching target line of opponent") {
75-
val board = makeBoard(0 y 6 to "m")
76-
board.movePiece(Move(0 y 6, 0 y 7)) shouldBe 0
72+
val board = makeBoard(6 y 0 to "m")
73+
board.movePiece(Move(6 y 0, 7 y 0)) shouldBe 0
7774
board shouldHaveSize 1
7875
}
7976
test("moewe") {
80-
val board = makeBoard(0 y 6 to "M")
81-
board.movePiece(Move(0 y 6, 0 y 7)) shouldBe 1
77+
val board = makeBoard(6 y 0 to "M")
78+
board.movePiece(Move(6 y 0, 7 y 0)) shouldBe 1
8279
board.shouldBeEmpty()
8380
}
8481
test("not for Robbe") {
85-
val board = makeBoard(0 y 6 to "R")
86-
board.movePiece(Move(0 y 6, 2 y 7)) shouldBe 0
82+
val board = makeBoard(6 y 0 to "R")
83+
board.movePiece(Move(6 y 0, 7 y 2)) shouldBe 0
8784
board shouldHaveSize 1
8885
}
8986
}
9087
context("from tower") {
91-
val board = makeBoard(0 y 1 to "M", 0 y 0 to "S2", 1 y 0 to "m", 1 y 1 to "r")
88+
val board = makeBoard(1 y 0 to "M", 0 y 0 to "S2", 0 y 1 to "m", 1 y 1 to "r")
9289
test("not onto own") {
9390
shouldThrow<InvalidMoveException> {
94-
board.movePiece(Move(0 y 0, 0 y 1))
91+
board.movePiece(Move(0 y 0, 1 y 0))
9592
}.mistake shouldBe MoveMistake.DESTINATION_BLOCKED
9693
}
9794
test("move tower") {
9895
board.movePiece(Move(0 y 0, 1 y 1)) shouldBe 1
9996
}
10097
test("move onto tower") {
101-
board.movePiece(Move(1 y 0, 0 y 0)) shouldBe 2
98+
board.movePiece(Move(0 y 1, 0 y 0)) shouldBe 2
10299
}
103100
}
104101
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class PieceTest: FunSpec({
2323
}
2424
}
2525
test("can't move backwards") {
26-
Piece(Herzmuschel, Team.ONE).possibleMoves shouldContainExactlyInAnyOrder listOf(Vector(1, 1), Vector(-1, 1))
27-
Piece(Seestern, Team.ONE).possibleMoves shouldContainExactlyInAnyOrder listOf(*Vector.diagonals, Vector(0, 1))
26+
Piece(Herzmuschel, Team.ONE).possibleMoves shouldContainExactlyInAnyOrder listOf(Vector(1, -1), Vector(1, 1))
27+
Piece(Seestern, Team.ONE).possibleMoves shouldContainExactlyInAnyOrder listOf(*Vector.diagonals, Vector(1, 0))
2828
}
2929
})

0 commit comments

Comments
 (0)