asdfjkl / jfxchess

JFXChess - Chess Program
https://asdfjkl.github.io/jfxchess
GNU General Public License v2.0
102 stars 21 forks source link

Insufficient material draw #117

Closed TTorell closed 3 years ago

TTorell commented 3 years ago

Hello again! Here's another one for you:

Warning! I think I might have changed pom.xml, Don't include that file in an eventual merge.

Jerry kept on playing with "King and bishop against King" (until a draw by threefold repetition was reached, real soon, but still...). Later I saw that the same thing happened with two lone Kings on the board. So, I thought AHA! another opportunity for me to contribute to the Open Source Software Community! I chose to interpret this rule as strictly as possible, as I read that FIDE does (Easier to code also). Found this on the web:

Impossibility of checkmate – if a position arises in which neither player could possibly give checkmate by a series of legal moves, the game is a draw. Such a position is called a dead position. This is usually because there is insufficient material left, but it is possible in other positions too.

Maybe my fantasy is limited, but which other positions are they talking about? (King and Queen vs. King and Queen where both Queens are pinned against their Kings, or what? No, one side can still blunder and lose the Queen. I tried at least.)

Combinations with insufficient material to checkmate include: king versus king king and bishop versus king king and knight versus king king and bishop versus king and bishop with the bishops on the same color.

When I started coding I only realized the first three cases and the code was simple and beautiful, but then came that fourth case and messed it up.

There is a more liberal interpretation of the rule in some countries and on some web sites. chess.com for instance. Something like this:

The solution I gave is, of course, just a suggestion. Change it anyway you like, or make it configurable.

Anyway, it seems to work fine (Ubuntu 20.04)

asdfjkl commented 3 years ago

thanks! will look into it. indeed, haven't included anything except checkmate, stalemate and 50 moves so far.

might take some time to merge, as it apparently involves some thinking on my side :-)

TTorell commented 3 years ago

That's allright. Take your time.

TTorell commented 3 years ago

By the way: In my comment on the change request I said I couldn't imagine which other "dead positions" they were talking about". Follow the link below and scroll down to the position titled (Mednis 1990:43), there's one of them. "Bad imagination on my part". https://en.wikipedia.org/wiki/Draw_(chess)#Draw_rules

Think it would be a difficult task to find all such positions programmatically, but possible of course. I don't want o push things in any way, but only suggest that the four piece-combinations searched for in this pull request (K vs K, K&B vs K, K&N vs K and K&B vs K&B with bishops on the same color of squares), are dead-sure impossible to find any checkmate with. They will always be part of which ever policy you choose to follow. And they cover a lot of practical situations. So, you could see it as an improvement in the right direction and add a TODO or Issue about expanding Jerry's "insufficient material"-policy later. (And it gives a better impression when that sign, "Draw (insufficient material)" pops up.)

TTorell commented 3 years ago

Removed the pom.xml commit which had been included by mistake.

asdfjkl commented 3 years ago

again thx. was scratching my head about the code since I thought ... this is falsely reporting checkmate possible if there is just one white and one black bishop until I realized that there is actually a possible checkmate if these are of opposing colors ;-)