Night 24: Move around
今夜の課題はPythonまたは疑似コードですでに完了しています。両方の言語で完了として記録されます。よければもう一度練習してください。
Tonight: move around
- Your pet has a map. Tonight it walks around on it!
- Nothing new to learn: you use
INPUT,WHILEandIFon a map.
Words for tonight
| Word | Meaning |
|---|---|
| move | go from one place to another |
| position | where something is: X and Y |
| command | a word that tells the program what to do |
Where is the pet?
- Two numbers say where the pet is:
X(left–right) andY(up–down). Y = 1is the top row. So "up" makesYsmaller.
| Move | Change |
|---|---|
| up | Y ← Y - 1 |
| down | Y ← Y + 1 |
| left | X ← X - 1 |
| right | X ← X + 1 |

Choose with CASE OF
- One variable, many choices:
CASE OFis neat for commands.
DECLARE X, Y : INTEGER
DECLARE Move : STRING
X ← 3
Y ← 3
Move ← "up"
CASE OF Move
"up" : Y ← Y - 1
"down" : Y ← Y + 1
"left" : X ← X - 1
"right" : X ← X + 1
ENDCASE
OUTPUT "Now at ", X, " ", Y
- In the tasks, the moves come from
INPUTuntil the player typesstop.
Stay on the map
- Check the edge before you move.
DECLARE X : INTEGER
DECLARE Move : STRING
X ← 1
Move ← "left"
IF Move = "left" AND X > 1 THEN
X ← X - 1
ENDIF
OUTPUT X
Xstays 1: the pet is already at the left wall.- Now take your pet for a walk!
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
Your pet is at X ← 3, Y ← 3. Read one move: up, down, left または right. Change X または Y, then output them. left gives 2 3. up makes Y smaller.
実行ボタンをクリックして出力を確認してください。
難易度 3/5 · 200 コイン + 今日初回達成時の小ボーナス
Now read moves again and again, until the move is stop. Change X かつ Y for each move. At the end, output X かつ Y.
実行ボタンをクリックして出力を確認してください。
難易度 3/5 · 200 コイン + 今日初回達成時の小ボーナス
The map is 5 × 5: X かつ Y go from 1 から 5. Do not let the pet walk off the map. A move into the wall does nothing.
実行ボタンをクリックして出力を確認してください。
難易度 4/5 · 280 コイン + 今日初回達成時の小ボーナス
After the moves, draw the 5 × 5 map: P where the pet is, . everywhere else. Row Y and column X hold the P.
実行ボタンをクリックして出力を確認してください。