GithubHelp home page GithubHelp logo

lichess-org / scalachess Goto Github PK

View Code? Open in Web Editor NEW
620.0 33.0 198.0 7.03 MB

Chess API written in scala. Immutable and free of side effects.

Home Page: https://lichess.org

License: MIT License

Scala 99.93% Python 0.07%
bitboard bitboard-datastructure chess functional-programming lichess scala-3

scalachess's Introduction

Continuous Integration

Chess API written in scala for lichess.org

It is entirely functional, immutable, and free of side effects.

INSTALL

Clone scalachess

git clone https://github.com/lichess-org/scalachess

Start sbt in scalachess directory

sbt

In the sbt shell, to compile scalachess, run

compile

To run the tests

testKit / test

To run benchmarks (takes more than 1 hour to finish):

bench / Jmh / run

Or to ouput a json file

bench / Jmh / run -rf json

To run quick benchmarks (results may be inaccurate):

bench / Jmh / run -i 1 -wi 1 -f1 -t1

To run benchmarks for a specific class:

bench / Jmh / run -rf json .*PlayBench.*

To run scalafmt and scalafix:

sbt prepare

scalachess's People

Contributors

antma avatar benediktwerner avatar clarkerubber avatar cxd4 avatar ddugovic avatar dignissimus avatar erdoganseref avatar fitztrev avatar fynsta avatar hanshoffrug avatar happy0 avatar isaacl avatar kaspervld avatar kraktus avatar lenguyenthanh avatar lovlas avatar m-dinhhoangviet avatar niklasf avatar ornicar avatar oziomajnr avatar psuter avatar scala-steward avatar srimethan avatar stscoundrel avatar superuser-does avatar thomas-daniels avatar tpsinnem avatar unihedro avatar veracion avatar ygyzys avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scalachess's Issues

chess.ClockTest failing

in the context of the Scala community build, I started seeing this failure happening (every run, not just intermittently):

[scalachess] [info]   multiple premoves with fast clock
[scalachess] [info]     + no lag
[scalachess] [error]     x no -> medium lag
[scalachess] [error]      5948 != 5932 (ClockTest.scala:122)
[scalachess] [error]     x no x4 -> big lag
[scalachess] [error]      5672 != 5648 (ClockTest.scala:125)

see e.g. the log at https://scala-ci.typesafe.com/job/scala-2.12.x-integrate-community-build/2327/consoleFull

for now I have dealt with it by freezing scalachess at revision a1c8abe, before the regression was introduced, but it would be nice if we could go back to tracking your master branch

Atomic version of OpeningDB

Historical sources like the atomic opening book that was popularly referenced: https://www.unix-ag.uni-kl.de/~chess/atomic/ have attempted to name variations and lines used in the opening, but they are known to be based on data from another version of Atomic and therefore not suitable for use of the Atomic of the variant being used here on lichess. Since atomic has its own gameplay and theory, I suggest generating an opening book and naming lines based on the nature and theory of the position instead of players except for stellar lines played by specific (and popular) lichess players.

Errors on running sbt

Anyone getting the same thing with [email protected]?

