Computer Chess with IF Authoring Systems

No way! That’s brilliant! I’d read that he was into games design, same for one of the other cast members (James Curry I think) who is the other “real programmer” in it. Small world. :sweat_smile:

1 Like

Huh. What do you know? I did manage to beat GlkChess at level 3. The trick is to disrupt pawn formation and go ASAP to endgame, where the computer plays poorly. It seems like it doesn’t have any attacking ambition, so if you have good defense, you should be fine.

2 Likes

Looks like I’m at level 4. Barely scraping with lots of takebacks. I’ll leave level 5 and higher to other people.

1 Like

There is a Z-machine chess game called Z-Chess which uses the upper window to draw a chess board, using Unicode for the pieces.

It’s not particularly usable with Gargoyle, unfortunately, because the cursor isn’t visible in the upper window. That should probably get fixed…

3 Likes

Uh, not sure how much you’ve fooled around with CS, but every computer turn would require, at minimum:

a) Checking which pieces are available (i.e. aren’t captured or boxed in) and then randomly picking which piece to move from the pieces that are eligible to move
b) Checking all possible moves for that piece to see if they are valid
c) Randomly picking a valid move
d) Checking whether that valid move is to an empty square or captures an enemy piece
e) Updating the variables for the enemy piece, if one is captured
f) Updating the moved computer piece’s coordinates

And that’s if the computer randomly chooses which piece to move and randomly makes the first legal move it can. I suppose, if you squint hard enough, that might be chess.

Building a decision tree to calculate which move would be most beneficial to the computer, however, even if it’s a rule as simple as “always capture the highest-ranking piece you can, if possible” would require quite a bit of work, indeed.

First, every possible move would have to be weighted with a numerical score, and then gosub routines would have to figure out which one has the absolute highest score. And you’d have to add an ancillary rule to flip a coin in the case of a tie (e.g. the computer has the possibility to capture either of two pawns).

If you think you can script out a chess simulator in CS, I’ll be the first one to try it!

1 Like

The entire thing blows my mind irrespective of which system you use. I mean you could program, say, the Spanish opening but how do you know the opponent isn’t going to do something completely weird like only move 1 pawn, or perpetually move a piece back and forth or only play with the left side of the board. Hats off to anyone who has managed to do this.

There is zugzwang, but it is only an endgame.

Not particularly usable in Windows Frotz, either, because the board looks like this:

Occupied squares are wider than empty squares, so the board is irregularly shaped.

Parchment doesn’t display it properly either, as the chess symbols aren’t present in the font it uses, and the replacement font the browser chooses has different metrics.

Oops. Thanks to those who mentioned/wound up playing my chess games. Adam, no worries if you didn’t remember it from ParserComp–I’m glad you sat down with it!

My belated view is this: a chess game of any complexity would be awful in Inform, and that’s why my two were just about placing pieces, not worrying about an opponent. There were so many special cases as-is. I used separate rooms for each square. I was able to use a “chess common” file that simplified things. My basic idea was to take something known in chess and put a spin on it that stronger players might not have considered. For 5x5, queen and rook endgames are relatively simple for experienced players but very interesting for newer players. For 4x4, the initial puzzles are meant to be a bit funny and bizarre. Many chess players know them but it’s clearly something you can’t force. The two-minor-piece mates are tricky (and with N&N impossible to force) but I had that “what if” moment that made up the hard-mode puzzles so I felt it was more than just pushing pieces.

Even something as (relatively) simple as a game with 2 bishops or bishop and knight is tough. I was shocked to read that one person in the Chicago chess scene who was a really strong knowledgeable player (close to senior master strength, wrote a book or two) wound up in 2005 not being able to convert a 2-bishop checkmate. And I think even though it could be taught, it might be too much of a grind.

Though just straight up chess seems possible with a homebrew parser especially as with however glkchess embedded an engine. But I’m a relatively serious chess player, so it feels to me like it’d be hard to capture anything chess-ish. It seems like puzzles would be the best bet for a story. The problem with a full game is that there are too many possibilities, and the problem with a puzzle is that it may seem forced, but it’s the lesser of the two.

I think puzzles showing the 4-on-4 or 3-on-3 pawn breakthroughs in an endgame would be neat, as would smothered mate or other tricky puzzles. Something like a full knight’s tour on an 8x8 board would be a challenge as well, as would placing 8 queens that can’t attack each other. But these are canonical puzzles that are hard to place. I think to make an interesting chess game you need a surprise twist that’s not too complex, and that’s where endgame pawn breakthroughs would come in.

