Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

勋章根据分数大小排序 #301

Merged
merged 4 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ jobs:
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Execute Gradle test
env:
GRADLE_OPTS: '-Xmx4g'
run: ./gradlew test

- name: Execute Gradle build
env:
GRADLE_OPTS: '-Xmx4g'
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ repositories {
}

dependencies {
testImplementation("junit:junit:4.9")
implementation("com.typesafe.akka:akka-actor_2.13:2.8.5")
implementation("io.netty:netty-all:4.1.108.Final")
implementation("io.ktor:ktor-server-netty:2.3.10")
Expand Down
29 changes: 28 additions & 1 deletion src/main/kotlin/Statistics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,11 @@ object Statistics {
playerInfoMap.keys.forEach {
playerInfoMap.computeIfPresent(it) { _, v ->
if (v.score <= 1) return@computeIfPresent null
val newTitle = v.title + getSeasonTitleByScore(v.maxScore)
v.copy(
winCount = 0,
gameCount = 0,
title = v.title + getSeasonTitleByScore(v.maxScore),
title = sortTitles(newTitle),
score = v.score / 2,
energy = v.energy.coerceAtLeast(10),
maxScore = v.score / 2,
Expand All @@ -342,6 +343,32 @@ object Statistics {
val totalPlayerGameCount: PlayerGameCount
get() = PlayerGameCount(totalWinCount.get(), totalGameCount.get())

fun getTitleRank(title: String): Int = when (title) {
"\u2B50" -> 1 // score >= 2900
"\uD83D\uDC51" -> 2 // score >= 1900
"\uD83D\uDCA0" -> 3 // score >= 1400
"\uD83D\uDC8D" -> 4 // score >= 920
"\uD83E\uDD47" -> 5 // score >= 520
else -> 6 // Lower than 520
}

fun sortTitles(titles: String): String {
val titleList = mutableListOf<String>()
var i = 0
while (i < titles.length) {
if (titles[i] == '\u2B50') {
// 如果是单字符 emoji(⭐)
titleList.add(titles[i].toString())
i += 1
} else {
// 处理其他双字符 emoji
titleList.add(titles.substring(i, i + 2))
i += 2
}
}
return titleList.sortedBy { getTitleRank(it) }.joinToString("")
}

private fun savePlayerInfo() {
val sb = StringBuilder()
for ((_, info) in playerInfoMap) {
Expand Down
12 changes: 12 additions & 0 deletions src/test/kotlin/Test.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.fengsheng

import org.junit.Assert.assertEquals
import org.junit.Test

class Test {
@Test
fun sortTitlesTest() {
val s = Statistics.sortTitles("💠👑🏅👑🏅💍💠🏅💠")
assertEquals("👑👑💠💠💠💍🏅🏅🏅", s)
}
}