@PeterTaylor Personally, I don't mind allowing a boring answer like that if it allows some other languages where answers are really interesting. For instance, it seems that it's not clear whether Malbolge is TC, and it's going to be hard to prove that you can test primality, but I'd hate to exclude it from the catalogue.
(If what I said about Malbolge is bullshit, I can go looking for another language.)
If the goal of this challenge is to just be "where we put the Hello, World! programs" I don't think we'd even want to get rid of the boring answers tbh.
Would it be worth setting another challenge to find a very simple (if inefficient) way of testing primality that can then be used to check any language more easily?
@Mauris Ok, I think primality testing is doable. But general Minsky machines can have arbitrarily large state machines, and I'm still not convinced that a finite number of temporary variables suffice to track the state with the limited looping and conditionals of Fourier.
@PeterTaylor Well, they're finite state machines. So your state is just a single integer, and you write: state = 1; while (state != 0) { if (state == 1) { ... }; if (state == 2) { ... }; ... }, right?
Also, people write papers about Malbolge, and it's amusing.
Ugh, what a dilemma... I know what one of the cops on the quiz is, but I only figured it out because it's the author's own language, and I know his user name on esolangs, and I only know that because I personally showed him the challenge ... :/
Needs a small tweak. if (state == 2 && x == 0) state = 5; else if (state == 2) { x--; state = 17} becomes c = 0; if (state == 2) c++; if (x == 0) c += 2; if (c == 1) { x--; state = 17; } if (c == 3) state = 5;
Rec(ursion)less execution
We have a simple (non-Turing complete) language.
Each line of program is a set of terms separated by single space.
Some of terms (ending with ()) are function calls.
Some lines (whose first term ends with :) are function definitions.
The lines that are not function def...
What is a good way of implementing pieces in Chess? My first thought was inheritance because inheritance just makes sense for it, but then as I was implementing my board, I discovered I kept having to use instanceof (Java) to check for Kings or Pawns since they have special behaviour.
I ended up switching to Enums.
But I'm not sure if that's a good idea either since there is inherent inheritance in here.
@Mauris That was my original intent. But there's en passant and the like, which can't be cleanly implemented through inheritance (or I haven't yet invented a way to do so).
@Doorknob Or better. Since it's a bunch of boilerplate to add an override for each piece, let's just use reflection to figure it out. (Actually a really bad idea... I like reflection a bit too much)
Give pieces a hitbox() method returning a List<Coordinate>. For almost all pieces, it returns the singleton list that contains their own position; for a pawn that jumped two ranks in the last turn, it contains its own position and the one it jumped over.
Then in the capture logic for other pieces, find all enemy pieces whose hitbox() contains the square being captured on.
Ahh but only pawns can capture pawns through en passant
The idea is I give my Piece base class a List<Coordinate> getMoves(Board board) method and each class overrides that. Each piece also has a location and a color, and can be taken, etc. The problem is the special rules regarding Pawn-Pawn interaction and King-Rook interaction (and dealing with check)
This does feel a bit roundabout, yeah! And it's because a more "human" description of the rules of chess talks about pawns concretely, as opposed to "pieces that can be captured en-passant" and "pieces that can capture en-passant".
But using this kind of writing, all of your board logic knows nothing about the kinds of pieces that exist, which is a very nice thing in OOP!
Right! player.inCheckBy(enemy) just ORs together piece.inCheckBy(enemy) for all pieces; piece.inCheckBy(enemy) returning false for non-Kings and ORing together each enemyPiece.canAttack(piece) for Kings.
@Justin It totally does, at first. It gets less silly the more your get brainwashed by OOP, and then it starts to seem like "just another way of doing things" :)