Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several small update bump version #430

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ lazy val scalachess = Project("scalachess", file(".")).settings(
)

ThisBuild / organization := "org.lichess"
ThisBuild / version := "15.3.5"
ThisBuild / version := "15.3.6"
ThisBuild / scalaVersion := "3.3.0"
ThisBuild / licenses += "MIT" -> url("https://opensource.org/licenses/MIT")

Expand Down
18 changes: 17 additions & 1 deletion src/main/scala/ByColor.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package chess

import cats.{ Applicative, Eq }
import cats.{ Applicative, Eq, Functor, Monoid }
import cats.syntax.all.*
import scala.annotation.targetName
import alleycats.Zero

case class ByColor[A](white: A, black: A):

Expand Down Expand Up @@ -78,9 +79,24 @@ case class ByColor[A](white: A, black: A):
object ByColor:
def apply[A](a: A): ByColor[A] = ByColor(a, a)
def apply[A](f: Color => A): ByColor[A] = ByColor(white = f(White), black = f(Black))
def apply[F[_], A](f: Color => F[A]): Applicative[F] ?=> F[ByColor[A]] =
(f(White), f(Black)).mapN(ByColor(_, _))

given [A: Eq]: Eq[ByColor[A]] with
def eqv(x: ByColor[A], y: ByColor[A]) =
x.white === y.white && x.black === y.black

given [A: Zero]: Zero[ByColor[A]] with
def zero = ByColor(Zero[A].zero)

given [A: Monoid]: Monoid[ByColor[A]] with
def empty = ByColor(Monoid[A].empty)
def combine(x: ByColor[A], y: ByColor[A]) =
ByColor(Monoid[A].combine(x.white, y.white), Monoid[A].combine(x.black, y.black))

given Functor[ByColor] with
def map[A, B](fa: ByColor[A])(f: A => B): ByColor[B] = fa.map(f)

extension [A](bc: ByColor[IterableOnce[A]]) def flatten: List[A] = bc.all.flatten

extension [A](p: (A, A)) def asByColor: ByColor[A] = ByColor(p._1, p._2)
2 changes: 1 addition & 1 deletion src/main/scala/Hash.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ object Hash extends OpaqueInt[Hash]:
data.pockets
.mapWithColor: (color, pocket) =>
val colorshift = color.fold(79, -1)
pocket.map((role, size) => crazyPocketMask(role, colorshift, size))
pocket.flatMap((role, size) => crazyPocketMask(role, colorshift, size))
.flatten
.computeHash(hcrazypromotions)

Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/Role.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ sealed trait Role:
lazy val forsythUpper: Char = forsyth.toUpper
lazy val pgn: Char = forsythUpper
lazy val name = toString.toLowerCase
inline def forsythBy(color: Color): Char =
if color.white then forsythUpper else forsyth

sealed trait PromotableRole extends Role

Expand Down
7 changes: 5 additions & 2 deletions src/main/scala/variant/Crazyhouse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ case object Crazyhouse
def store(piece: Piece): Pockets =
pockets.update(!piece.color, _.store(piece.role))

def forsyth = pockets.white.forsythUpper + pockets.black.forsyth
def forsyth = pockets.reduce(_.forsythUpper + _.forsyth)

case class Pocket(pawn: Int, knight: Int, bishop: Int, rook: Int, queen: Int):

Expand Down Expand Up @@ -228,9 +228,12 @@ case object Crazyhouse
case Queen => f(queen).map(x => copy(queen = x))
case King => None

def map[B](f: (Role, Int) => Option[B]): List[B] =
def flatMap[B](f: (Role, Int) => IterableOnce[B]): List[B] =
List(f(Pawn, pawn), f(Knight, knight), f(Bishop, bishop), f(Rook, rook), f(Queen, queen)).flatten

def map[B](f: (Role, Int) => B): List[B] =
List(f(Pawn, pawn), f(Knight, knight), f(Bishop, bishop), f(Rook, rook), f(Queen, queen))

object Pocket:
val empty = Pocket(0, 0, 0, 0, 0)
def apply(roles: List[Role]): Pocket =
Expand Down