Like this. I thought I was winning as white. Black to move.

The solution is …d5! as if cxd5 c4! and White has to play b5 (if Ka4 Kc7 b5 a5!) as if …axb5 Kb4! planning a4 wins. But …c3 bxa6 and White queens in time and it’s a draw. Black’s queen keeps checking on the c-file.

Something like this is a legitimate puzzle, as there aren’t too many possible solutions, but what’s there seems counterintuitive at first.

Anyway, folks, thanks for this topic. I actually saw it, then remembered I needed to put a post-comp release out, then forgot about it, and then I saw all these responses, which was nice to come back to.

3 Likes

Glkchess is pretty strong even on the lower levels. So if anyone feels like a duffer for not beating it, don’t. It does however make some errors that were popular among computers before they became what they are now. I think I’d like to discuss this, as an excuse to show off my chess skills. But I also want to try to address “how would we tie chess into a creative work in general?” I’d be interested in others’ thoughts. If I’m rattling on, I hope people find it entertaining.

Following up on what Harry noted

As Harry mentioned, on level 3 you can wreck its pawns and then grind it down. But it’s a pretty deadly tactical sniper. I was playing lazily and it kept finding good ones with major pieces on the board that won back a pawn, etc. It plays for activity and doesn’t always judge positional weaknesses well. So you have to be careful and avoid cheap (or not-so-cheap) tactics & once you’ve weathered the storm, you have mop-up work.

One trap I ran into was c4 e5 g3 Nf6 Bg2 Bd6?! … and then also tends to over-extend its e-pawn playing e4 and e3 so that you can just take it. Another trap was 1. g3 d5 2. c4 Nc6 3. cxd5 Qxd5 4. Nf3 Ne5 5. Bg2 Bg4 6. Qa4+ Bd7 7. Qf4 Ng6 8. Qe3 Qe6 9. d4 Qxe3 10. Bxe3 Nf6 11. Nc3 Ng4 12. Bd2 e5? 13. h3 Nh6 … again, the computer doesn’t “see” the e-pawn will eventually get killed until it’s far too late.

But I was able to smash it tactically. Hope none of this is showing you up, Harry! Still, if anyone wants the satisfaction of crushing GLKchess, here is a roadmap, though you may need to keep resetting until the first 4 moves fall into place.

16 move win

(I am white) 1. e4 e5 2. d4 Nc6 3. Nf3 exd4 4. Nxd4 Qh4?! { risky but in keeping with MSCP’s aggressive style. I used to get burned by this a lot until I learned and started enjoying facing it. } 5. Nc3 Bb4 6. Nb5 Qxe4+ 7. Be2 Bxc3+ 8. bxc3 Qxg2 { this loses material since c7 is tough to defend. Glkchess probably thought it was safe looking 3 moves ahead but it needed to look 4 } 9. Bf3 Qxh1+ 10. Bxh1 Kd8 11. Bf4 d6 12. Nxc7 Kxc7 13. Qxd6+ Kb6 14. Rb1+ Ka6 15. Qd3+ Ka5 16. Qb5#

I was able to beat it on level 5, and I’m pleased enough about it to offer analysis.

beating level 5

(I am white again) 1. e4 e5 2. d4 exd4 3. Nf3 Bb4+ {…Nc6 is main line stuff, and this is a better move than …c5 which I score well off. It forces White to sacrifice a pawn. } 4. c3 dxc3 5. bxc3 Be7 6. Bc4 Nf6?! { Harry mentioned smashing the computer’s pawns works well. Here it’s not just for positional advantage but for an attack. } 7. e5 Ng4 8. h3 Nh6 9. Bxh6 gxh6 10. O-O?! { Qd5! is a known brutal move in these positions. … O-O 11. Bd3 Kg7 (hard to guard h7 otherwise) 12. Qe4 Rh8 13. Qg4+ and Qh5 and black is very, very uncomfortable } … O-O 11. Bd3 {apparently Qd2 is better since Nxg5 Qxg5 f4 is strong} d5?! {d6 is more solid} 12. exd6?! {Qc1 or Qd2 again} Qxd6 13. Qc2 f5?! { very weakening } 14. Nbd2 Be6 15. Nc4 { Nd4 is also good as it just wins the pawn back as Nxe6 Qxe6 Bc4 is also a threat } Qd5 16. Rfe1 Nc6 17. Rad1 Rf6 18. Nfe5?! { Wrong knight! Nce5 Qxa2 Nxc6 I win a piece as Nxe7 comes with check, and on anything else, Qb3 Bc4 Nd4 win a rook back for free due to the pin on the diagonal } Nxe5? { Qxc6 Ne5 and White has an edge } 19. Ne3 { Na5! Qb6 Bc4 is devastating as …Bxc4 Nxc4 threatens e7, and attacking the knight allows Rxe7 and Rd7, which is brutal } Raf8 { Bc5 Bxf5 Bxe3 Bxh7+ } 20. Rxe6?! { plain old Bxf5 just wins a pawn. I don’t know what I was thinking. } Rxe6 21. Bxf5 Rd6 22. Bxh7+ Kf7? { Odd move as it gets the king in trouble. Kh8 is just safe } 23. Rb1 b6? { Black can’t afford to move pawns now. Bg5 is more active. } 23. Be4 { obvious and strong but Nf5 may be even better } Qc5 24. Qb3+ Kf6? { Wow, not very concerned about king safety! } 24. Nd5+ Ke5? { trying too hard for an attack. Ke6 is even. } 25. Bf3 Bf6? { Rxd5 Qxd5+ Qxd5 Re1+ Kd6 Bxd5 Bf6! draws, but that’s tough to see } 26. Re1+ Kf5 27. Qc2+ Kg5 28. h4+ Kxh4 29. Re4+ { yes, Qe4+ is a move quicker } Kg5 30. Rg4+ Kh5 31. Rg6+ { Oops! Two mate-in-ones, but I had calculated a mate and played it } Kh4 32. Qe4#

