5 ms·
Chess Written in GNU Sed
- numlocked 3y agoIt says: Not Implemented: - Roque - Ceit not - Draw game - Human move correctness What is Ceit not? Roque is French for castling, it appears. This is wild.
- d_bud 3y agoCeit not is likely “Zeitnot”, or time pressure.
- inputError 3y ago[dead]
- stevage 3y agoI came to ask this. I assumed it's en passant, which is likely not to be implemented if castling isn't.
- GNOMES 3y agoI really need to invest more time into Sed/Awk. I typically only use them for find/replace or deleting characters/lines in my shell scripts.
- jmholla 3y agoI've shared this before, but this sed tutorial made me a pro. [0] Even if you don't use it for more complex things, you may find there are faster ways to do the things you are now. [0]: https://www.grymoire.com/Unix/Sed.html https://www.grymoire.com/Unix/Sed.html Edit: That said, I don't even want to start dissecting the submitted code.
- DryLabRebel 3y agoGrymoire is how I learned sed, and is a fantastic quick reference for grep and regex also.
- chasil 3y agoFor awk, start with the book by Kernighan/Aho/Weinberger. The PDF of the first edition is freely available on archive.org, and a second edition has been announced. Chapter 2 of the first edition is only 40 pages, and describes all language features. https://news.ycombinator.com/item?id=13451454 https://news.ycombinator.com/item?id=13451454 For sed, the best resource is likely the free "UNIX Bookshelf" from O'Reilly that can be found online; this contains a book specifically focusing on Sed and Awk. https://freecomputerbooks.com/The-Unix-CD-Bookshelf-Version-3-0.html https://freecomputerbooks.com/The-Unix-CD-Bookshelf-Version-...
- Brentward 3y agoThe second edition is out! I started reading it last week, and it's great so far. https://www.awk.dev/ https://www.awk.dev/
- rjh29 3y agoJust use Perl for one-liners. It's more powerful than sed/awk but it does pretty much everything those do.
- garciasn 3y agoPerl is probably overkill for 99% of one-liners and may not be available on as many environments as awk/sed are, but I advocate that folks do whatever is best for them in their environment and if that's Perl for you, rock it out!
- nickpeterson 3y agoIf Perl isn’t available in the environment try ‘systemctl start oyster-farm’
- anthk 3y agoawk can do much more than sed. And, with patience, you could even write a Z-machine interpreter on it as some guy did with postscript. You might have to convert the binary input to hex first with xxd/od in order to parse the opcodes in a nice way, but everything else would be simulated from awk.
- tyingq 3y ago> You might have to convert the binary input to hex first If you're okay with gawk, most implementations ship with gawkextlib, which has readfile(), and you also have FIELDWIDTHS.
- asicsp 3y agoI have ebooks on GNU sed and GNU awk with plenty of examples and exercises (free to read online): * https://learnbyexample.github.io/learn_gnused/ https://learnbyexample.github.io/learn_gnused/ * https://learnbyexample.github.io/learn_gnuawk/ https://learnbyexample.github.io/learn_gnuawk/ I also wrote TUI apps for interactive exercises (grep, sed, awk, etc): https://github.com/learnbyexample/TUI-apps https://github.com/learnbyexample/TUI-apps
- nvy 3y agoThis taught me awk, from an HN submission years ago: https://ferd.ca/awk-in-20-minutes.html https://ferd.ca/awk-in-20-minutes.html I've had some fun using awk to generate C# classes for an Ultima Online emulator.
- deleted 3y ago[deleted]
- tromp 3y agoI played a game where I moved my bishop to c4 and queen to h5 while Black was busy advancing h and g pawns (and trading its rook for my knight on h3), and when I thought I played the final move Qxf7 checkmate, it calmly played ... Kxd8 I guess making illegal moves is its only way of acknowledging defeat.
- demondemidi 3y agoit says in the comments that it does not check correctness. impressive feat with sed but not really worthy of the term "chess engine"
- tromp 3y agoThe comments say that > Human move correctness is Not Implemented. Which suggests that the script only makes correct moves. My example shows that's not true when there are no valid moves.
- kazinator 3y agoThat's the same as a typical Unix script cobbed together with these tools. When the input data isn't of the expected form (a regex doesn't match, or matches in the wrong place, or whatever), there is often still a nonfailing behavior of some kind.
- wrp 3y agoIn the late 1970s, I bought a chess computer at J. C. Penney, the one in a brown plastic case with the chessboard printed on top and a keypad to the right with a red LED display. I returned it after about a week because it cheated. Whenever I moved to take its King/Queen, it would call an illegal move, and claim that its King/Queen was on the other side of the board. I've wondered what glitch in programming would create that behavior.
- 4star3star 3y agoIt's a cool idea, but the computer sucks. They even moved their King in check, which is an illegal move.
- rjh29 3y agoIt's fucking sed. Nobody expects it to have a full AI engine in there...
- riotnrrd 3y agoMicro-Max (https://home.hccnet.nl/h.g.muller/max-src2.html https://home.hccnet.nl/h.g.muller/max-src2.html) is a chess engine written in C (2000 characters!) and has an ELO of about 1900 and plays only legal moves.
- pmarreck 3y agoSweet, now do Awk! (I guess Sed is turing-complete?)
- B1FF_PSUVM 3y agoRelated: Sokoban in sed https://aurelio.net/projects/sedsokoban/ https://aurelio.net/projects/sedsokoban/
- asicsp 3y agoSee also: * "A proof that Unix utility sed is Turing complete" https://catonmat.net/proof-that-sed-is-turing-complete https://catonmat.net/proof-that-sed-is-turing-complete * https://github.com/izabera/cube.sed https://github.com/izabera/cube.sed
- hdaz0017 3y agoblack removed its own queen when I placed its king into checked :P then it moved its king from check to the space to the left staying in check :) :P impressive but the graphics need to be much bigger. Would be good to have some indication that is is my move and show the move that the chess.sed made, would also be good to place all moves into chess.log :P