Chess written in sed
github.com
github.com
I'd like to see more sed programs on HN instead of the usual Python, Ruby or Go offerings.
I wrote a sed version of the the Python script "youtube-dl". This way I don't need Python installed to download YouTube videos. And it's easy to edit if YouTube suddenly changes their "API"; no need to wait for someone else to fix their Python or Lua script. In truth, it's not pure sed though. It uses sh (not bash), sed and ftp (or any other http client that handles 302's).
I agree its nice to see a variety of languages. Gives a fresh perspective on how to do things.
I never need to install Python permanently.[1] In my experience, there is almost always a way to do what needs to be done with what UNIX provides, without installing more software. This keeps the system smaller, more standardized and hence more portable than one where various dependencies are haphazardly added.
1. Sometimes I have to install it temporarily, for "reverse engineering" a non-Python solution, e.g., when someone decides to use Python as a substitute for make.
Like sed, all UNIX systems provide ssh. It's not "extra software". There's no need to use telnet.
On the other hand, not all UNIX systems have Python pre-installed. Moreover, as in the case of embedded products, not all systems may have the space for it.
it has deep roots in the psyche of my old country:
http://en.wikipedia.org/wiki/The_Tale_of_Cross-eyed_Lefty_fr...
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?? 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 :).
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.
That said, I've recommended learning Python to a few people, but have never even suggested anybody learn sed or awk.
(hint: see line 14.)
- 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.
Programmer who did something like that is mad. Or he/she is from Russia.