➜  scalachess git:(master) sbt
[info] Loading settings from plugins.sbt ...
[info] Loading project definition from /Users/steventsao/workspace/scalachess/project
[info] Updating {file:/Users/steventsao/workspace/scalachess/project/}scalachess-build...
[warn] 	::::::::::::::::::::::::::::::::::::::::::::::
[warn] 	::          UNRESOLVED DEPENDENCIES         ::
[warn] 	::::::::::::::::::::::::::::::::::::::::::::::
[warn] 	:: org.scalariform#sbt-scalariform;1.8.0: Resolution failed several times for dependency: org.scalariform#sbt-scalariform;1.8.0 {compile=[default(compile)]}::
[warn] 	1
[warn] 	1
[warn] 	1
[warn] 	::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn] 	Note: Some unresolved dependencies have extra attributes.  Check that these dependencies exist with the requested attributes.
[warn] 		org.scalariform:sbt-scalariform:1.8.0 (scalaVersion=2.12, sbtVersion=1.0)
[warn]
[warn] 	Note: Unresolved dependencies path:
[warn] 		org.scalariform:sbt-scalariform:1.8.0 (scalaVersion=2.12, sbtVersion=1.0) (/Users/steventsao/workspace/scalachess/project/plugins.sbt#L1-2)
[warn] 		  +- default:scalachess-build:0.1-SNAPSHOT (scalaVersion=2.12, sbtVersion=1.0)
[error] sbt.librarymanagement.ResolveException: unresolved dependency: org.scalariform#sbt-scalariform;1.8.0: Resolution failed several times for dependency: org.scalariform#sbt-scalariform;1.8.0 {compile=[default(compile)]}::
[error] 	1
[error] 	1
[error] 	1
[error]
[error] 	at sbt.internal.librarymanagement.IvyActions$.resolveAndRetrieve(IvyActions.scala:331)

Threefold repetition not including initial position

Just "moving" this bug: lichess-org/lila#7009 to this repository, in order to submit a Pull Request fixing it.

There is an old broken test that is commented "3fold on initial position - broken" that seems to be the exact functionality to fix.

It seems that the initial position is never added to the positionHashes in the History as this is only added in Move.finalizeAfterand Drop.finalizeAfterand is created with the default value of Array.empty when called via the usual Board.init(variant: Variant) that is called inside Game.apply(variant: chess.variant.Variant)

PGN format compliance

According to https://www.chessclub.com/user/help/PGN-spec, the 7 first (mandatory) headers are expected to be :

  1. Event (the name of the tournament or match event)
  2. Site (the location of the event)
  3. Date (the starting date of the game)
  4. Round (the playing round ordinal of the game)
  5. White (the player of the white pieces)
  6. Black (the player of the black pieces)
  7. Result (the result of the game)

Round is missing, for instance: http://fr.lichess.org/game/export/FGI5RzDc.pgn

[Event "Casual game"]
[Site "http://lichess.org/FGI5RzDc"]
[Date "2016.05.23"]
[White "ptitfred"]
[Black "tOk_W"]
[Result "0-1"]
[WhiteElo "1422"]
[BlackElo "1500"]
[PlyCount "38"]
[Variant "Standard"]
[TimeControl "240+0"]
[ECO "D35"]
[Opening "Queen's Gambit Declined: Normal Defense"]
[Termination "Normal"]
[Annotator "lichess.org"]

1. d4 d5 2. c4 e6 3. Nc3 Nf6 { D35 Queen's Gambit Declined: Normal Defense } 4. a3 Bd6 5. Nf3 O-O 6. Ne5 Nbd7 7. Bf4 Bxe5 8. dxe5 Ne8 9. e4 dxc4 10. Bxc4 Qh4 11. Qf3 c6 12. a4 Nb6 13. g3 Qe7 14. Qg4 Nxc4 15. Bh6 Qb4 16. Qxg7+ Nxg7 17. Bxg7 Kxg7 18. O-O Qxb2 19. Ne2 Qxe2 { White resigns } 0-1

According to the spec, we could simply put [Round "-"]

The Round tag value gives the playing round for the game. In a match
competition, this value is the number of the game played. If the use of a
round number is inappropriate, then the field should be a single hyphen
character. If the round is unknown, a single question mark should appear as
the tag value.

Berserk increment penalty overly harsh

What's the background behind having berserkers lose all increment? It makes berserking inc tourneys less beneficial than their non-inc brethren.

Consider changing berserk to inc/2, rounded down, so:

  • 1+2 => 30s+1
  • 1+1 => 30s+0

Berserking 1+2 does not behave as expected

From lichess help:

Going Berserk in time controls with an increment also cancels the increment. (1+2 is an exception, it gives 1+0)

However, berserking 1+2 actually gives 30s+0. From clock.beserkPenalty:
if (iniTime < incTime / 2) 0 else iniTime / 2

For 1+2, the checks if 60 < 80 / 2.

Exploded king atomic position yields legal moves

I would like to use your library from Javascript. I'm aware of https://github.com/veloce/scalachessjs, but it is a WebWorker and also I need some additional functionality ( for example listing legal moves in a position ), which it does not have.

To this end I compiled your library to Javascript myself:

https://github.com/hyperbotauthor/scalachess

The legal moves for a position I determine like this:

https://github.com/hyperbotauthor/scalachess/blob/dd88ce2a41e62ec7a6bad16f04d98c65f37aade0/src/main/scala/ChessApp.scala#L51

I created a minimal GUI to test legal move generation:

https://scalachess.netlify.app

If you select atomic from the variant combo, and make the moves e2e3, e7e6, d1f3, d7d6, f3f7 ( either by clicking or by selecting from legal move list ), this should end the game due to black king being exploded and there should be no legal moves. Yet the position lists legal moves, which are just pseudo legal, as black has no king.

img

Change specs2 to specs2-core

specs2 tests failed
maybe this is better

libraryDependencies ++= List(
  "org.scalaz" %% "scalaz-core" % "7.1.1",
  "org.specs2" %% "specs2-core" % "3.0.1" % "test",
  "com.github.ornicar" %% "scalalib" % "5.2",
  "joda-time" % "joda-time" % "2.7",
  "org.joda" % "joda-convert" % "1.7"
)

50 moves rules doesn't include castling

Looking at this code in Move.scala (which I think is responsible for keeping a history of moves which possibly fall under the 50 moves rule) I think there is a bug.

Castling shouldn't reset the history counting (thus preventing the 50 moves rule from getting applied). The FIDE rules (9.3) for the 50 moves rule only mention "pawn movement" and "capture".


As I don't fully understand the code I'm unsure whether the promotes check is included there correctly. Is it needed because at the time of the check piece is Pawn isn't true anymore as the pawn was promoted and thus promotes is checked to check for a special kind of "pawn movement"?


This report is also related to the discussion in the 50 moves rule thread on lichess.org

situation calced twice in applyMove

In applyMove we calc situation for a temporary Game object and then return a new object which also calcs situation.

Perhaps we need a global situation cache instead of a lazy val?

Crazyhouse insufficient material draws

In Crazyhouse, scalachess currently autodraws the game when there is insufficient mating material on the board. This behavior is incorrect, since a player could have material that they can place, and in these cases, the player can still mate by placing material on the board.

Here is an example of the incorrect behaviour: https://lichess.org/IVDQElJG

In Crazyhouse, insufficient mating material draws should never occur, since material never leaves the game state (it can always be placed back). This means that at least one player is always able to mate the other.

Autodraw: Check for material insufficient

TLDR;

  1. If (excluding the kings) there are 2 pieces (or more) on the board (they don't have to be of the same color) the position is not a draw.
  2. If (excluding the kings) there are only bishops left, all residing on the same color, the position is a draw.
  3. Make sure 2. prevails over 1.

After the discussion in the 50 moves rule thread on lichess.org I took a closer look and found that the hasEnoughMaterialToMate check in Board.scala is inaccurate.

It will incorrectly cause an "autodraw" in many positions while missing other positions where it could declare "autodraw".

e.g. It's incorrect to "autoclaim" draw in a king+knight vs king+bishop endgame.

Black to move. Mate in 1
8/8/8/8/4n3/7k/8/6BK b - - 0 1
8/8/8/8/4n3/7k/8/6BK b - - 0 1

This happens because the check finds that each color, on it's own, hasn't enough material to mate but fails to recognize that if one side plays badly a mate is still possible (see above).

I found The Insufficient Mating Material Rule on E4EC to be a good resource to quickly get a good overview of various cases where a draw could/should be declared automatically.

I suggest to just slightly fix the code to take into account the first 4 cases on the site linked to above.


The other cases sometimes are very intricate and are inaccessible to straight forward code-checks and thus only recognizable by a human or with a non trivial amount of an AI evaluating the position (and AI is ill-suited to recognize certain types of drawn positions where they just play it out until the 50 moves rules hits home)

These cases end in a draw naturally anyway when play just continues (some people will of course still lose such games because they can forfeit on time, but I guess that can be neglected)

How to play with machine?

As I understand, scalachess validates moves, so human can play with human.

Does scalachess provides a generic AI feature for all the chess variants it supports? Or do I have to create AI for each variant by myself?

Bug in PGN parser

I unfortunately do not understand the PGN parser enough to provide a fix. It fails to parse long castles written as 0-0-0 (zeroes). All other castles seem to be parsed correctly.

My branch bug/parser-long-castle has a new test that exposes the bug.

allow parsing pgn with non-nag glyph annotations

  • URL to the bug: https://lichess.org/study/

  • Problem description: when trying to import PGN into Lichess study, that contains non-standard glyph annotations like 8. Bxd3?? ∓, the PGN would fail to parse and fail.

  • How to reproduce:

Trying to import this PGN into a new study chapter:

1. e4 e5 2. Nf3 d5 3. exd5 e4 4. Nd4 Qxd5 5. c3 Bc5 6. Nb3 Nf6 7. d4 exd3 8.
Bxd3?? ∓ {BLUNDER (-4.28)} ({(+0.33) The best move was} 8. Nxc5 Qxc5 9. Bxd3 Bg4
10. Qb3 Qe5+ 11. Be3 Qd5 12. Qxd5 Nxd5 13. Bd2 Nc6 14. Na3 Ne5 15. Bc2 O-O-O 16.
f3 Be6 17. O-O-O a6) 8... Qxg2 9. Rf1 {INACCURACY (-4.62)} ({(-3.60) The best
move was} 9. Qe2+ Kd8 10. Qf1 Bxf2+ 11. Kd1 Bh3 12. Kc2 Qxf1 13. Rxf1 Bxf1 14.
Bxf1 a5 15. a4 Re8 16. Bg5 Nd7 17. Bg2 Re2+ 18. N1d2 Be3 19. Bxb7) 9... Bb6 10.
Bf4? {MISTAKE (-7.01)} ({(-4.43) The best move was} 10. Qe2+ Kd8 11. Kd1 Re8 12.
Qd2 Bg4+ 13. f3 Bxf3+ 14. Rxf3 Qxf3+ 15. Be2+ Qd5 16. Bf3 Qxd2+ 17. N1xd2 c6 18.
Nc4 Nbd7 19. Bg5 h6 20. Bxf6+ Nxf6 21. Kc2 Kc7 22. Rd1 Rad8 23. Rxd8 Rxd8 24. h4
Re8) (10. Bf4 O-O 11. Qd2 Bg4 12. f3 Re8+ 13. Kd1 Bxf3+ 14. Kc1 Nc6 15. Qxg2
Bxg2 16. N1d2 Rad8 17. Kc2 Rxd3 18. Kxd3 Bxf1+ 19. Rxf1 Nd5 20. Bg3 Re3+ 21. Kc4
Rxg3 22. hxg3 Ne3+ 23. Kb5 a6+ 24. Ka4 Nxf1) 1-0
  • Expected to happen: game imported into the study, with non-NAG glyph annotation ignored.
  • What happened: import fails. User need to manually remove the glyph annotations.

I understand that NAG annotation is the standard way to do glyph annotations, however, can we ignore the non-standard symbols, and still parse the PGN with best effort? This would allow users to import chess.com games without issues.

Currently, users either has to manually find and remove all such symbols, or using a 3rd party softward to import then export the PGN.

Can't compile due to dependency

Hi,

I am not able to compile due to scala_llib dependency cannot be found. How can I resolve it?

Thanks,
Andrew

[warn] http://oss.sonatype.org/content/repositories/releases/com/github/ornicar/scalalib_2.11/5.0/scalalib_2.11-5.0.pom
[warn] ==== awesomepom: tried
[warn] https://raw.github.com/jibs/maven-repo-scala/master/com/github/ornicar/scalalib_2.11/5.0/scalalib_2.11-5.0.pom
[info] Resolving jline#jline;2.12 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: com.github.ornicar#scalalib_2.11;5.0: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[trace] Stack trace suppressed: run last *:update for the full output.
error sbt.ResolveException: unresolved dependency: com.github.ornicar#scalalib_2.11;5.0: not found
[error] Total time: 5 s, completed Oct 2, 2014 8:12:47 AM

Openings detection (ECO)

Hi,

The detection of openings (see https://github.com/ornicar/scalachess/blob/master/src/main/scala/Openings.scala) can be improved.

The detection is based on an exact comparison of the first moves, but some subtle deviations can lead to the same exact position and opening.

For instance ("C10", "French Defence, Rubinstein Variation", "e4 e6 d4 d5 Nc3 dxe4"),
if you play Nd2 (instead of Nc3) then it is not detected as "Rubinstein Variation" (but as nothing)

The issue is not critical at all, and the current solution has the merit of being elegant, simple, and fast.

Best,

Mathieu

Include server time with game state returned by the board stream endpoint

I'm trying to implement a custom client for playing games, and it occurred to me that it would be useful if there was a server time included with each object returned by the board stream API.

This would allow updating the client game clock with the correct time regardless of any hiccups / delay in getting the message.

GAME_TIME = REPORTED_GAME_TIME + (NOW - LICHESS_SERVER_TIME)

scalalib is no longer available through iliaz.com

The website scala.iliaz.com redirects to a message stating it is for sale, which in turn makes scalalib not available to SBT.

As a workaround, the scalalib project can be checked out from github and published locally via:

sbt publishLocal

hope you can find someplace else to host scalalib.

Are new Variants accepted if I send a PR?

I like lichess, been playing the app for a couple months and just realized the whole thing is open source. I have an idea for a chess variant I like to call Mimic. I'm a developer, but I haven't done scala yet (it's on my list of things to try). I'd be happy to write up a PR for the below, and wanted to first check and see if this idea at least has a chance of getting merged into the project before I dig in and figure out the implementation.

The rule concepts I have could go one of a two ways, with a potential configuration option.

*After perusing wikipedia to brush up on my known chess variants, the closest I see is Plunder Chess
*If my proposed Mimic variant isn't interesting enough to warrant building in, is there a different known variant you'd want? I'd still like to play around with this project a bit, and I think variants would be fun.

Possible Ruleset A: (simplest)

When a pawn captures, it turns into the piece that it captured. No more En passant but you get another back row piece. (this becomes much more interesting if it applies to all pieces -- see third configurable option)

Possible Ruleset B: (stacking)

When a pawn captures, it adds the movement attributes of the piece it captured to its own.
Movement properties stack.
So if a pawn captures a knight and then a queen, it would be able to do the knight movements, queen movements, and pawn movements, but the attribute of hopping from the knight wouldn't stack onto the queen style movements.
If a pawn captures a bishop, it could still move forward and En passant (pawn movements), as well as move diagonally (bishop movements)

Possible Ruleset: (configureable - built off A or B)

Either of the above rulesets, but allow players to configure which pieces it applies to ie: queens and knights, or pawns and king, or any combination or all pieces

A

If the simplest ruleset was used (A), then a queen capturing a pawn would become a pawn. If pawns weren't configured, it'd be stuck as a pawn.

B

If the stacking ruleset was used (B), then a queen capturing a knight would still be a queen, but also have the movement of a knight.

possible issues

if doing B, there's the issue of how to change the display to the user to show how any given piece can move. Currently thinking showing multiple pieces on a single square, but then would have to scale down the size of the image.

upgrade to specs2 4.x?

we probably will never support specs2 3.x in the Scala 2.13 community build, so this upgrade is required for scalachess to stay in the community build, long-term

some source changes are apparently required; I saw many errors like

[scalachess] [error] /Users/tisue/community.213/target-0.9.10/project-builds/scalachess-a04a00d4022de36ef6909662a3ae9682e7d09632/src/test/scala/BoardTest.scala:60:14: not found: value beSuccess
[scalachess] [error]       ) must beSuccess.like {
[scalachess] [error]              ^
[scalachess] [error] /Users/tisue/community.213/target-0.9.10/project-builds/scalachess-a04a00d4022de36ef6909662a3ae9682e7d09632/src/test/scala/BoardTest.scala:70:14: not found: value beFailure
[scalachess] [error]       ) must beFailure

Training Rating drop despite getting the puzzle correct

My training rating went down, despite getting the puzzle correct:

image

As you can see, it's supposed to add 7 to my training rating, but the rating seems to have gone down by 1. If you want to look closer at my user, my nick is "siddhartha13". The puzzle solved is # 83713.

Win awarded despite forced mate for other side

I saw #163 and I got wondering if I could make a crazy position where it was a truly forced (ie from both sides) mate and would that be detected.

A little bit later I had made a game to test and found that lichess doesn't detect it correctly and awards a win to black who cannot possibly win if white makes a move.

I don't expect there is an easy solution to this and situations like this probably will never happen in a real game, but I wanted to show that insufficient material rules are not simple to detect.

http://www.e4ec.org/immr.html additionally contains some forced draws which I don't suspect is detected either.

Variant request: Marseillais chess

Hello, is it possible to implement this? https://en.wikipedia.org/wiki/Marseillais_chess
I feel it will be very simple. Unless the turn concept and move concept are not separated in the code then it may be hard.
I'm willing to do it myself but need to wait for me to learn scala first. I'm a Java programmer so hope not to hard.
And if I get to do it myself, I will make these changes too.

  • Start with standard chess.
  • No two squares pawn initial move. Thus no en-passant. (Pawn's initial two squares move was introduced to make the game enter combat faster. Now we move 2 pieces per turn, this is no longer an issue. This will simplify and make chess easy to learn.
  • No castling. (Make chess easy to learn)
  • White commence the game by move one piece. Black then move two different pieces one by one, must move two and must be different. Then white’s turn to move two different pieces and so on. (Makes the game balanced and white has less advantage from moving first)
  • A side is allowed to move only one piece if that piece is the only one that has legal move. (This is for at the end game, when one side has only a king left for example)

It will be different from Marseillais chess, so maybe we can name it something different.

Atomic castling with touching kings

This paper, written by FICS player Rekursiv, outlines all atomic rules as employed on FICS, and Lichess is using the same ruleset.

Quoting the paper:

As in normal chess, it is illegal to castle if your king has previously moved or if your rook with which you are castling has previously moved. It is also illegal to castle if you are currently in atomic check, if moving the king one square closer to the rook (with the rook staying put) would place you in atomic check (i.e. you cannot castle through check), or if completing castling would place you in atomic check.

Now consider this position: https://lichess.org/analysis/atomic/8/8/8/8/8/8/5k2/R3K2r_w_Q_-

Lichess allows O-O-O in here, which is inconsistent with this ruleset ("illegal [...] if moving the king one square closer to the rook (with the rook staying put) would place you in atomic check").

(Note that, when changing this, we must ensure that O-O-O stays valid in https://lichess.org/analysis/atomic/8/8/8/8/8/8/4k3/R3K2r_w_Q_- - Lichess correctly allows O-O-O in here.)

cc @niklasf

Picking the most general opening

The method that picks the most general opening in src/main/scala/Openings.scala seems broken, although I'm not sure because I don't know Scala.

To use an example from lichess: The most general opening in C40 on lichess is "Elephant Gambit, General" (line 258), even though "King's Knight Opening, General" (line 2484) is more general.

Position hashing for opening explorer

In pursuit of lichess-org/lila#1528, we need to create unique hash keys from chess positions.

A position consists of

  • the piece positions,
  • side to move,
  • castling rights,
  • en passant square,
  • number of checks in three-check,
  • captured pieces in crazy house.

Traditionally Zobrist hashing is used for this.

I see that there is already https://github.com/ornicar/scalachess/blob/master/src/main/scala/Hash.scala that accounts for piece positions and the side to move.
#3 also seams to be related to hashing.

Heuristic function for game phase is asymetric

I've been looking at the heuristic for deciding when a game is in the opening/midgame/endgame

https://github.com/ornicar/scalachess/blob/2d4aa7e2db77ce7dff353ccbc61ed4529669f5f7/src/main/scala/Divider.scala

It looks like the way the heuristic works is that it "scores" all 2x2 grids on the board and takes the sum of all the scores. A score is higher if there are many white and black pieces on the grid, or if the grid is mostly white and on the black side of the board or mostly black and on the white side of the board.

I would've expected this function to be symmetric, meaning if I take some 2x2 grid and switch all the colors and mirror it accross the y axis the score should not change.

That would mean
score(x, y, ypos) == score(y, x, 8 - ypos)
for all x y pairs

But that is not true. For example score(1, 2, y) for y <- 1 to 7 is 3, 4, 5, 6, 7, 8, 9 but score(2, 1, y) for y <- 7 to 1 is 5, 6, 7, 8, 9, 10, 11. What this means in practice is for 2x2 grids containing 2 of one color and one of the other, the algorithm cares more about more white pieces on the black side of the board than black pieces on the white side of the board.

Maybe i'm misunderstanding something about the algorithm. If i'm right and this is a bug, i'd be happy to submit a pull request.

increase lag comp for friend games

I'm going to PR lag comp that scales with estimated game time. In a follow up, I'd like to increase lag comp for games between friends, who (I'd assume) would prefer fairer time controls and can stop a series if their opp is lagging too much.

Related: lichess-org/lila#3154

Knight vs Bishop is not a draw

Playing on Lichess.org, I had an endgame of king & knight vs king & bishop which is a draw by insufficient material. However, it was only deemed a draw after one of the pieces was eaten. Doing some testing the following situations were also not considered draws:

  • knight v knight
  • bishop v bishop (opposite squares)

scale lag comp based on time control

Players on slack suggest that lag comp is making bullet tourneys less fun when they get paired with a lagger and are requesting we reduce lag comp in these situations.

Stage 1 will be scaling lag comp based on game time.
Follow up will be #117, which will bring back full lag comp for friend games.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.