ive made a surprisingly functional chess port over the course of the last 2 days
i tried doing this in turing like half a year ago but couldn't get check detection down
this time it actually worked
it comes with 4 modes of difficulty:
0 - random
1 - captures when possible
2 - makes trades
3 - avoids checkmate
according to an elo tester, level 3 is rated around 1530
i don't trust this number, the test comprised of 10 questions and i ranked 1615 despite having a chess.com elo of 612 (:
the difficulty, plus "many" more things, can be changed in the pause menu
update 1.1:
update 1.2:
update 1.3:
update 1.4:
update 1.5:
update 1.6:
update 1.7:
Very well done, an impressive feat of programming capability!
I played a game and am really quite impressed. On the occasions I have begun to program it, I normally get distracted by other projects before I implement any AI for chess (with, at time of original post, one exception which had AI but not a strong game).
Unfortunately, I had a runtime error occur after the computer player (v1.4) got in a tight spot.
Click show for error details.
Similarly (v1.5), in the hope that posting these helps you to track them down:
Update:
20/7/2020 Everything seems fixed by version 1.7
I have played a few more games without any crashes. The computer gives a varied game, and is quite pleasant to play against (which is to say that unlike competition level chess computers it doesn't crush me).
Minor tactical spoilers:
I think it's the first time I've had an en passant situation against SWEEZEchess.
There is a minor bug in the rules logic; it won't occur often, but the logic should allow a player to capture en passant to get out of check.
The following position is white to move after black plays pawn d7-d5+. White should be able to play cxd6 en passant (if white wanted to), but the computer does not recognise it.
White: remcode
Black: SWEEZEChess 1.7
(The above position was after a deliberately unusual opening for variety, with 1. b4 Nf6 2. c4 allowing some interesting play later after ... a5; Qa4 pinning the black a-pawn to the rook and the black d-pawn to the king, and e3 to allow both bishops to move to the queenside to target the black kingside.)
Non-authoritative reference:https://en.wikipedia.org/wiki/En_passant#Unusual_examples
"In the diagram, if Black plays 1...g5+, ... Black overlooks that White can counter this check with the en passant capture 2. fxg6e.p.#"
SWEEZEchess 1.7/3
SWEEZEchess 1.7/3 is primarily a bugfix (by remcode) for MEINsweeze's SWEEZEchess 1.7. As of the third version of this bugfix, it also includes 2 extra AI opponents.
AI 4 and 5
General overview of AI 4 and 5
These AI opponents were written to play with a level somewhere between SWEEZEchess's existing AI and Krystman's CheckMate AI. There was neither an intention to provide an AI comparable to Krystman's, nor to provide an AI much stronger than SWEEZEchess level 3. They take longer to think about a move than the existing SWEEZEchess AI, and because of this some rudimentary feedback is given on screen about their thinking process.
At level 4 the AI should provide a game of about the same level as MEINsweeze's AI 3, but might be a little less aggressive. At level 5 it should (generally but not always) provide SWEEZEchess's current best game, which should hopefully still be suitable in strength for a casual game, although it can take a while to think about its moves. All the AI from level 2 through to level 5 use the same worth tables so should have some similarity to their gameplay.
AI 3 will play a much faster game than AI 4 (or AI 5) and given that AI 3 and 4 are close in strength (particularly since the 12th of March bugfix) most people will likely find AI 3 the more suitable choice. AI 5 will play slightly better in some given situations, but is ultimately limited by the shallow depth of its search and thus by not following exchanges through to their conclusion.
Technical overview of AI 4 and 5
The two extra AI opponents share a minimax algorithm, but use it with different search depths. At level 4, it has a fixed search depth of 2-ply (2 half moves, or 1 whole move). At level 5, it has a variable search depth of up to 4-ply (4 half moves, or 2 whole moves). At both levels the AI runs a second minimax search with results which looked close to being reasonable, thus providing it with a second-best move as well, allowing it some variety in its move (this is indicated on screen by the fact that two progress bars fill one after the other). (This was chosen as an easy way to get variable play, not for efficiency; nevertheless the second-best move search should take less time than the first-best.)
For anyone thinking of programming a chess AI, hopefully ai_four (and ai_five, which is really just ai_four with a longer search depth) can give you an idea of possible program structure (although it is by no means definitive). Minimax and negamax have been standard algorithms for chess (and other) AI for a while, and it can be worth researching them.
The level 4 (and 5) AI was not written to be particularly strong or fast - there are many changes that could be made to achieve greater strength or speed. It was written for clarity - so as to provide anyone looking at the code a greater chance of understanding how it arrives at its decision. This is mainly to align with pico-8 encouraging new coders to look at code and learn from it.
Removing AI 4 and 5
@MEINsweeze ai_four and ai_five can be easily removed from SWEEZEchess - simply remove the last two tabs (7 and 8), change the ai_level in _init, and make the appropriate adjustments to your own functions deeper (tab 6) and cycle_level (tab 0). The added minimax AI was carefully added in such a way that if you should want to remove it, it would be easily possible to do so; this will allow you to keep the bugfixes without having someone else's AI in your program.
Notes
Fix summary
Detail of fixes and improvements
wow! timely or not, i'm happy to see any interaction with this!
i'm astonished my code was legible enough to reverse engineer and fix!
i was planning on getting back to this at some point to fix a few bugs, as there are a few that're still extant (primarily one which, considering you seem to be a better chess player than i, i'm not surprised you haven't come across: if your rook gets taken before your king has moved, you can still castle with it; the castling will take place as if the piece that took the rook was the rook and it'll basically necromancy it back into existence. i know how to fix this, just to check if the rook is actually alive for whether it's legal, but it's pretty silly i missed that.)
regardless of the still living bugs, thanks for making the fix!
maybe this'll be the kick i need to start working on it again lmao
re: legible - yes ... it took a while to work out enough of how it worked to fix some of these (a few local variables, and returns from functions might have made it easier for me) :-)
I didn't mention it above but I think while I was trying things out to fix the problem with white playing to lose, I may have swapped the 1 and -1 in the calls to analyze(1) and analyze(-1) at the tops of tabs 1 and 6 around. This is purely accidental - I have to admit I'm not entirely sure what difference it makes, or if it makes a difference depending which colour pieces the AI is playing. This might be a change you'll need to playtest to make sure I haven't made the gameplay worse. [Edit: I am sure now I put them back the right way round, and it makes a considerable difference.] :)
Good luck with any future fixes you make to it!
thank you! i'll try to fix it, and i'm gonna be honest, i didn't know about local variables and returns at all when i made this! the language i'm used to programming in, turing, is very similar to lua except locals aren't a thing; when i learned lua, i never bothered to google how to do local variables since i was completely unaware that they were even a thing. as a result, i use an abundance of variables, and that gets tedious, so i just name neatly every variable whatever mouth sound i make, maybe plus an x or y if it's revelant lmao
as for returns, that's more of my bad habits; i use so many variables that my first instinct is to just save the result of a function as yet another global variable
EDIT: oh god, turing has locals too.. i just never learned about them. :(
[Please log in to post a comment]



