Snakes and Ladders - Matlab help!

651 Views Asked by At

I'm trying to write a simulation for snakes and ladders in Matlab but I'm stuck.

How would I write something to check if the player is on a square that has a snake or ladder? I read somewhere that in Python you can just use something like "if newposition in snakes" (where snakes is an array of all the snake related moves), but I don't think the "in" command works in Matlab?

I was thinking I could just do "if newposition = 2, position=5" but I'm sure there's an easier way than making 100 if statements right...

Any help would be great, thanks

1

There are 1 best solutions below

0
On

Here is one suggestion: Have one array
SnakeHead = [15,17,93];
and another
SnakeTail = [5,6,88];
then during the game

b = find(newposition==SnakeHead);
if length(b)>0,
position = SnakeTail(b);
end;