Draft

Placing Robots

Description:

You are making a simple game where there is a 10x10 map, with the player starting at (5,5). You want a function to place a certain number of robots that the player will have to escape from. This function will take the map (a 10x10 array) and the number of robots to add. It should return the map with the number of robots added to it in random locations. Remember you can't place robots on top of each other (or the player)!

If there isn't enough space, the map should be returned with as many spaces filled as possible.

On the map: "." = empty space "P" = player "r" = robot

So the input map will be:

var map = [
[".",".",".",".",".",".",".",".",".",".",],
[".",".",".",".",".",".",".",".",".",".",],
[".",".",".",".",".",".",".",".",".",".",],
[".",".",".",".",".",".",".",".",".",".",],
[".",".",".",".",".",".",".",".",".",".",],
[".",".",".",".",".","p",".",".",".",".",],
[".",".",".",".",".",".",".",".",".",".",],
[".",".",".",".",".",".",".",".",".",".",],
[".",".",".",".",".",".",".",".",".",".",],
[".",".",".",".",".",".",".",".",".",".",],
];

And an example output map for place_robots(map,10) could be:

[
[".",".","r",".",".",".",".",".",".",".",],
["r",".",".",".",".","r",".","r",".",".",],
[".",".",".",".",".",".",".",".",".",".",],
[".",".",".",".",".",".",".",".",".",".",],
[".",".",".","r",".",".",".","r",".",".",],
["r",".",".",".",".","p",".",".",".",".",],
[".",".",".",".",".",".",".",".",".",".",],
[".",".",".",".",".",".",".",".",".",".",],
["r",".",".","r",".",".",".","r",".",".",],
[".",".",".",".",".",".",".",".",".",".",],
];
Games
Arrays

Similar Kata:

Stats:

CreatedJun 28, 2014
Warriors Trained33
Total Skips2
Total Code Submissions220
Total Times Completed15
JavaScript Completions15
Total Stars0
% of votes with a positive feedback rating0% of 0
Total "Very Satisfied" Votes7
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes2
Ad
Contributors
  • ollyfg Avatar
Ad