Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
42 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package lila.round | ||
|
||
import lila.common.LightUser.IsBotSync | ||
import lila.game.{ Game, GameRepo, CrosstableApi } | ||
|
||
private final class BotFarming( | ||
crosstableApi: CrosstableApi, | ||
isBotSync: IsBotSync | ||
) { | ||
|
||
val SAME_PLIES = 20 | ||
val PREV_GAMES = 2 | ||
|
||
/* true if | ||
* - at least one bot | ||
* - rated | ||
* - recent game in same matchup has same first SAME_PLIES and same winner | ||
*/ | ||
def apply(g: Game): Fu[Boolean] = g.userIds.distinct match { | ||
case List(u1, u2) if g.finished && g.rated && g.userIds.exists(isBotSync) => | ||
crosstableApi(u1, u2) flatMap { | ||
_ ?? { ct => | ||
GameRepo.gamesFromSecondary(ct.results.reverse.take(PREV_GAMES).map(_.gameId)) map { | ||
_ exists { prev => | ||
g.winnerUserId == prev.winnerUserId && | ||
g.pgnMoves.take(SAME_PLIES) == prev.pgnMoves.take(SAME_PLIES) | ||
} | ||
} | ||
} | ||
} | ||
case _ => fuccess(false) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters