mirror of
https://github.com/jie65535/mirai-console-j24-plugin.git
synced 2025-06-01 17:29:15 +08:00
fix '(' and ')' error
This commit is contained in:
parent
8838330f0b
commit
ad5c9866f7
@ -30,13 +30,14 @@ object PluginMain : KotlinPlugin(
|
||||
"请用以上四组数字组合成结果为24的算式,以“答”开头验证"
|
||||
}
|
||||
startsWith("答") quoteReply {
|
||||
val game = games[this.sender.id]
|
||||
val game = games[sender.id]
|
||||
if (game == null) {
|
||||
"你还没有抽数字哦,说“24点”来开始游戏吧"
|
||||
} else {
|
||||
try {
|
||||
val result = game.evaluate(message.contentToString().removePrefix("答").trim())
|
||||
if (result == 24.0) {
|
||||
games.remove(sender.id)
|
||||
"恭喜你,答对了!"
|
||||
} else {
|
||||
"答错了,计算结果为 $result"
|
||||
|
@ -21,8 +21,10 @@ class Point24 {
|
||||
)
|
||||
|
||||
fun evaluate(expression: String): Double {
|
||||
val expr = expression.replace('(', '(').replace(')', ')')
|
||||
|
||||
val tokens = ShuntingYard.convertToRPN(
|
||||
expression,
|
||||
expr,
|
||||
null,
|
||||
mapOf(),
|
||||
null,
|
||||
@ -47,7 +49,7 @@ class Point24 {
|
||||
if (nums.isNotEmpty())
|
||||
throw IllegalArgumentException("必须使用所有数值")
|
||||
|
||||
return ExpressionBuilder(expression)
|
||||
return ExpressionBuilder(expr)
|
||||
.implicitMultiplication(false)
|
||||
.build()
|
||||
.evaluate()
|
||||
|
Loading…
Reference in New Issue
Block a user