diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8872523b..5fb2c4ff 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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' diff --git a/build.gradle.kts b/build.gradle.kts index 2f8658b6..628f601d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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") diff --git a/src/main/kotlin/Statistics.kt b/src/main/kotlin/Statistics.kt index 9c1cc00a..c38a5c6c 100644 --- a/src/main/kotlin/Statistics.kt +++ b/src/main/kotlin/Statistics.kt @@ -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, @@ -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() + 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) { diff --git a/src/test/kotlin/Test.kt b/src/test/kotlin/Test.kt new file mode 100644 index 00000000..1ab48cfc --- /dev/null +++ b/src/test/kotlin/Test.kt @@ -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) + } +}