2 kyu

Three Dots--Play game Series #8

50 of 80myjinxin2015

Description:

Play game Series #8: Three Dots

Welcome

In this kata, we'll playing with three dots.

Task

You are given a gamemap, like this:

+------------+
|RGY         | +,-,| --> The boundary of game map
|            | *     --> The obstacle
|     **     | R,G,Y --> Three Dots with different color(red,green,yellow)
|     **     | r,g,y --> The target position of three dots
|            |           You should move R to r, G to g and Y to y
|         rgy|
+------------+

In the testcase, it displayed like this:

Your task is calculate a path to move three dots from the initail position to the target position. The result should be a string. Use ↑↓←→ representing four directions(up,down,left and right).

Moving Rules

  • When the move command(↑↓←→) is executed, the three dots move in the same direction at the same time unless the boundary or barrier is in front of them.
  • Only the dot blocked by the obstacle will stop moving, and the dots that does not encounter obstacles will continue to move.

Like the example above, you can return a path like this:

"→→→→→→→→→↓↓↓↓↓"

After move right x 9:

After move down x 4:

So easy! right? ;-) Please write a nice solution to solve this kata. I'm waiting for you, code warrior ^_^

Note

  • You can assume that all test cases have at least one possible solution. Of course, usually it has many solutions, and you just need to return one of them.
  • Somethimes, the obstacle/boundary may be your enemy or your friend ;-)

Examples

Let's see some harder examples:

For gameMap =

+------------+
|R           |
|G           |
|Y    **     |
|     **    r|
|           g|
|           y|
+------------+

The output can be "→→→→→←↓↓↓↓→→→↑↑→→→→→↓"

Let's see the moving step by step:

initial game map:

First we move three dots to the right: →→→→, after move right x 4:

Then, continue the moving:

Now, we can see: Y was stoped, but R and G move to right.

Hmm.. we should move to left 1 step:

Then moving the dots downward: ↓↓↓

Hmm.. Not enough. Continue to move downward:

Now dots can finally move to the right: →→→

Hey! Wait, Their shape is incorrect:

So we need some extra steps: ↑↑

Now we can move to the right again ;-) →→→→

r is covered by G, then

r is covered by G, g is covered by Y, then

r is covered by R, g is covered by G and y is covered by Y. You win the game ;-)

For gameMap =

+------------+
|R           |
|G    **     |
|Y    **     |
|            |
|     **    r|
|     **    g|
|           y|
+------------+

The output can be "→→→→↓→↓→↓→↓→↓→→→→→↓"

initial game map:

→→→→

→→→→→

Recommand

You can submit the example solution(preloaded in the initail code) to see how it works ;-)

Play Games Series

Puzzles
Games
Game Solvers

Stats:

CreatedAug 30, 2017
PublishedAug 30, 2017
Warriors Trained1333
Total Skips432
Total Code Submissions1280
Total Times Completed80
JavaScript Completions50
Python Completions33
Total Stars79
% of votes with a positive feedback rating100% of 26
Total "Very Satisfied" Votes26
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes0
Total Rank Assessments3
Average Assessed Rank
2 kyu
Highest Assessed Rank
2 kyu
Lowest Assessed Rank
2 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • kazk Avatar
  • user9644768 Avatar
  • lachesism Avatar
Ad