Alak was invented by the mathematician A. K. Dewdney, and described in his 1984 book Planiverse. The rules of Alak are simple:
Alak is a two-player game played on a one-dimensional board with eleven slots on it. Each slot can hold at most one piece at a time. There's two kinds of pieces, "x" and "o". x's belong to one player, o's to the other. The initial configuration of the board is:
The players take turns moving. At each turn, each player can move only one piece, once. A player cannot pass up on his turn. A player can move any one of his pieces to the next unoccupied slot to its right or left, which may involve jumping over occupied slots. A player cannot move a piece off the side of the board.
If a move creates a pattern where the opponent's pieces are surrounded, on both sides, by two pieces of the mover's color (with no intervening unoccupied blank slot), then those surrounded pieces are removed from the board.
The goal of the game is to remove all of your opponent's pieces, at which point the game ends. Removing all-but-one ends the game as well, since the opponent can't surround you with one piece, and so will always lose within a few moves anyway.
I found this game online and was wondering: can it be golfed?
Rules of the golf
- Your code must follow all the rules in the game, handling captures, proper moving, etc. (only exception is you don't have to add a bot, but you must have both players controlled somehow, and one player must be human).
- Input must be move piece at tile X to tile Y, or quit. For example, you can use
1 4to say 'move this piece at tile 1 to tile 4'.
quitwould end the program, although using Control-C would be acceptable. You also have to check if a move is invalid (by going outside the board or moving somewhere that you would have to cross over unoccupied spaces to get to or sending a message that is not a pair of tiles or
- Outputs for players winning and invalid must be
P2 WINS, and
INVALID, respectively. (All of these are 7 characters.)
- Output must show the board. That's all that's required.
- It doesn't matter if you use any aids like numbered tiles or other pieces.
The challenge ends if:
- One answer gets 50 votes
- One answer remains the top-voted for 3 weeks, and no other answers were posted in that time
and the challenge has at least 3 answers (so there's some real competition).
Rules of the game
- The player on the left must start first.
- Only one piece occupies a square at a time. You move the piece left or right until it hits an unoccupied space. The board does not wrap, and you can't move through unoccupied areas. For example:
xoo__o. Here, the
xmoving right would change the board to
xxooo_. Here, the farthest-left
xcould move to yield
_xooox, which captures the
x__oox. Here, the
os are not captured (there is still a gap). Capture is not possible because you can't move through unoccupied spaces. The
xon the left could only move one space, because there are no other pieces in between (leaving
- Multiple adjacent pieces can be captured at once if the group is surrounded by the opponent's pieces. E.g. from
_xooxwill capture both
os and result in
- If after a move, you first capture the opponent's pieces, before checking if your own piece should be remove. Take two examples:
oxox_. First, the second
ox_x_, so the first
xremains on the board.
oxoo_. This time, none of the
os are captured, so the
xis captured instead.
- If you have only one piece, the game ends, because you can't capture with just one piece.
Let the games begin! I look forward to seeing what you come up with.