Let's play some boardgame! Introduction

Boardgames are a classic play between kids, but there are some kids that feel bored playing a boardgame step by step. Now they want the result to be shown before they put their hands on the board.

Challenge

Suppose this boardgame: &gt;---#&lt;---X---&lt;X&lt;--#-$

&gt;   means the start of the game
-   means a position without danger
&lt;   means the player should return one step back
X   means the player won't move next round
#   means a portal where the player returns to the start position
$   the first player to get there or after there wins the game


The input consists of a string with the boardgame's aspects described above and two arrays with some values (from 1 to 6) in order that both players (kid A and kid B) had got when playing one cube.

Both arrays will always have the same length >= 1.

The kid A always start the game.

You must output the kid which got the end or closer to the end first.

If neither one got the end and both kids stay at the same position print 0 or any other falsy value.

If one array runs out while the other has remaining dice rolls (due to one player missing several turns on Xs), the remaining dice rolls should be used up.

For this task, you can create a program/function, that reads input from stdin, or take parameters/arguments and output/return/print the winner kid.

Since this is code-golf, shortest answer in bytes wins!

Example Input and Output

You can also use diferrent formats of input, but you should only take the boardgame, the kid-A and the kid-B values.

Example 1:

board:  &gt;---#&lt;---X---&lt;X&lt;--#-$
kid-A:  [3,6,6,5,2,1]
kid-B:  [4,5,3,5,5,5]

output: A


Explaining:

&gt;---#&lt;---X---&lt;X&lt;--#-$     # both kids in position
B--A#&lt;---X---&lt;X&lt;--#-$     # kid-A moved 3 to -
B--A#&lt;---X---&lt;X&lt;--#-$     # kid-B moved 4 to # and returned home
B---#&lt;---A---&lt;X&lt;--#-$     # kid-A moved 6 to X and will wait one round
B---#&lt;---A---&lt;X&lt;--#-$     # kid-B moved 5 to &lt; returned one to # and returned home
&gt;--B#&lt;---A---&lt;X&lt;--#-$     # kid-B moved 3 to -
&gt;--B#&lt;---X---&lt;A&lt;--#-$     # kid-A moved 6 to &lt; returned one to X and will wait again
&gt;---#&lt;--BX---&lt;A&lt;--#-$     # kid-B moved 5 to -
&gt;---#&lt;---X--B&lt;A&lt;--#-$     # kid-B moved 5 to &lt; returned one to -
&gt;---#&lt;---X--B&lt;X&lt;--#A$     # kid-A moved 5 to -
&gt;---#&lt;---X---&lt;X&lt;-B#A$     # kid-B moved 5 to -
&gt;---#&lt;---X---&lt;X&lt;-B#-$A    # kid-A moved 2 and won the game!




Example 2:

board:  &gt;-&lt;&lt;&lt;&lt;&lt;$
kid-A:  [1,2,3]
kid-B:  [5,5,4]

output: 0




Example 3:

board:  &gt;-&lt;-&lt;#&lt;-&lt;-&lt;-$
kid-A:  [5,4,2]
kid-B:  [1,1,1]

output: B


Explaining:

&gt;-&lt;-&lt;#&lt;-&lt;-&lt;-$     # both kids in position
&gt;-&lt;-&lt;#&lt;-&lt;-&lt;-$     # kid-A moved 5 to # returned home
AB&lt;-&lt;#&lt;-&lt;-&lt;-$     # kid-B moved 1 to -
&gt;B&lt;A&lt;#&lt;-&lt;-&lt;-$     # kid-A moved 4 to &lt; returned one to -
&gt;B&lt;A&lt;#&lt;-&lt;-&lt;-$     # kid-B moved 1 to &lt; returned one to -
AB&lt;-&lt;#&lt;-&lt;-&lt;-$     # kid-A moved 2 to # returned home
AB&lt;-&lt;#&lt;-&lt;-&lt;-$     # kid-B moved 1 to &lt; returned one to -

Current position: (A:0, B:1) output: B
Perl, 188 180 + 2 = 182 bytes

Wuhuu, got to use goto.

@q=/.(?!$)/g,next if$w=$e=!@q;for(@F){a:$w+=$_;$_=$q[$w];/&lt;/?($_=-1,goto a):/X/?$e++:/#/?$w=0:!$_&amp;&amp;last;$e++}$r+=$"lt$r?-$w:$w;$t+=$"lt$t?-$e:$e-1}{say$w&gt;@q?$t&lt;0?B:A:!$r?0:$r&lt;0?B:A


Requires -a and -E|-M5.010:

$ echo $'&gt;-&lt;-&lt;#&lt;-&lt;-&lt;-&lt;-$\n5 4 2\n1 1 1' | perl -M5.010 boardgame.pl
B


Somewhat ungolfed version:

#!/usr/bin/perl -a

# Read all but last char from the board into an array
@board = /.(?!$)/g,next if $pos = $turns = !@board;
for (@F) {
    a:
    $pos+=$_;
    $_=$board[$pos];
    /&lt;/?($_=-1,goto a):
    /X/?$turns++:
    /#/?$pos=0:
    # End of Game (Victory!)
    !$_&amp;&amp;last;

    $turns++
}
# Make sure '$pos_diff' and '$turns_diff' are not zero by checking against [:space:]
# ' ' is less than 0 on the ascii table
$pos_diff += $"lt$pos_diff ? -$pos : $pos;
$turns_diff += $"lt$turns_diff ? -$turns : $turns-1;
}{
    say $pos&gt;@board?
            $turns_diff&lt;0?B
            :A
        :
        !$pos_diff?0:
        $pos_diff&lt;0?B:
        A