Blame users on ai games

This commit is contained in:
Thibault Duplessis 2012-05-18 22:40:40 +02:00
parent b988e6e774
commit 3788c1e292
6 changed files with 25 additions and 11 deletions

View file

@ -38,7 +38,8 @@ final class CoreEnv private (application: Application, val settings: Settings) {
mongodb = mongodb.apply _,
gameRepo = game.gameRepo,
timelinePush = timeline.push.apply,
ai = ai.ai)
ai = ai.ai,
dbRef = user.userRepo.dbRef)
lazy val timeline = new lila.timeline.TimelineEnv(
settings = settings,

View file

@ -47,6 +47,10 @@ case class DbPlayer(
def isUser(u: User) = user.fold(_.getId == u.id, false)
def withUser(u: User, ref: DBRef) = copy(
elo = u.elo.some,
user = ref.some)
def wins = isWinner getOrElse false
def hasMoveTimes = moveTimes.size > 10

View file

@ -3,16 +3,19 @@ package setup
import http.Context
import game.{ DbGame, GameRepo, Pov }
import user.User
import chess.{ Game, Board }
import ai.Ai
import com.mongodb.DBRef
import scalaz.effects._
final class Processor(
configRepo: UserConfigRepo,
gameRepo: GameRepo,
timelinePush: DbGame IO[Unit],
ai: () Ai) {
ai: () Ai,
dbRef: User DBRef) {
def ai(config: AiConfig)(implicit ctx: Context): IO[Pov] = for {
_ ctx.me.fold(
@ -20,7 +23,9 @@ final class Processor(
io()
)
pov = config.pov
game = pov.game
game = ctx.me.fold(
user pov.game.updatePlayer(pov.color, _.withUser(user, dbRef(user))),
pov.game)
_ gameRepo insert game
_ game.variant.standard.fold(io(), gameRepo saveInitialFen game)
_ timelinePush(game)

View file

@ -1,19 +1,22 @@
package lila
package setup
import com.mongodb.casbah.MongoCollection
import scalaz.effects._
import core.Settings
import game.{ DbGame, GameRepo }
import ai.Ai
import user.User
import com.mongodb.casbah.MongoCollection
import scalaz.effects._
import com.mongodb.DBRef
final class SetupEnv(
settings: Settings,
mongodb: String MongoCollection,
gameRepo: GameRepo,
timelinePush: DbGame IO[Unit],
ai: () Ai) {
ai: () Ai,
dbRef: User DBRef) {
import settings._
@ -26,5 +29,6 @@ final class SetupEnv(
configRepo = configRepo,
gameRepo = gameRepo,
timelinePush = timelinePush,
ai = ai)
ai = ai,
dbRef = dbRef)
}

View file

@ -10,8 +10,8 @@ import scalaz.effects._
import com.roundeights.hasher.Implicits._
class UserRepo(
collection: MongoCollection,
val dbRef: User => DBRef) extends SalatDAO[User, ObjectId](collection) {
collection: MongoCollection,
val dbRef: User DBRef) extends SalatDAO[User, ObjectId](collection) {
def user(userId: String): IO[Option[User]] = user(new ObjectId(userId))

2
todo
View file

@ -15,7 +15,7 @@ prevent cheaters from joining the game
translate "view rematch"
translate clock name
start chess960 after both player move http://fr.lichess.org/forum/lichess-feedback/clock-fairness-in-chess960-games
elo floor 800
next deploy:
db.user.update({},{$unset:{isOnline: true}}, false, true)