However, I think all this is too much to crowd into something that presumably already has a story. In terms of literature, I think the best integrations of chess into a novel are Nabokov’s The Defense and Martin Amis’s Money. You may have to understand chess to fully get Amis’s game, which never tells you the position, just what’s going on. The narrator is totally losing and doesn’t know it, just thinks he’s temporarily down a bit and he’ll get it back (echoing the theme of “I’m close to the big $$ windfall” which never turns up,) and his opponent simply trades back material for a dead-won endgame, which the narrator would never consider because it’s allegedly too boring.

For those who want to see about integrating a chess game into a movie, I really like the first review of The Luzhin Defense (based on the novel above–sort of) … It’s about a 3 minute clip, and the person annotating is an International Master, one step below Grandmaster. The others are interesting, but I think the first part really underscores how to combine “actual” chess into drama, tension, etc.

There are two other videos at Chess Master Breaks Down Chess Scenes from Movies and TV | PART 3 - YouTube and Chess Master Breaks Down Chess Scenes from Movies and TV - YouTube … I think the analyses of Searching for Bobby Fischer and From Russia with Love and Fresh give the best idea of how to fit a chess game into any sort of narrative, even if it is not branching.

notes on SFBF the movie

I was slightly disappointed in SfBF’s finale (and not the only one) because the movie didn’t follow the book. The final game Waitzkin vs Sarwer in the book was a neat roller coaster, and I think it could’ve translated well to the big screen, but they provided a simplified tactic at the end that would clearly be eye-catching and would be illuminating for casual players and forced resignation. I feel sort of like a snob, but it brings into question how much you can/should play down to the audience. In the book, Josh fought hard just for a draw, which was enough to win him the tournament, and tourney players know how good it feels to hold a draw. But the audience might find it boring.)

This does call into question how “real” and full of technical detail chess games within a work should be.

1 Like

You read Waitzkin’s book? I think that qualifies you as chess snob. Then again, me too. :sweat_smile:

Congrats on beating level 5. You make it like it’s a regular occurrence! I eventually did try out level 5, and managed to eke out a win by the barest margin. This I achieved after so many draws and losses, mind you.

Of course, you showed me up. But you deserve it! You’re a much better chess player than me! :+1::+1:

1 Like

Well, it may sound corny, but the key is to improve, and I’m glad I pushed you to do something you wondered if you could. The next time will be easier, if you choose to go that way.

I’d really like to see chess in more books and games, etc., and implemented rigorously as well. I had an excuse/opening to say something here and I went for it.

As for level 5? Well, I had to spend my time thinking about it. And the analysis took time. It’s always a good exercise, to see what you missed and do better. If I did it more often, I might improve to where I really want to be.

By the way, one neat feature I was thrilled to see in GlkChess is that saving the game

  1. gives the full PGN
  2. has funny names for the player (e.g. Gladys Knight and Chubby Checker.)
1 Like

