Skip to main content
deleted 5103 characters in body
Source Link
lyxal
  • 34.3k
  • 1
  • 20
  • 47

Execute a Befunge Chess Boarddiddly darn posted

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.

Source

Befunge chess is a 2-player game. The players are called A and B At the start of the game, a board is randomly generated with two cells already filled, like so:

.....
.....
.A...
.....
...B.

The A and the B can go anywhere on the board - their position is arbitrary.

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.

Commands

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

Execution

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 first column in the first row.
....

Your challenge is to output the outcome of executing the board.

Testcases

  • The board is guaranteed to contain an A and B piece
>....v.
.....A.
..B....
.......

Output: A


>.v..v.
....>A.
.<B....
..^....

Output: B

....
....
.AB.
....

Output: Tie


AB

Output: A

Note that this is the smallest possible board you have to handle.


.v. 
>.A
^<B 

Output: Tie

This is because the middle cell is passed twice.


>v....
B#....
.A....
^>....

Output: B


...^^...
..<A>...
.^.v....
<B>.....
.v......

Output: Tie

Extra Rules

  • 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 A, B and a mixture of commands).
  • The board size will always be 2x1 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 , so the shortest program in each language wins.

Feedback

  • How can this be made clearer?
  • Do I need to explain the rules of Befunge chess a bit more?
  • What can be removed to make it easier/more approachable to answer?

Execute a Befunge Chess Board

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.

Source

Befunge chess is a 2-player game. The players are called A and B At the start of the game, a board is randomly generated with two cells already filled, like so:

.....
.....
.A...
.....
...B.

The A and the B can go anywhere on the board - their position is arbitrary.

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.

Commands

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

Execution

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 first column in the first row.
....

Your challenge is to output the outcome of executing the board.

Testcases

  • The board is guaranteed to contain an A and B piece
>....v.
.....A.
..B....
.......

Output: A


>.v..v.
....>A.
.<B....
..^....

Output: B

....
....
.AB.
....

Output: Tie


AB

Output: A

Note that this is the smallest possible board you have to handle.


.v. 
>.A
^<B 

Output: Tie

This is because the middle cell is passed twice.


>v....
B#....
.A....
^>....

Output: B


...^^...
..<A>...
.^.v....
<B>.....
.v......

Output: Tie

Extra Rules

  • 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 A, B and a mixture of commands).
  • The board size will always be 2x1 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 , so the shortest program in each language wins.

Feedback

  • How can this be made clearer?
  • Do I need to explain the rules of Befunge chess a bit more?
  • What can be removed to make it easier/more approachable to answer?
:
Source Link
lyxal
  • 34.3k
  • 1
  • 20
  • 47

>v....
B#....
.A....
^>....

Output: B


...^^...
..<A>...
.^.v....
<B>.....
.v......

Output: Tie

  • 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 A, B and a mixture of commands).
  • The board size will always be 2x1 or larger.
  • You can use any character set you like for the different tiles, as long as you have 118 consistent characters/values.
  • 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 A, B and a mixture of commands).
  • The board size will always be 2x1 or larger.
  • You can use any character set you like for the different tiles, as long as you have 11 consistent characters.

>v....
B#....
.A....
^>....

Output: B


...^^...
..<A>...
.^.v....
<B>.....
.v......

Output: Tie

  • 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 A, B and a mixture of commands).
  • The board size will always be 2x1 or larger.
  • You can use any character set you like for the different tiles, as long as you have 8 consistent characters/values.
:
Source Link
lyxal
  • 34.3k
  • 1
  • 20
  • 47

While the full mini-game I devised uses 28 commands, you'll be required to implement a 11an 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)
?        Set the instruction pointer to a direction chosen randomly (uniform chance) from [up, down, left, right] 
#        Jump over the next cell
|        Set the instruction pointer to either up or down (chosen randomly [uniform chance])
_        Set the instruction pointer to either left or right (chosen randomly [uniform chance])
.        Do nothing (NOP)
A        Player A's target piece
B        Player B's target piece
  • The board is guaranteed to contain an A and B piece
  • The result may not always be deterministic

Possible output(s)Output: A

Possible output(s)Output: B

....
....
.AB.
....

Possible output(s): Tie

.....?.....
...........
..B..?.....
...........
.....?.A...
...........

Possible output(s): A, B, Tie

This is because the ? randomly switches the direction, so the winner is determined at run time.


v.....|..
>...|.A..
..B?_....

Possible output(s)Output: A, B, Tie

This is because there are multiple commands that randomly switches the direction, so the winner is determined at run time.

Possible output(s)Output:   A

Possible output(s)Output: Tie

While the full mini-game I devised uses 28 commands, you'll be required to implement a 11 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)
?        Set the instruction pointer to a direction chosen randomly (uniform chance) from [up, down, left, right] 
#        Jump over the next cell
|        Set the instruction pointer to either up or down (chosen randomly [uniform chance])
_        Set the instruction pointer to either left or right (chosen randomly [uniform chance])
.        Do nothing (NOP)
A        Player A's target piece
B        Player B's target piece
  • The board is guaranteed to contain an A and B piece
  • The result may not always be deterministic

Possible output(s): A

Possible output(s): B

....
....
.AB.
....

Possible output(s): Tie

.....?.....
...........
..B..?.....
...........
.....?.A...
...........

Possible output(s): A, B, Tie

This is because the ? randomly switches the direction, so the winner is determined at run time.


v.....|..
>...|.A..
..B?_....

Possible output(s): A, B, Tie

This is because there are multiple commands that randomly switches the direction, so the winner is determined at run time.

Possible output(s): A

Possible output(s): 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 board is guaranteed to contain an A and B piece

Output: A

Output: B

....
....
.AB.
....

Output: Tie

Output:   A

Output: Tie

added 351 characters in body
Source Link
lyxal
  • 34.3k
  • 1
  • 20
  • 47
Loading
added 165 characters in body
Source Link
lyxal
  • 34.3k
  • 1
  • 20
  • 47
Loading
Source Link
lyxal
  • 34.3k
  • 1
  • 20
  • 47
Loading