Your goal is to write a program that creates a random 10x10 map using 0
, 1
, and 2
, and finds the shortest path from top-left to bottom-right, assuming that:
0 represents a grass field: anyone can walk on it;
1 represents a wall: you cannot cross it;
2 represents a portal: when entering a portal, you can move to any other portal in the map.
Specs:
- The top-left element and the bottom-right one must be 0;
- When creating the random map, every field should have 60% chance of being a 0, 30% of being a 1 and 10% of being a 2;
- You can move in any adjacent field (even diagonal ones);
- Your program should output the map and the number of steps of the shortest path;
- If there isn't a valid path that leads to the bottom-right field, your program should output the map only;
- You can use any resource you'd like to;
- Shortest code wins.
Calculating steps:
A step is an actual movement; every time you change field, you increment the counter.
Output:
0000100200
0100100010
1000000111
0002001000
1111100020
0001111111
0001001000
0020001111
1100110000
0000020100
9