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: >---#<---X---<X<--#-$
> means the start of the game
- means a position without danger
< 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: >---#<---X---<X<--#-$
kid-A: [3,6,6,5,2,1]
kid-B: [4,5,3,5,5,5]
output: A
Explaining:
>---#<---X---<X<--#-$ # both kids in position
B--A#<---X---<X<--#-$ # kid-A moved 3 to -
B--A#<---X---<X<--#-$ # kid-B moved 4 to # and returned home
B---#<---A---<X<--#-$ # kid-A moved 6 to X and will wait one round
B---#<---A---<X<--#-$ # kid-B moved 5 to < returned one to # and returned home
>--B#<---A---<X<--#-$ # kid-B moved 3 to -
>--B#<---X---<A<--#-$ # kid-A moved 6 to < returned one to X and will wait again
>---#<--BX---<A<--#-$ # kid-B moved 5 to -
>---#<---X--B<A<--#-$ # kid-B moved 5 to < returned one to -
>---#<---X--B<X<--#A$ # kid-A moved 5 to -
>---#<---X---<X<-B#A$ # kid-B moved 5 to -
>---#<---X---<X<-B#-$A # kid-A moved 2 and won the game!
Example 2:
board: >-<<<<<$
kid-A: [1,2,3]
kid-B: [5,5,4]
output: 0
Example 3:
board: >-<-<#<-<-<-$
kid-A: [5,4,2]
kid-B: [1,1,1]
output: B
Explaining:
>-<-<#<-<-<-$ # both kids in position
>-<-<#<-<-<-$ # kid-A moved 5 to # returned home
AB<-<#<-<-<-$ # kid-B moved 1 to -
>B<A<#<-<-<-$ # kid-A moved 4 to < returned one to -
>B<A<#<-<-<-$ # kid-B moved 1 to < returned one to -
AB<-<#<-<-<-$ # kid-A moved 2 to # returned home
AB<-<#<-<-<-$ # kid-B moved 1 to < returned one to -
Current position: (A:0, B:1) output: B