Live data from Hacker News

Chess written in sed

github.com

31–40 of 57 posts

Re: Chess written in sed

#32
post #27

Earlier quoted context omitted.

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…

Hey cool, thanks. I've always overlooked it.

Re: Chess written in sed

#33
I don't want to detract from how absolutely awesome this is, but there are definitely some bugs in this.

- It routinely moves bishops vertically.

- It lets you make illegal moves yourself (not a huge deal).

- I got a square turning black for no reason.

Might also be nice if it told you what move it just made.

Re: Chess written in sed

#34
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?

I use sed in makefiles, to scrape the source code for a version number, and then embed that version number in the name of the executable to be built. That would be easy enough in, say, Python, but as a sed script it's lightweight, decently readable, and puts everything you need to know right there in the makefile.

That said, I've recommended learning Python to a few people, but have never even suggested anybody learn sed or awk.

Re: Chess written in sed

#35

Earlier quoted context omitted.

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

I use sed in makefiles, to scrape the source code for a version number, and then embed that version number in the name of the executable to be built. That would be easy enough in, say, Python, but as a sed script it's lightweight, decently readable, and puts everything you need to know right there in the makefile. That said, I've recommended learning Python to a few people, but have never even suggested anybody learn…

Oh, yeah, sed and awk are great, I meant ed in particular.

Re: Chess written in sed

#38

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 perh…

The readme says passant isn't implemented, and there's no validation of the player's moves. So you did an illegal move.

Re: Chess written in sed

#39

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.

Do you have a link to that?

I saw the video many years ago, and a search just now seems to only find links to a video that has disappeared from YouTube.
Post reply on HN