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:
xxxx___oooo
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 4
to say 'move this piece at tile 1 to tile 4'.quit
would 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 orquit
). - Outputs for players winning and invalid must be
P1 WINS
,P2 WINS
, andINVALID
, 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, thex
moving right would change the board to_oox_o
.xxooo_
. Here, the farthest-leftx
could move to yield_xooox
, which captures theo
s, leaving_x___x
.x__oox
. Here, theo
s are not captured (there is still a gap). Capture is not possible because you can't move through unoccupied spaces. Thex
on the left could only move one space, because there are no other pieces in between (leaving_x_oox
).
- Multiple adjacent pieces can be captured at once if the group is surrounded by the opponent's pieces. E.g. from
x_oox
to_xoox
will capture botho
s and result in_x__x
. - If after a move, you first capture the opponent's pieces, before checking if your own piece should be remove. Take two examples:
o_oxx
tooxox_
. First, the secondo
is captured,ox_x_
, so the firstx
remains on the board.o_oox
tooxoo_
. This time, none of theo
s are captured, so thex
is 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.