どの端末でも同じ難しさにする ── 「種」と、60Hz と 120Hz の話The same difficulty on every device: seeds, 60 Hz and 120 Hz
/ WAITROOM 運営事務局WAITROOM Operations Office
対戦では、全員が同じ問題を同じ速さで遊べなければ公平になりません。WAITROOM が問題を「種」から作る理由と、画面の書き換えの速さ(60Hz と 120Hz)で難しさが変わらないようにした工夫を紹介します。A match is only fair if everyone plays the same problem at the same speed. Here is why WAITROOM builds every problem from a “seed”, and how we keep screen refresh rates (60 Hz vs 120 Hz) from changing the difficulty.
公平な対戦に必要なこと
部屋コードの対戦では、2〜8人がそれぞれ自分の端末で同時に遊びます。端末は、新しい iPhone もあれば数年前の Android もあります。それでも、出る問題と、問題の進む速さは全員同じでなければなりません。
問題はすべて「種」から作る
WAITROOM では、問題の中身を決める値を「種」(seed)と呼んでいます。スライドロボの盤面・壁・ロボットの位置・ゴール、シグナルタップで光るまでの待ち時間、フラッシュメモリで光る順番、カラーミスの文字と色の組み合わせ、ジャストストップのバーの速さと動き始める位置。これらはすべて種から計算します。
部屋の全員の端末に同じ種を配れば、全員の画面に同じ問題が出ます。プログラムでよく使う「毎回ちがう乱数」(Math.random)は使っていません。それを使うと、端末ごとに違う問題が出てしまうからです。同じ種からは必ず同じ問題ができることは、自動テストで毎回確かめています。
1台まわしだけは、わざと問題を変える
1台の端末を順番に回して遊ぶときは、逆の考え方をしています。順番に遊ぶので、全員に同じ問題を出すと、後の人は前の人のプレイを横で見て答えを覚えられてしまいます。
みんなで画面をのぞき込むのが1台まわしの楽しさなので、見られることを前提にして、人ごとに違う問題を出しています。そのぶん、問題によって難しさが偏らないことを、たくさんの種で問題を作って分布を調べる検査で確かめています。
画面の書き換えの速さで、バーの速さが変わってはいけない
スマートフォンの画面は、1秒に 60 回書き換わるもの(60Hz)と、120 回書き換わるもの(120Hz)があります。ジャストストップのように動くバーを止めるゲームで、書き換えのたびにバーを少しずつ進める作り方をすると、120Hz の端末では 60Hz の端末の2倍の速さでバーが動いてしまいます。
処理が重くなって書き換えが飛んだとき(コマ落ち)にも、バーの動きが遅れて、止めやすくなったり止めにくくなったりします。
そこで WAITROOM では、バーの位置を「動き始めてから何ミリ秒たったか」から毎回計算しています。左端から右端へ行って戻る動きを、時間の式で表しておくやり方です。こうすると、何回書き換えても、同じ時刻には同じ位置にバーがあります。60Hz と 120Hz で同じ時刻のバーの位置が一致することは、自動テストで確かめています。
画面の幅が違っても、ずれは同じに数える
ジャストストップの記録は、狙いの位置からどれだけずれたかで決まります。画面の幅は端末によって違うので、ずれをそのまま画面上の距離で数えると、画面の大きい端末ほどずれが大きく出てしまいます。WAITROOM では、ずれを幅 320px の画面に換算して数えています。
また、バーの動き始める位置も種で毎回変えています。いつも同じ位置から動き出すと、「何秒後に押せばいいか」を覚えるだけのゲームになってしまうからです。
タイミングの判定は、触れた瞬間の時刻で
どの瞬間に押したかの判定にも、端末の差が入りこみます。WAITROOM では、プログラムが押されたことに気づいた時刻ではなく、ブラウザが記録した「画面に触れた瞬間の時刻」で判定しています。その理由と実際に測った数字は、「タップしてから反応するまでを実機で測った」の記事にまとめています。
What a fair match needs
In a room-code match, 2 to 8 people play at the same time, each on their own device: a new iPhone here, a several-year-old Android there. Even so, the problem and how fast it moves must be identical for everyone.
Every problem comes from a seed
WAITROOM calls the value that decides a problem’s contents the seed. The Slide Robo board, walls, robot positions and goal; the wait before Signal Tap lights up; the order Flash Memory lights its squares; Color Miss’s word-and-color pairs; the speed and start position of the Just Stop bar. All of them are computed from the seed.
Hand the same seed to every device in the room and everyone gets the same problem. We never use the usual “different every time” random function (Math.random), because then each device would get a different problem. Automated tests check every time that the same seed always produces the same problem.
Pass & play deliberately changes the problem
When one device is passed around, we do the opposite. Players take turns, so if everyone got the same problem, later players could watch earlier ones and memorize the answer.
Crowding around the screen is the fun of pass & play, so we assume people are watching and give each player a different problem. To make up for that, a check generates problems from many seeds and examines the distribution, to make sure no problem is much harder than another.
The bar must not speed up on faster screens
Phone screens redraw 60 times a second (60 Hz) or 120 times (120 Hz). In a game like Just Stop, where you stop a moving bar, nudging the bar a little on every redraw would make it move twice as fast on a 120 Hz screen as on a 60 Hz one.
When the device is busy and skips redraws (dropped frames), the bar would also fall behind, making it easier or harder to stop.
So WAITROOM calculates the bar’s position each time from how many milliseconds have passed since it started, describing the left-to-right-and-back motion as a formula of time. However many redraws happen, the bar is in the same place at the same moment. Automated tests confirm that the bar’s position at a given moment is the same at 60 Hz and 120 Hz.
Different screen widths, same error
A Just Stop record is how far you missed the target. Screens differ in width, so measuring the miss as on-screen distance would make bigger screens look worse. WAITROOM converts the miss to a 320 px wide screen before counting it.
The bar’s starting position also changes with the seed each time. If it always started in the same place, the game would just be memorizing how many seconds to wait.
Timing is judged by the moment of touch
Device differences also creep into judging when you pressed. WAITROOM judges by the moment the browser recorded the touch, not when the code noticed it. The reasons and the numbers we measured are in “Measuring tap latency on a real phone”.