Skip to content

Commit cd615e6

Browse files
committed
feat(plugin25): revamp extended stats
1 parent 2ff9b09 commit cd615e6

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

plugin2025/src/main/kotlin/sc/plugin2025/GameState.kt

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import sc.plugin2025.GameRuleLogic.calculateCarrots
88
import sc.plugin2025.GameRuleLogic.calculateMoveableFields
99
import sc.plugin2025.util.HuIConstants
1010
import sc.shared.InvalidMoveException
11+
import kotlin.math.pow
12+
import kotlin.math.sqrt
1113

1214
/**
1315
* The GameState class represents the current state of the game.
@@ -42,6 +44,9 @@ data class GameState @JvmOverloads constructor(
4244
fun isAhead(player: Hare = currentPlayer) =
4345
player.position > player.opponent.position
4446

47+
fun isAhead(team: Team) =
48+
isAhead(getHare(team))
49+
4550
val currentField: Field?
4651
get() = currentPlayer.field
4752

@@ -115,12 +120,14 @@ data class GameState @JvmOverloads constructor(
115120
}
116121
}
117122
}
123+
118124
Field.MARKET -> {
119125
if(player.carrots >= 10)
120126
Card.values().map { arrayOf(it) }
121127
else
122128
listOf()
123129
}
130+
124131
else -> null
125132
}
126133

@@ -146,18 +153,20 @@ data class GameState @JvmOverloads constructor(
146153
}
147154
}
148155

149-
fun awardPositionFields() {
150-
when(currentField) {
156+
fun awardPositionFields(hare: Hare = currentPlayer) {
157+
when(hare.field) {
151158
Field.POSITION_1 -> {
152-
if(isAhead()) {
153-
currentPlayer.carrots += 10
159+
if(isAhead(hare)) {
160+
hare.carrots += 10
154161
}
155162
}
163+
156164
Field.POSITION_2 -> {
157-
if(!isAhead()) {
158-
currentPlayer.carrots += 30
165+
if(!isAhead(hare)) {
166+
hare.carrots += 30
159167
}
160168
}
169+
161170
else -> {}
162171
}
163172
}
@@ -180,7 +189,11 @@ data class GameState @JvmOverloads constructor(
180189

181190
/** Basic validation whether a field may be entered via a jump that is not backward.
182191
* Does not validate whether a card can be played on hare field. */
183-
fun validateTargetField(newPosition: Int, player: Hare = currentPlayer, carrots: Int = player.carrots): HuIMoveMistake? {
192+
fun validateTargetField(
193+
newPosition: Int,
194+
player: Hare = currentPlayer,
195+
carrots: Int = player.carrots,
196+
): HuIMoveMistake? {
184197
if(newPosition == 0)
185198
return HuIMoveMistake.CANNOT_ENTER_FIELD
186199
val field = board.getField(newPosition)
@@ -250,7 +263,22 @@ data class GameState @JvmOverloads constructor(
250263
getHare(team).let { intArrayOf(it.position, it.carrots) }
251264

252265
override fun getPointsForTeamExtended(team: ITeam): IntArray =
253-
getHare(team).let { intArrayOf(if(it.inGoal) 100 else 0, it.position, it.carrots, -it.salads * 2, it.getCards().size * 5) }
266+
getHare(team).copy().let { hare ->
267+
awardPositionFields(hare)
268+
// 1 at the beginning, 12 at the end
269+
val positionFactor = 1.04.pow(hare.position)
270+
intArrayOf(
271+
when {
272+
hare.inGoal -> 100
273+
hare.field == Field.SALAD -> 3
274+
else -> 0
275+
},
276+
hare.position,
277+
((55 - hare.position.toDouble()).pow(0.3) / 2 * sqrt(hare.carrots.toDouble())).toInt(),
278+
-(hare.salads * positionFactor).toInt(),
279+
(hare.getCards().size * (10 - positionFactor) / 3).toInt(),
280+
)
281+
}
254282

255283
override fun teamStats(team: ITeam) =
256284
getHare(team).run {

0 commit comments

Comments
 (0)