One idea I’ve had (which I’m all ideas and no execution unfortunately) was a game about joining a chess club, mainly thinking back to my time in my high school chess club. I pretty have no idea where I’d start with coding this but the idea I had was that the club would be made up of about a half dozen to a dozen members all ranging in skill and play style (as well as personality) so that even people who have never played before would have at least one opponent they could beat and better players could test themselves against everyone to see where they lie. While I wanted the chess to be a fun engaging part of the game, and make up most of the real gameplay, another important part that the chess club setting lends itself too is also allowing the games to be a way to get to know the other players, where you say things to them between moves, or see how they hide their face in their hands after realizing the mistake they made.

Another area I thought that the chess and characters could interact well would be by doing puzzles with your fellow club mates, having them to help you like a hint system if the puzzle is too hard for you, and learning more about how they see the game (such as the player who always plays really aggressive talking about how they always look at captures first, or the more book smart player talking about what game this puzzle is from).

A big area I think chess can interact with narrative though is learning how each of the characters got into chess. At least from my own experience at meetups it seems everyone has a somewhat unique or special story about what got them into it, whether it was an early mentor or often family, or just a passion/interest from a young age.

I think this sort of approach, especially of having certain players at certain predefined levels with certain play styles works well for a game about learning and getting better at chess (my aim with the game) but could definitely be lacking if the player is already much better then each of the characters. I did think it would be cool to have something like a state championship tournament or something where more experienced players could then meet more characters at an even higher level would be interesting but this also raises problems for players who do come in completely new. It’s hard enough to have someone come into a chess game who may not even know how to play to teach them, but to then expect them to get to an intermediate/advanced sort of level just through the course of play to see the whole game would be an extremely daunting task.

2 Likes

These are really good ideas! Yes, I think this sort of thing is important no matter what your rating is. So I hope you find the resources to execute at least a few of them.

I know there’s a certain (unfair) stereotype of chess players (looking back, the worst came from other kids in honors classes,) but seeing the boom in chess streamers since 2020, it’s obvious that there are many different personal styles, etc.

I was shocked to learn how much physical training players at the top level do, too. And I certainly was surprised to see how many chess players at smaller school had letterman jackets for football, etc. So it’s not just “durr durr chess is for nerds.”

It’s also nontrivial to describe how you can learn mutually from someone rated 400 points below you if you focus on openings you don’t know, etc. So there is opportunity to describe connection. Certainly 2 people I played against in high school, from an “archrival” school, helped me get better at stuff beyond chess. One of them was very tactical, another very positional.

I also agree that learning about the game vs maximizing your rating now is an important thing to address. For instance, some players on the internet will try to “farm” me as I am stuck in an opening they know and I don’t. They will win in the short term, but I can learn from my losses and not get swatted the next time. There are also tricky openings I know are unsound (Qh5 in the Center Counter after I play h3,) and maybe I’ll lose, but then a chess engine shows me sensible things to do later.

(Note–another side point here. Just playing too much and not using tools to learn is a hazard, and that’s something that can be captured in a narrative as well. It’s not on the level of chemical addiction, but “just one more game” leading to more and eventually playing automatically and not enjoying it is a dead end we can fall into.)

Speaking of stories, there’s this movie called seventh seal, where a knight plays chess with Death. You can shape the game as it progresses according to how the player plays.

This isn’t limited to Choice either. You can have multiple chess personalities, and as player choose passive solution in the narrative, the chess engine becomes an attacker. Aggressive player will face defensive engine, and so on.

In case you’ve been wondering what I have been doing in the past few weeks.

This past week has been especially tough, but I survived. I also learned to play Bullet chess in the process. Sadly, I still decline too many Botez Gambits.

Now back to TACK. Design is done, so just coding now.

4 Likes

Congrats.

2 Likes

Congrats on getting to Legend! I’ve been stuck on Champion.

I haven’t made as much time to play as I like, though I still do the daily puzzle, and I usually try to do a survival puzzle rush. I definitely try to play one interesting game per day I can learn from. I hope you do, too!

It’s amazing how absorbing Bullet can be. I hit a certain rating point and decided I wouldn’t be playing for a while, because sometimes I’d say “just a few bullet games” and it was more than a few and took more time than if I’d settled for 3- or 5-minute games.

What helped me was playing hyperaggressive openings–you just want to make your opponents freeze up and think! In particular, 1. e4 c5 2. d4 is really good as it has the side benefit of them maybe premoving d6, then dxc5, Qxd8, Be3 Nc3 etc. and they are not playing what they want from a Sicilian. This approach probably helped me to enjoy risky attacking positions more in general. And they should be fun. You can learn a lot from them.

If used correctly, bullet helps you stop worrying about less relevant things & gives confidence in your intuition.

2 Likes

Trade early. Trade often. Win pawn endgame.

1 Like