Live data from Hacker News

Chess written in sed

github.com

21–30 of 57 posts

Re: Chess written in sed

#21
post #18

sed, and also awk, and ed, are worth learning. I mean coding a chess game in those tools is just a novelty, but you can do so much really useful text processing with just those tools, and they are pretty much guaranteed to be available on almost any *nix machine.

What's an example of something non-interactive that ed is good for that you can't easily do with other tools?

Re: Chess written in sed

#22

There appears to be a bug. Here is the state I reached (notice that "white" now has two bishops of the same color). a b c d e f g h 8 ♖ ♘ ♗ ♕ ♔ ♘ ♖ 7 ♙ ♙ ♙ ♙ ♙ ♗ 6 5 ♙ 4 ♝ ♟ ♟ 3 ♙ 2 ♟ ♟ ♟ ♟ ♟ ♟ 1 ♜ ♞ ♝ ♚ ♞ ♜ Someone want to submit a pull request? :-) edit: For anyone who wants to reproduce ("black" went first, since black appears as white on the board) 1. e4 h5 2. d4 h4 3. Bb4 h3 4. Qf3 g5 5. Qxf7 Bxf7??

I just tried this in real life and got the same bug. Hmmm.

Re: Chess written in sed

#23

This is a bit like that fellow who did pixel art by manually writing coloured table cells in HTML in Notepad - very, very impressive, but it does make one wonder a little about the person who has done it.

>very, very impressive, but it does make one wonder a little about the person who has done it. it has deep roots in the psyche of my old country: http://en.wikipedia.org/wiki/The_Tale_of_Cross-eyed_Lefty_fr...

Many thanks for posting this - it's enlightening context. :)

Re: Chess written in sed

#24
post #18

sed, and also awk, and ed, are worth learning. I mean coding a chess game in those tools is just a novelty, but you can do so much really useful text processing with just those tools, and they are pretty much guaranteed to be available on almost any *nix machine.

That's true... but I haven't had to do real work on a system that didn't already have Python installed on it in a long time.

Re: Chess written in sed

#25

There appears to be a bug. Here is the state I reached (notice that "white" now has two bishops of the same color). a b c d e f g h 8 ♖ ♘ ♗ ♕ ♔ ♘ ♖ 7 ♙ ♙ ♙ ♙ ♙ ♗ 6 5 ♙ 4 ♝ ♟ ♟ 3 ♙ 2 ♟ ♟ ♟ ♟ ♟ ♟ 1 ♜ ♞ ♝ ♚ ♞ ♜ Someone want to submit a pull request? :-) edit: For anyone who wants to reproduce ("black" went first, since black appears as white on the board) 1. e4 h5 2. d4 h4 3. Bb4 h3 4. Qf3 g5 5. Qxf7 Bxf7??

It also seems to allow some illegal moves. The computer moved its bishop like a rook.

Re: Chess written in sed

#27
post #18

sed, and also awk, and ed, are worth learning. I mean coding a chess game in those tools is just a novelty, but you can do so much really useful text processing with just those tools, and they are pretty much guaranteed to be available on almost any *nix machine.

What's an example of something non-interactive that ed is good for that you can't easily do with other tools?

OK I'll bite. For this answer I'll assume "easily" to mean "with less typing".

ed has a more concise syntax for joining arbitrary lines of a file (by line number or pattern) and then saving the file (by way of a temp file in $TMPDIR). You could do this with awk and perhaps with other standard tools (note: I don't consider perl to be "standard"). But I think it's safe to say the ed script would always be shorter. ed's syntax for deleting and moving arbitrary lines is similarly concise. For these specific tasks, it's not going to be easy to win at code golf using awk or other tools... and in some cases it may be impossible.

Re: Chess written in sed

#29

There appears to be a bug. Here is the state I reached (notice that "white" now has two bishops of the same color). a b c d e f g h 8 ♖ ♘ ♗ ♕ ♔ ♘ ♖ 7 ♙ ♙ ♙ ♙ ♙ ♗ 6 5 ♙ 4 ♝ ♟ ♟ 3 ♙ 2 ♟ ♟ ♟ ♟ ♟ ♟ 1 ♜ ♞ ♝ ♚ ♞ ♜ Someone want to submit a pull request? :-) edit: For anyone who wants to reproduce ("black" went first, since black appears as white on the board) 1. e4 h5 2. d4 h4 3. Bb4 h3 4. Qf3 g5 5. Qxf7 Bxf7??

On my first game I got an even better bug:

  a b c d e f g h
8 ♔       ♛ ♝ ♘

7 ♙ ♙ ♙ ♙

6

5         ♙

4       ♟ ♟     ♕

3   ♟ ♞

2 ♟   ♟     ♟   ♟

1 ♜     ♛ ♚ ♝   ♜

After performing en passant the computer went crazy and the King started taking all the pieces between down row 8. I ended up with a very easy checkmate as I walked my pawn the remaining three rows, unfettered even when it was under double pressure from the night and queen.

I wonder if this is perhaps an issue caused by the fact I used OS X's BSD sed.

Edit: Hmm, can't seem to format it right. Anyways, the bug seems to be present in gnu sed as well. Really the whole game was screwy. I started with e2 e4 and it all went down hill from their for my opponent :).

Post reply on HN