fix '(' and ')' error

This commit is contained in:
2022-06-14 12:05:31 +08:00
parent 8838330f0b
commit ad5c9866f7
2 changed files with 6 additions and 3 deletions

View File

@ -30,13 +30,14 @@ object PluginMain : KotlinPlugin(
"请用以上四组数字组合成结果为24的算式以“答”开头验证" "请用以上四组数字组合成结果为24的算式以“答”开头验证"
} }
startsWith("") quoteReply { startsWith("") quoteReply {
val game = games[this.sender.id] val game = games[sender.id]
if (game == null) { if (game == null) {
"你还没有抽数字哦说“24点”来开始游戏吧" "你还没有抽数字哦说“24点”来开始游戏吧"
} else { } else {
try { try {
val result = game.evaluate(message.contentToString().removePrefix("").trim()) val result = game.evaluate(message.contentToString().removePrefix("").trim())
if (result == 24.0) { if (result == 24.0) {
games.remove(sender.id)
"恭喜你,答对了!" "恭喜你,答对了!"
} else { } else {
"答错了,计算结果为 $result" "答错了,计算结果为 $result"

View File

@ -21,8 +21,10 @@ class Point24 {
) )
fun evaluate(expression: String): Double { fun evaluate(expression: String): Double {
val expr = expression.replace('', '(').replace('', ')')
val tokens = ShuntingYard.convertToRPN( val tokens = ShuntingYard.convertToRPN(
expression, expr,
null, null,
mapOf(), mapOf(),
null, null,
@ -47,7 +49,7 @@ class Point24 {
if (nums.isNotEmpty()) if (nums.isNotEmpty())
throw IllegalArgumentException("必须使用所有数值") throw IllegalArgumentException("必须使用所有数值")
return ExpressionBuilder(expression) return ExpressionBuilder(expr)
.implicitMultiplication(false) .implicitMultiplication(false)
.build() .build()
.evaluate() .evaluate()