Created
October 31, 2012 14:56
-
-
Save knaveofdiamonds/3987483 to your computer and use it in GitHub Desktop.
Snakes and ladders Kata
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def board(size, tunnels) | |
Hash.new {|_,i| i }. | |
merge(Hash[(1..6).map{|i| [size + i, size - i] }]). | |
merge(tunnels) | |
end | |
def move(board, players, player, roll) | |
players[player] = board[ players[player] + roll ] | |
[players, next_player(players.size, player, roll)] | |
end | |
def next_player(number_of_players, player, roll) | |
roll == 6 ? player : ((player + 1) % number_of_players) | |
end | |
def winner(size, positions) | |
positions.index(size) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment