function [ i, d ] = snakes_move ( i, snake, ladder )

%*****************************************************************************80
%
%% snakes_move() takes one move in a game of Snakes and Ladders.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    17 July 2016
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer I, the current location.
%
%    integer SNAKE(101,1), LADDER(101,1), define the snakes and
%    ladders.  If a player lands on square I, then if SNAKE(I) is not I,
%    the player is immediately moved to a previous square whose index
%    is SNAKE(I).  Similarly, if LADDER(I) is not I, then player is
%    immediately taken to a later square whose index is LADDER(I).
%
%  Output:
%
%    integer I, the current location.
%
%    integer D, the value of the die roll, between 1 and 6.
%
  rng ( 'shuffle' );
%
%  O is the offset, which is 1 for 1-based languages.
%
  O = 1;
%
%  Roll the die.
%
  d = randi ( [ 1, 6 ], 1 );
%
%  Move from I to I + D.
%
  i = i + d;
%
%  Your position can't exceed 100.
%
  i = min ( i, 100 );
%
%  If we landed on a snake, we slide down.
%
  i = snake ( i + O ) - O;
%
%  If we landed on a ladder, we climb up.
%
  i = ladder ( i + O ) - O;

  return
end

