Release v1.0.47

This commit is contained in:
2026-11-02 15:51:41 +02:00
parent 6137923ca1
commit 52b0cb43c6
191 changed files with 34595 additions and 33605 deletions
@@ -1,5 +1,7 @@
package cc.skysparkle.matewave.spectate
import cc.skysparkle.matewave.security.toHex
/**
* What this device adds to its network announcement while it plays a watchable LAN game: a short
* tag shared by both players of the game, and, on the host, the spectator port. Older app versions
@@ -40,7 +42,7 @@ object SpectatorAdvert {
fun tagOf(gameId: String): String {
if (gameId.isEmpty()) return ""
val digest = java.security.MessageDigest.getInstance("SHA-256").digest(gameId.toByteArray(Charsets.UTF_8))
return digest.take(4).joinToString("") { "%02x".format(it) }
return digest.toHex(4)
}
private val TAG_PATTERN = Regex("^[0-9a-f]{8}$")
@@ -42,7 +42,7 @@ class SpectatorGame {
val sans = ArrayList<String>(snapshot.movesUci.size)
var last: Move? = null
for (uci in snapshot.movesUci) {
val move = resolve(board, uci) ?: return false
val move = Notation.fromUci(board, uci) ?: return false
sans.add(Notation.toSan(board, move))
board = ChessEngine.applyMove(board, move)
last = move
@@ -69,7 +69,7 @@ class SpectatorGame {
if (message.gameId != current.gameId) return Applied.NEEDS_RESYNC
if (current.result != null || message.ply <= current.ply) return Applied.IGNORED
if (message.ply != current.ply + 1) return Applied.NEEDS_RESYNC
val move = resolve(current.board, message.uci) ?: return Applied.NEEDS_RESYNC
val move = Notation.fromUci(current.board, message.uci) ?: return Applied.NEEDS_RESYNC
view = current.copy(
board = ChessEngine.applyMove(current.board, move),
movesUci = current.movesUci + move.toUci(),
@@ -95,14 +95,6 @@ class SpectatorGame {
if (clock == null || current.result != null) return
view = current.copy(clock = clock)
}
private fun resolve(board: Board, uci: String): Move? {
if (uci.length !in 4..5) return null
val candidate = runCatching { Move.fromUci(uci) }.getOrNull() ?: return null
if (candidate.from !in 0..63 || candidate.to !in 0..63) return null
val matches = ChessEngine.legalMoves(board).filter { it.from == candidate.from && it.to == candidate.to }
return matches.firstOrNull { it.promotion == candidate.promotion } ?: matches.firstOrNull()
}
}
/** Turns successive host snapshots into the messages spectators need to follow along. */