Befunge Chess is an esolang mini-game I invented that is centered around the Befunge esolang. The general gist of the game is to make the instruction pointer land on a specific target cell while avoiding the opponent's target cell. Today's challenge isn't to play the game, but to simply execute arbitrary boards.
The Rules of Befunge Chess (Context)
Quoting the Befunge esolangs article:
A Befunge program is laid out on a two-dimensional playfield of fixed size. The playfield is a rectangular grid of ASCII characters, each generally representing an instruction. The playfield is initially loaded with the program. Execution proceeds by the means of a [instruction pointer]. This points to a grid cell on the playfield. The instruction pointer has inertia: it can travel to any of the four cardinal directions, and keep traveling that way until an instruction changes the direction. The instruction pointer begins at a set location (the upper-left corner of the playfield) and is initially travelling in a set direction (right). As it encounters instructions, they are executed. [C]ontrol flow is done by altering the direction of the [instruction pointer], sending it to different literal code paths.
Befunge chess is a 2-player game. The players are called
At the start of the game, a board is randomly generated with two cells already filled, like so:
..... ..... .A... ..... ...B.
A and the
B can go anywhere on the board - their position is arbitrary. However, they cannot go in the top left corner where the instruction pointer would start.
Players take turns placing commands from a modified subset of Befunge commands onto the board in an attempt to make the instruction pointer reach their target square. These commands will be described in their own section. The board is not executed during this phase.
On a player's turn, if they feel that the instruction pointer will land on their target cell, they can choose to execute the board instead of placing a command. This initiates the end sequence of the game. If the instruction pointer does reach the executing player's target piece they win. If it doesn't (i.e. it a) reaches the opponent's target piece, b) reaches a cell it's already passed or c) errors), then the other player wins. Note: stop condition b means that there aren't any infinite loops - hence there will always be an outcome for every possible board
If the board is completely full, then execution is automatic. Errors/reaching an already passed square lead to a tie.
While the full mini-game I devised uses 28 commands, you'll be required to implement an 8 command subset:
^ Set the instruction pointer's direction to up (north) v Set the instruction pointer's direction to down (south) < Set the instruction pointer's direction to left (west) > Set the instruction pointer's direction to right (east) # Jump over the next cell . Do nothing (NOP) A Player A's target piece B Player B's target piece
The instruction pointer starts in the top left corner (0, 0). It initially moves right (east). It transverses the board until one of the following conditions is met:
A) A player piece is reached B) An error occurs C) A cell is reached that has already been passed once
Note that if the instruction pointer would fall off the board (i.e. reach an edge), it "wraps around to the other side:
...> # upon reaching the >, the instruction pointer would wrap back to the first cell in the row .... .v.. # if the v were reached, the instruction pointer would continuing heading down and then wrap around to the second column in the first row. ....
Your challenge is to output the outcome of executing the board.
- The board is guaranteed to contain an
>....v. .....A. ..B.... .......
>.v..v. ....>A. .<B.... ..^....
.... .... .AB. ....
Note that this is the smallest possible board you have to handle.
.v. >.A ^<B
This is because the middle cell is passed twice.
>v.... B#.... .A.... ^>....
...^^... ..<A>... .^.v.... <B>..... .v......
- Input/output can be given in any reasonable/convenient format
- The board size will always be rectangular (have a length and a width), will always be valid (have
Band a mixture of commands).
- The board size will always be 2x2 or larger.
- You can use any character set you like for the different tiles, as long as you have 8 consistent characters/values.
Finally, this is code-golf, so the shortest program in each language wins.