字幕表 動画を再生する
Dawn and the train are both breaking when Ethic and Hedge arrive in the woods.
エシックとヘッジが森林に着く頃には 日が昇り始め 列車は速度を緩めていました
The adventurers have recovered the first artifact—
この2人の冒険者たちは 1つめのアイテム―
the Node of Power—
力の石を手に入れて
and have come to the 198forest in search of the second.
2つめのアイテムを探しに 198番森林へやってきました
Here they're welcomed by the director of the colony, Octavia.
ここで2人は共同体の指導者 オクタヴィアに迎えられました
She established this treehouse sanctuary
ロボットのおかげで 仕事をする必要がなくなってから
after the robots freed everyone from having to work.
彼女はこのツリーハウスの 楽園を作ったのです
It was meant to be a haven where people could follow their passions,
ここは人々が 情熱の赴くままに過ごし 工芸に打ち込み
take up crafts, and find fulfillment.
充足感を得られる 安息の地になるはずでした
Which they did… at first.
最初は そうでした
Some years ago everyone forgot the point.
数年前 人々は目的を 忘れてしまい
They abandoned arts and crafts
芸術や工芸をやめて
and instead just painted and exhibited pictures of themselves
ただ自画像を描いては 展示することを
over, and over, and over.
ひたすら繰り返すようになりました
The location of the second artifact is no secret;
2つめのアイテムの場所は 明らかで
it's in a tower, guarded by a garrison of bots,
塔の中にありますが 固く守られていて
a bottomless ravine, and who knows what other traps.
ロボットの軍団に 底なしの谷 その他どんな罠があるかわかりません
As soon as the tower went up with the node inside,
アイテムを収めた塔が そびえ立つようになると
human communication across the land went dark.
人々は通信ができなくなりました
Octavia's been after it for years,
オクタヴィアは何年も アイテムを盗みだそうとしてきましたが
but try as she might, the defenses thwart her.
いくら頑張っても 防御システムに阻まれてしまいます
In order to even get to the tower, the team will need a distraction.
塔に到達するだけでも 警備の目をそらす必要があります
Octavia has an idea:
オクタヴィアには 考えがありました
stir up the people through some well-intentioned vandalism.
自画像に悪意のない落書きをして 人々に騒ぎを起こさせるのです
The residents' paintings are all squares that come in different sizes,
居住者たちの作品はすべて 様々な大きさの正方形で
all an odd number of pixels across.
縦横が奇数のマス目になっています
Helper-bots pick up the finished portraits
お助けロボットが 完成した作品を拾い上げて
and hang them in public places for everyone to admire.
誰もが鑑賞できるように 公共の場に飾ります
There's a slim margin of time when Hedge can access the paintings.
ヘッジが作品に近づけるのは ほんの短い間だけです
If he were to deface each one with an X,
ヘッジがすべての作品に バツ印をつけて汚せば
the people would blame the helper-bots,
人々はお助けロボットに抗議し
creating just the distraction the team needs.
うまい具合に 目をそらせるでしょうが
If only it were so easy.
ことは それほど簡単ではありません
Hedge can't just paint an X—
ヘッジは 単にバツ印をつけることは できません
his painting processor requires very specific instructions.
ヘッジの描画プロセッサには 非常に具体的な指示が必要で
Treating the paintings as square grids,
絵画を正方形のマス目とみて
he can fill in one pixel, or little square, at a time.
1マスずつ塗ることになります
He can move forwards and make 90 degree turns over the canvas,
キャンバスの上で 前進と 90度回転はできますが
but can't move diagonally.
斜めに移動はできません
How does Ethic program Hedge to paint an X over each portrait?
ヘッジがすべての自画像に バツ印をつけるには
Pause now to figure it out for yourself.
エシックはどうプログラムすれば いいでしょう?
Here's a hint.
[ビデオをいったん止めて 自分で考えてみましょう]
Try drawing a square grid like this,
ヒントをあげましょう
and simulating Hedge's path over it.
こんな正方形のマス目を描いて
What patterns can you find to guide him?
ヘッジの動きを シミュレーションしてみましょう
Pause now to figure it out for yourself.
どんなパターンで動けば バツ印は描けるか?
The challenge here is to craft a set of instructions
[ビデオをいったん止めて 自分で考えてみましょう]
that will work for any square grid.
ここで難しいのは
Fortunately, one of the strengths of programming
マス目がどんなサイズでも 有効な指示を考えることです
is the flexibility to solve not just one problem,
幸い プログラミングのいいところは
but a whole class of them all at once.
1つの問題だけでなく 同じような問題を
It often helps to start with one case, and work towards the general.
一気に解決することが できるところです
Let's say we had this square.
ある場合についてまず考え それから一般化するとよいでしょう
Hedge can measure the length of its sides and store that number as a variable.
こんなマス目だったとします
Now, what we need is a plan for how Hedge will paint an X,
ヘッジは一辺の長さを測り その数字を変数として記憶します
pixel by pixel.
さて必要なのはヘッジが 1マスずつ塗りつぶして
There's more than one right answer for how to do this;
バツ印を描くための指示です
let's look at two.
これにはいくつも やり方がありますが
First, what if Hedge went row by row, like a typewriter?
2つほど考えてみましょう
If it's a 9 pixel by 9 pixel painting,
1つめは ヘッジが1行ずつ タイプライターのように動く場合です
in the first row he'd paint, skip 7, and then paint again.
1辺が9マスの絵の場合
In the second row he'd skip the first, paint, skip 5, and paint.
1行目では まず最初のマスを塗り 7マスとばして また塗ります
And so on.
2行目では 1マスとばしてマスを塗り 5マスとばして また塗ります
The pattern here is that for each row the pixels skipped at the beginning
これを続けていきます
go up by one,
ここで見られるパターンは 1行ごとに最初にとばすマスの数が
and the pixels skipped in the middle go down by 2.
1ずつ増加し
Things get more complicated when Hedge reaches the center.
真ん中でとばすマスの数は 2ずつ減少するというものです
Here there's a row with just one pixel painted.
ヘッジが中央に到達すると 話が変わり
Then the whole thing reverses—
この行で色がつくのは 真ん中の1マスだけで
the number of pixels skipped goes down by one each time on the left,
それからパターンが反対になります
and up by two each time in the middle.
とばす左側のマスの数は 1行ごとに1ずつ減っていき
Instructing Hedge to do this with a series of loops will work
真ん中でとばすマスの数は 1行ごとに2ずつ増えます
and is a perfectly fine solution.
この方法をループを使って ヘッジに指示すれば上手くいきますし
The main drawback is that this requires quite a bit of logic—
まったく問題ありませんが
knowing what to do in the middle, when to reverse the process,
この方法の難点は 処理の手順が煩雑になることです
and exactly how to reverse it.
中央ではどうするのか いつパターンが反対になり
So how might we approach this
どうやって反対にするのかを わかっている必要があります
so that the logic remains consistent from start to finish?
最初から最後まで
The key insight is to look at a grid as a series of concentric squares.
一定の方法でやることは できないでしょうか?
Each square follows the same pattern—
ポイントは マス目を同心状の正方形の 集まりと見なすことで
painted pixels in the corners, and unaltered pixels in between.
こうすれば各正方形を 同じように処理できます
So if we can figure out a way to paint one nested square,
角のマスに色をつけ 間のマスはそのままにすればいいのです
transition to the next, and repeat, we can paint them all.
そのため 1つの正方形に 色をつける方法がわかれば
Painting the outermost one is easy.
それを繰り返すことで すべてに色をつけることができます
Start in a corner and paint that pixel.
一番外側の四角に 色をつけるのは簡単です
If we call the length of the painting n,
角から始めて そのマスに色をつけます
fly forward n minus 1 spaces.
絵の1辺の長さをnとすると
Paint another pixel, and turn right.
n - 1 だけ前進して
Now do the whole thing again… and again.
1マス色をつけて右折します
Now move forward one less space, turn right, fly forward once,
同じことをあと2回繰り返します
and Hedge will be in the next concentric square
今度は1マス少ない距離を前進し 右折して1マス進みます
and ready to repeat the whole process.
これでヘッジは 次の正方形に移ったことになるので
Each square is n minus 2 pixels smaller than the last in length and width,
同じ過程を繰り返します
and we can follow this spiral pattern all the way to the center
正方形はそれぞれ 外側の正方形よりも 各辺の長さが 2 だけ小さくなります
with a loop and a variable that tracks how far Hedge should fly.
この渦巻き状のパターンを 中心に至るまで続ければよく
Is one of these methods better than the other?
ループと とばすマスの数を表す変数を使って 実行できます
It really depends on what you value.
どちらがより良い方法でしょう?
The strength of the spiral is the simplicity of finding a pattern
それは何を重視するかによります
and reusing the same logic from start to finish.
渦巻き状方式の長所は パターンがシンプルであることと
The advantage of the typewriter approach
最初から最後まで同じ方法を 使えるところです
is that it's a more generalized solution,
タイプライター方式の長所は
meaning it can be adapted much more simply to fill in any pattern.
より一般的な解決法で
For Ethic's sake, either will do just fine.
他の絵柄に簡単に 応用が利くところです
So here's what happens.
エシックの目的のためには どちらでもいいでしょう
Hedge rapidly defaces all of the portraits.
さて どうなるでしょう
And within moments
ヘッジはすごい速さで 自画像にバツ印をつけます
cries of anguish break out all over the forest.
まもなく
The garrison guarding the tower abandon their posts
森一帯に怒りの声が上がりました
to calm the agitated people,
塔を守っている警備ロボットは 持ち場を離れて
and Ethic, Hedge, and Octavia slip through—
人々の騒ぎを鎮めに行きます
and nearly slip into the depths of the gorge
エシックとヘッジと オクタヴィアはこっそりと抜けだし―
standing between them and the tower.
危うく塔への道を阻む谷底へと