Showing posts with label bf joust. Show all posts
Showing posts with label bf joust. Show all posts

Friday, 22 May 2009

BF Joust King of the Hill

BF Joust is a capture the flag programming game based on the esoteric Brainf*** programming language. Recently ais523 revised the language and enviroment, setting up a king of the hill tournament.

The game is played between two programs on a tape with a length randomly chosen between 10 and 30 cells. The cells initially contain 0 with the exception of the cells at either end which contain the flag 128.

Each program views the tape with their own flag on the left and the opponent's flag on the right. The object of the game is to find and set the opponents flag to 0 and keep it 0 for two consecutive cycles. If a program's pointer points to a location off the tape, it loses.

Here's a quick summary of the instruction set:

OpDescription
<move the pointer to the left
>move the pointer to the right
+add 1 to the value stored at pointer
-subtract 1 from the value stored at pointer
[jump past the matching ] if the cell at pointer is 0
]jump to instruction after matching [ unless cell at pointer is 0
.no operation, do nothing

The interpreter also understands certain macros. Instructions inside parentheses are repeated a number of times. For example (>-)*4 expands to >->->->-.

For full details see the rules on the BF Joust Wiki page and check the current hill standings. To submit a program to the BF Joust hill, join the channel #esoteric on irc.freenode.net and send a message to egobot:
/msg egobot !bfjoust program_name program_code
It isn't possible to remove a program, but it can be replaced by submitting another with the same name.

Finally, I'll leave you with the code for shortsword the current king of the hill with 100% wins ;-)
(>++>--)*2(>)*6([-[+]]>)*20
The standings:
ID Score Pts Program
18 90.00 18 shortsword.bfjoust
19 71.12 12 stranger.bfjoust
16 69.75 11 scythe_impomatic.bfjoust
1 59.38 9 ais523_attack5.bfjoust
6 42.50 4 ais523_defend5.bfjoust
2 41.50 6 ais523_attackslow.bfjoust
7 38.00 2 asie1.bfjoust
0 37.00 0 ais523_attack2.bfjoust
12 32.38 -1 fool1.bfjoust
9 28.00 0 attack1.bfjoust
4 18.25 -4 ais523_defend0_1.bfjoust
3 16.25 -5 ais523_defend0.bfjoust
11 11.88 -9 ehirdomatic.bfjoust
10 10.50 -7 defend1.bfjoust
5 10.50 -5 ais523_defend1.bfjoust
17 5.62 -4 shield.bfjoust
15 5.62 -9 programname.bfjoust
14 2.62 -10 nop.bfjoust
8 2.62 -8 asie2.bfjoust
20 0.00 0 stuff.bfjoust
13 0.00 0 iwin.bfjoust
Let me know if you have any success with BF Joust.

Friday, 6 February 2009

Hostile Programming on the BF Joust Hill

For the past couple of days I've been playing on the BF Joust Hill. BF (or Brainf***) is a simple programming language with 8 instructions as follows:

OpDescription
<move pointer to the left
>move pointer to the right
+increment the value stored at pointer
-decrement the value stored at pointer
[jump past the matching ] if the cell at pointer is 0
]jump to the matching [
,character input (not used by BF Joust)
.character output (not used by BF Joust)

The object of the game is to capture the flag. The size of memory is chosen at random in the range 135 - 167. Memory is initialise to 0. Both flags are set to 128. Your flag is at the far left end of memory, the opponent's flag is to the right.

The object is to set the opponent's flag to 0. If your flag is set to 0, or your pointer runs off either end of memory, you lose.

A simple strategy would be to keep moving right, setting any non-zero memory to 0:
[>[-]-]
Against the last 15 warriors on BF Joust, this scores 76. The maximum score is 300.

What would happen if we build a decoy to slow down the opponent? We could set a few non-zero memory cells next to the flag:
>+>->+>->+>->+>->+>-[>[-]-]
The new score is 103. Some memory cells are incremented to 1, others are decremented to -1 (255). It doesn't matter whether the opponent is using [-] or [+] to set memory to zero, it will be delayed for hundreds of cycles.

How can we avoid wasting time if the opponent has a similar decoy? One technique is to increment the memory cell just before entering the decrement loop:
>+>->+>->+>->+>->+>-[>+[-]-]
If there's a -1 decoy, it's changed to 0 and the [-] loop is never executed. The new code scores 140.

We can prevent the opponent from benefiting from a similar technique as follows:
>+++>--->+++>--->+++>--->+++>--->+++>---[>+[-]-]
This scores 181 :-)

Finally, we know the enemy's flag is in the memory range 135-167. We can quickly skip ahead to location 135:
>+++>--->+++>--->+++>--->+++>--->+++>---
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>
+[>+[-]-]
Scoring 209!
Rank             Program  TOT
-----------------------------
1 woggle_050109_2 246
2 joust12 240
3 woggle_050109_1 228
4 woggle_060109_3 213
* 5 Challenger 209
6 wooble_231208_2 188
7 ehird_060109_1 143
8 BPilgrim_271208_1 132
9 wooble_191208_1 130
10 ais523_201208_1 121
11 ehird_201208_4 103
12 BPilgrim_271208_2 77
13 ehird_191208_3 55
14 comex_241208_1 46
15 comex_241208_3 16
16 comex_241208_2 16
-----------------------------
Let me know if you've discovered a better technique, or if you can beat 209.