code golf

the previous code was good.
However it was creating futures that were not chained,
so it was superfluous. Just admit that these functions
are just fire-and-forget side effects,
and that the potential error conditions are discarded.
pull/4973/head
Thibault Duplessis 2019-04-08 08:03:02 +07:00
parent af944b082e
commit 4b37ce6852
1 changed files with 15 additions and 26 deletions

View File

@ -4,6 +4,7 @@ import akka.actor._
import scala.concurrent.duration._
import scala.concurrent.Promise
import chess.format.Uci
import lila.game.{ Game, GameRepo, Pov }
import lila.hub.actorApi.map.Tell
@ -22,11 +23,8 @@ final class BotPlayer(
if (!pov.isMyTurn) fufail("Not your turn, or game already over")
else {
val promise = Promise[Unit]
if (pov.player.isOfferingDraw && (offeringDraw contains false)) {
declineDraw(pov)
} else if (!pov.player.isOfferingDraw && (offeringDraw contains true)) {
offerDraw(pov)
}
if (pov.player.isOfferingDraw && (offeringDraw contains false)) declineDraw(pov)
else if (!pov.player.isOfferingDraw && (offeringDraw contains true)) offerDraw(pov)
system.lilaBus.publish(
Tell(pov.gameId, BotPlay(pov.playerId, uci, promise.some)),
'roundMapTell
@ -86,26 +84,17 @@ final class BotPlayer(
}
else fufail("This game cannot be resigned")
def declineDraw(pov: Pov): Funit = {
if (pov.game.drawable) {
if (pov.opponent.isOfferingDraw) fuccess {
system.lilaBus.publish(
Tell(pov.gameId, DrawNo(pov.playerId)),
'roundMapTell
)
}
else fufail("The opponent isn't offering a draw")
} else fufail("This game cannot be drawn")
}
def declineDraw(pov: Pov): Unit =
if (pov.game.drawable && pov.opponent.isOfferingDraw)
system.lilaBus.publish(
Tell(pov.gameId, DrawNo(pov.playerId)),
'roundMapTell
)
def offerDraw(pov: Pov): Funit =
if (pov.game.drawable) fuccess {
if (pov.game.playerCanOfferDraw(pov.color) && pov.isMyTurn) {
system.lilaBus.publish(
Tell(pov.gameId, DrawYes(pov.playerId)),
'roundMapTell
)
} else fufail("You cannot offer a draw")
}
else fufail("This game cannot be drawn")
def offerDraw(pov: Pov): Unit =
if (pov.game.drawable && pov.game.playerCanOfferDraw(pov.color) && pov.isMyTurn)
system.lilaBus.publish(
Tell(pov.gameId, DrawYes(pov.playerId)),
'roundMapTell
)
}