<commit_before>package lila.playban

import chess.{ Color, Speed }
import scala.math.{ log10, sqrt }

import lila.game.Game

case class RageSit(counter: Int) extends AnyVal {
  def isBad      = counter <= -40
  def isVeryBad  = counter <= -80
  def isTerrible = counter <= -160

  def goneWeight: Float =
    if (!isBad) 1f
    else (1 - 0.7 * sqrt(log10(-(counter / 10) - 3))).toFloat atLeast 0.1f

  def counterView = counter / 10
}

object RageSit {
  val empty = RageSit(0)

  sealed trait Update
  case object Noop       extends Update
  case object Reset      extends Update
  case class Inc(v: Int) extends Update

  def imbalanceInc(game: Game, loser: Color) = Inc {
    {
      import chess.variant._
      (game.chess.board.materialImbalance, game.variant) match {
        case (_, Antichess | Crazyhouse | Horde) => 0
        case (a, _) if a >= 4                    => 1
        case (a, _) if a <= -4                   => -1
        case _                                   => 0
      }
    } * {
      if (loser.white) 1 else -1
    } * {
      if (game.speed <= Speed.Bullet) 5
      else if (game.speed == Speed.Blitz) 10
      else 15
    }
  }

  def redeem(game: Game): Inc = Inc {
    game.speed match {
      case s if s < Speed.Bullet => 0
      case Speed.Bullet          => scala.util.Random.nextInt(1)
      case Speed.Blitz           => 1
      case _                     => 2
    }
  }
}<commit_msg>Calculate antichess material imbalance ornicar/scalachess#186<commit_after>package lila.playban

import chess.{ Color, Speed }
import scala.math.{ log10, sqrt }

import lila.game.Game

case class RageSit(counter: Int) extends AnyVal {
  def isBad      = counter <= -40
  def isVeryBad  = counter <= -80
  def isTerrible = counter <= -160

  def goneWeight: Float =
    if (!isBad) 1f
    else (1 - 0.7 * sqrt(log10(-(counter / 10) - 3))).toFloat atLeast 0.1f

  def counterView = counter / 10
}

object RageSit {
  val empty = RageSit(0)

  sealed trait Update
  case object Noop       extends Update
  case object Reset      extends Update
  case class Inc(v: Int) extends Update

  def imbalanceInc(game: Game, loser: Color) = Inc {
    {
      import chess.variant._
      (game.chess.board.materialImbalance, game.variant) match {
        case (_, Crazyhouse | Horde) => 0
        case (a, _) if a >= 4                    => 1
        case (a, _) if a <= -4                   => -1
        case _                                   => 0
      }
    } * {
      if (loser.white) 1 else -1
    } * {
      if (game.speed <= Speed.Bullet) 5
      else if (game.speed == Speed.Blitz) 10
      else 15
    }
  }

  def redeem(game: Game): Inc = Inc {
    game.speed match {
      case s if s < Speed.Bullet => 0
      case Speed.Bullet          => scala.util.Random.nextInt(1)
      case Speed.Blitz           => 1
      case _                     => 2
    }
  }
}
{'fraction_non_alphanumeric': 0.1097645429362881, 'fraction_numerical': 0.02873961218836565, 'mean_word_length': 1.7254716981132074, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4654297', 'n_tokens_mistral': 1031, 'n_tokens_neox': 933, 'n_words': 281}