Copy several game-state members into client state
[lmno.games] / empathy / empathy.jsx
1 const MAX_PROMPT_ITEMS = 20;
2
3 function undisplay(element) {
4   element.style.display="none";
5 }
6
7 function add_message(severity, message) {
8   message = `<div class="message ${severity}" onclick="undisplay(this)">
9 <span class="hide-button" onclick="undisplay(this.parentElement)">&times;</span>
10 ${message}
11 </div>`;
12   const message_area = document.getElementById('message-area');
13   message_area.insertAdjacentHTML('beforeend', message);
14 }
15
16 /*********************************************************
17  * Handling server-sent event stream                     *
18  *********************************************************/
19
20 const events = new EventSource("events");
21
22 events.onerror = function(event) {
23   if (event.target.readyState === EventSource.CLOSED) {
24     setTimeout(() => {
25       add_message("danger", "Connection to server lost.");
26     }, 1000);
27   }
28 };
29
30 events.addEventListener("game-info", event => {
31   const info = JSON.parse(event.data);
32
33   window.game.set_game_info(info);
34 });
35
36 events.addEventListener("player-info", event => {
37   const info = JSON.parse(event.data);
38
39   window.game.set_player_info(info);
40 });
41
42 events.addEventListener("player-enter", event => {
43   const info = JSON.parse(event.data);
44
45   window.game.set_other_player_info(info);
46 });
47
48 events.addEventListener("player-update", event => {
49   const info = JSON.parse(event.data);
50
51   if (info.id === window.game.state.player_info.id)
52     window.game.set_player_info(info);
53   else
54     window.game.set_other_player_info(info);
55 });
56
57 events.addEventListener("game-state", event => {
58   const state = JSON.parse(event.data);
59
60   window.game.reset_game_state();
61
62   window.game.set_prompts(state.prompts);
63
64   window.game.set_active_prompt(state.active_prompt);
65
66   window.game.set_players_answered(state.players_answered);
67
68   window.game.set_players_answering(state.players_answering);
69
70   window.game.set_end_answers(state.end_answers);
71
72   window.game.set_ambiguities(state.ambiguities);
73
74   window.game.set_players_judged(state.players_judged);
75
76   window.game.set_players_judging(state.players_judging);
77
78   window.game.set_end_judging(state.end_judging);
79
80   window.game.set_scores(state.scores);
81 });
82
83 events.addEventListener("prompt", event => {
84   const prompt = JSON.parse(event.data);
85
86   window.game.add_or_update_prompt(prompt);
87 });
88
89 events.addEventListener("start", event => {
90   const prompt = JSON.parse(event.data);
91
92   window.game.set_active_prompt(prompt);
93 });
94
95 events.addEventListener("player-answered", event => {
96   const player = JSON.parse(event.data);
97
98   window.game.set_player_answered(player);
99 });
100
101 events.addEventListener("player-answering", event => {
102   const player = JSON.parse(event.data);
103
104   window.game.set_player_answering(player);
105 });
106
107 events.addEventListener("vote-end-answers", event => {
108   const player = JSON.parse(event.data);
109
110   window.game.set_player_vote_end_answers(player);
111 });
112
113 events.addEventListener("unvote-end-answers", event => {
114   const player = JSON.parse(event.data);
115
116   window.game.set_player_unvote_end_answers(player);
117 });
118
119 events.addEventListener("ambiguities", event => {
120   const ambiguities = JSON.parse(event.data);
121
122   window.game.set_ambiguities(ambiguities);
123 });
124
125 events.addEventListener("player-judged", event => {
126   const player = JSON.parse(event.data);
127
128   window.game.set_player_judged(player);
129 });
130
131 events.addEventListener("player-judging", event => {
132   const player = JSON.parse(event.data);
133
134   window.game.set_player_judging(player);
135 });
136
137 events.addEventListener("vote-end-judging", event => {
138   const player = JSON.parse(event.data);
139
140   window.game.set_player_vote_end_judging(player);
141 });
142
143 events.addEventListener("unvote-end-judging", event => {
144   const player = JSON.parse(event.data);
145
146   window.game.set_player_unvote_end_judging(player);
147 });
148
149 events.addEventListener("scores", event => {
150   const scores = JSON.parse(event.data);
151
152   window.game.set_scores(scores);
153 });
154
155 /*********************************************************
156  * Game and supporting classes                           *
157  *********************************************************/
158
159 function copy_to_clipboard(id)
160 {
161   const tmp = document.createElement("input");
162   tmp.setAttribute("value", document.getElementById(id).innerHTML);
163   document.body.appendChild(tmp);
164   tmp.select();
165   document.execCommand("copy");
166   document.body.removeChild(tmp);
167 }
168
169 const GameInfo = React.memo(props => {
170   if (! props.id)
171     return null;
172
173   return (
174     <div className="game-info">
175       <span className="game-id">{props.id}</span>
176       {" "}
177       Share this link to invite friends:{" "}
178       <span id="game-share-url">{props.url}</span>
179       {" "}
180       <button
181         className="inline"
182         onClick={() => copy_to_clipboard('game-share-url')}
183       >Copy Link</button>
184     </div>
185   );
186 });
187
188 const PlayerInfo = React.memo(props => {
189   if (! props.player.id)
190     return null;
191
192   return (
193     <div className="player-info">
194       <span className="players-header">Players: </span>
195       {props.player.name}
196       {props.player.score > 0 ? ` (${props.player.score})` : ""}
197       {props.other_players.map(other => (
198         <span key={other.id}>
199           {", "}
200           {other.name}
201           {other.score > 0 ? ` (${other.score})` : ""}
202         </span>
203       ))}
204     </div>
205   );
206 });
207
208 function fetch_method_json(method, api = '', data = {}) {
209   const response = fetch(api, {
210     method: method,
211     headers: {
212       'Content-Type': 'application/json'
213     },
214     body: JSON.stringify(data)
215   });
216   return response;
217 }
218
219 function fetch_post_json(api = '', data = {}) {
220   return fetch_method_json('POST', api, data);
221 }
222
223 async function fetch_put_json(api = '', data = {}) {
224   return fetch_method_json('PUT', api, data);
225 }
226
227 class CategoryRequest extends React.PureComponent {
228   constructor(props) {
229     super(props);
230     this.category = React.createRef();
231
232     this.handle_change = this.handle_change.bind(this);
233     this.handle_submit = this.handle_submit.bind(this);
234   }
235
236   handle_change(event) {
237     const category_input = this.category.current;
238     const category = category_input.value;
239
240     const match = category.match(/[0-9]+/);
241     if (match) {
242       const num_items = parseInt(match[0], 10);
243       if (num_items <= MAX_PROMPT_ITEMS)
244         category_input.setCustomValidity("");
245     }
246   }
247
248   async handle_submit(event) {
249     const form = event.currentTarget;
250     const category_input = this.category.current;
251     const category = category_input.value;
252
253     /* Prevent the default page-changing form-submission behavior. */
254     event.preventDefault();
255
256     const match = category.match(/[0-9]+/);
257     if (match === null) {
258       category_input.setCustomValidity("Category must include a number");
259       form.reportValidity();
260       return;
261     }
262
263     const num_items = parseInt(match[0], 10);
264
265     if (num_items > MAX_PROMPT_ITEMS) {
266       category_input.setCustomValidity(`Maximum number of items is ${MAX_PROMPT_ITEMS}`);
267       form.reportValidity();
268       return;
269     }
270
271     const response = await fetch_post_json("prompts", {
272       items: num_items,
273       prompt: category
274     });
275
276     if (response.status === 200) {
277       const result = await response.json();
278       if (! result.valid) {
279         add_message("danger", result.message);
280         return;
281       }
282     } else {
283       add_message("danger", "An error occurred submitting your category");
284     }
285
286     form.reset();
287   }
288
289   render() {
290     return (
291       <div className="category-request">
292         <h2>Submit a Category</h2>
293         <p>
294           Suggest a category to play. Don't forget to include the
295           number of items for each person to submit.
296         </p>
297
298         <form onSubmit={this.handle_submit} >
299           <div className="form-field large">
300             <input
301               type="text"
302               id="category"
303               placeholder="6 things at the beach"
304               required
305               autoComplete="off"
306               onChange={this.handle_change}
307               ref={this.category}
308             />
309           </div>
310
311           <div className="form-field large">
312             <button type="submit">
313               Send
314             </button>
315           </div>
316
317         </form>
318       </div>
319     );
320   }
321 }
322
323 const PromptOptions = React.memo(props => {
324
325   if (props.prompts.length === 0)
326     return null;
327
328   return (
329     <div className="prompt-options">
330       <h2>Vote on Categories</h2>
331       <p>
332         Select any categories below that you'd like to play.
333         You can choose as many as you'd like.
334       </p>
335       {props.prompts.map(p => {
336         return (
337           <button
338             className="vote-button"
339             key={p.id}
340             onClick={() => fetch_post_json(`vote/${p.id}`) }
341           >
342             {p.prompt}
343             <div className="vote-choices">
344               {p.votes.map(v => {
345                 return (
346                   <div
347                     key={v}
348                     className="vote-choice"
349                   >
350                     {v}
351                   </div>
352                 );
353               })}
354             </div>
355           </button>
356         );
357       })}
358     </div>
359   );
360 });
361
362 const LetsPlay = React.memo(props => {
363
364   const quorum = Math.round((props.num_players + 1) / 2);
365   const max_votes = props.prompts.reduce(
366     (max_so_far, v) => Math.max(max_so_far, v.votes.length), 0);
367
368   if (max_votes < quorum)
369     return null;
370
371   const candidates = props.prompts.filter(p => p.votes.length >= quorum);
372   const index = Math.floor(Math.random() * candidates.length);
373   const winner = candidates[index];
374
375   return (
376     <div className="lets-play">
377       <h2>Let's Play</h2>
378       <p>
379         That should be enough voting. If you're not waiting for any
380         other players to join, then let's start.
381       </p>
382       <button
383         className="lets-play"
384         onClick={() => fetch_post_json(`start/${winner.id}`) }
385       >
386         Start Game
387       </button>
388     </div>
389   );
390 });
391
392 class Ambiguities extends React.PureComponent {
393
394   constructor(props) {
395     super(props);
396
397     const word_sets = props.words.map(word => {
398       const set = new Set();
399       set.add(word);
400       return set;
401     });
402
403     this.state = {
404       word_sets: word_sets,
405       submitted: false,
406       selected: null
407     };
408
409     this.judging_sent_recently = false;
410   }
411
412   async handle_submit() {
413     const response = await fetch_post_json(
414       `judged/${this.props.prompt.id}`,{
415         word_groups: this.state.word_sets.map(set => Array.from(set))
416       }
417     );
418
419     if (response.status === 200) {
420       const result = await response.json();
421       if (! result.valid) {
422         add_message("danger", result.message);
423         return;
424       }
425     } else {
426       add_message("danger", "An error occurred submitting the results of your judging");
427       return;
428     }
429
430     this.setState({
431       submitted: true
432     });
433   }
434
435   handle_click(word) {
436
437     /* Let the server know we are doing some judging, (but rate limit
438      * this so we don't send a "judging" notification more frquently
439      * than necessary.
440      */
441     if (! this.judging_sent_recently) {
442       fetch_post_json(`judging/${this.props.prompt.id}`);
443       this.judging_sent_recently = true;
444       setTimeout(() => { this.judging_sent_recently = false; }, 1000);
445     }
446
447     if (this.state.selected == word) {
448       /* Second click on same word removes the word from the group. */
449       const idx = this.state.word_sets.findIndex(s => s.has(word));
450       const set = this.state.word_sets[idx];
451       if (set.size === 1) {
452         /* When the word is already alone, there's nothing to do but
453          * to un-select it. */
454         this.setState({
455           selected: null
456         });
457         return;
458       }
459
460       const new_set = new Set([...set].filter(w => w !== word));
461       this.setState({
462         selected: null,
463         word_sets: [...this.state.word_sets.slice(0, idx),
464                     new_set,
465                     new Set().add(word),
466                     ...this.state.word_sets.slice(idx+1)]
467       });
468     } else if (this.state.selected) {
469       /* Click of a second word groups the two together. */
470       const idx1 = this.state.word_sets.findIndex(s => s.has(this.state.selected));
471       const idx2 = this.state.word_sets.findIndex(s => s.has(word));
472       const set1 = this.state.word_sets[idx1];
473       const set2 = this.state.word_sets[idx2];
474       const new_set = new Set([...set2, ...set1]);
475       if (idx1 < idx2) {
476         this.setState({
477           selected: null,
478           word_sets: [...this.state.word_sets.slice(0, idx1),
479                       ...this.state.word_sets.slice(idx1 + 1, idx2),
480                       new_set,
481                       ...this.state.word_sets.slice(idx2 + 1)]
482         });
483       } else {
484         this.setState({
485           selected: null,
486           word_sets: [...this.state.word_sets.slice(0, idx2),
487                       new_set,
488                       ...this.state.word_sets.slice(idx2 + 1, idx1),
489                       ...this.state.word_sets.slice(idx1 + 1)]
490         });
491       }
492     } else {
493       /* First click of a word selects it. */
494       this.setState({
495         selected: word
496       });
497     }
498   }
499
500   render() {
501     if (this.state.submitted)
502       return (
503         <div className="please-wait">
504           <h2>Submission received</h2>
505           <p>
506             The following players have completed judging:
507             {[...this.props.players_judged].join(', ')}
508           </p>
509           <p>
510             Still waiting for the following players:
511           </p>
512           <ul>
513             {Object.keys(this.props.players_judging).map(player => {
514               return (
515                 <li
516                   key={player}
517                 >
518                   {player}
519                   {this.props.players_judging[player] ?
520                    <span className="typing"/> : null }
521                 </li>
522               );
523             })}
524           </ul>
525           <button
526             className="vote-button"
527             onClick={() => fetch_post_json(`end-judging/${this.props.prompt.id}`) }
528           >
529             Move On
530             <div className="vote-choices">
531               {[...this.props.votes].map(v => {
532                 return (
533                   <div
534                     key={v}
535                     className="vote-choice"
536                   >
537                     {v}
538                   </div>
539                 );
540               })}
541             </div>
542           </button>
543
544         </div>
545       );
546
547     const btn_class = "ambiguity-button";
548     const btn_selected_class = btn_class + " selected";
549
550     return (
551       <div className="ambiguities">
552         <h2>Judging Answers</h2>
553         <p>
554           Click on each pair of answers that should be scored as equivalent,
555           (and click any word twice to split it out from a group). Remember,
556           what goes around comes around, so it's best to be generous when
557           judging.
558         </p>
559         {this.state.word_sets.map(set => {
560           return (
561             <div
562               className="ambiguity-group"
563               key={Array.from(set)[0]}
564             >
565               {Array.from(set).map(word => {
566                 return (
567                   <button
568                     className={this.state.selected === word ?
569                                btn_selected_class : btn_class }
570                     key={word}
571                     onClick={() => this.handle_click(word)}
572                   >
573                     {word}
574                   </button>
575                 );
576               })}
577             </div>
578           );
579         })}
580         <p>
581           Click here when done judging:<br/>
582           <button
583             onClick={() => this.handle_submit()}
584           >
585             Send
586           </button>
587         </p>
588       </div>
589     );
590   }
591 }
592
593 class ActivePrompt extends React.PureComponent {
594
595   constructor(props) {
596     super(props);
597     const items = props.prompt.items;
598
599     this.state = {
600       submitted: false
601     };
602
603     this.answers = [...Array(items)].map(() => React.createRef());
604     this.answering_sent_recently = false;
605
606     this.handle_submit = this.handle_submit.bind(this);
607     this.handle_change = this.handle_change.bind(this);
608   }
609
610   handle_change(event) {
611     /* We don't care (or even look) at what the player is typing at
612      * this point. We simply want to be informed that the player _is_
613      * typing so that we can tell the server (which will tell other
614      * players) that there is activity here.
615      */
616
617     /* Rate limit so that we don't send an "answering" notification
618      * more frequently than necessary.
619      */
620     if (! this.answering_sent_recently) {
621       fetch_post_json(`answering/${this.props.prompt.id}`);
622       this.answering_sent_recently = true;
623       setTimeout(() => { this.answering_sent_recently = false; }, 1000);
624     }
625   }
626
627   async handle_submit(event) {
628     const form = event.currentTarget;
629
630     /* Prevent the default page-changing form-submission behavior. */
631     event.preventDefault();
632
633     const response = await fetch_post_json(`answer/${this.props.prompt.id}`, {
634       answers: this.answers.map(r => r.current.value)
635     });
636     if (response.status === 200) {
637       const result = await response.json();
638       if (! result.valid) {
639         add_message("danger", result.message);
640         return;
641       }
642     } else {
643       add_message("danger", "An error occurred submitting your answers");
644       return;
645     }
646
647     /* Everything worked. Server is happy with our answers. */
648     form.reset();
649     this.setState({
650         submitted: true
651     });
652   }
653
654   render() {
655     if (this.state.submitted)
656       return (
657         <div className="please-wait">
658           <h2>Submission received</h2>
659           <p>
660             The following players have submitted their answers:
661             {[...this.props.players_answered].join(', ')}
662           </p>
663           <p>
664           Still waiting for the following players:
665           </p>
666           <ul>
667             {Object.keys(this.props.players_answering).map(player => {
668               return (
669                 <li
670                   key={player}
671                 >
672                   {player}
673                   {this.props.players_answering[player] ?
674                    <span className="typing"/> : null }
675                 </li>
676               );
677             })}
678           </ul>
679           <button
680             className="vote-button"
681             onClick={() => fetch_post_json(`end-answers/${this.props.prompt.id}`) }
682           >
683             Move On
684             <div className="vote-choices">
685               {[...this.props.votes].map(v => {
686                 return (
687                   <div
688                     key={v}
689                     className="vote-choice"
690                   >
691                     {v}
692                   </div>
693                 );
694               })}
695             </div>
696           </button>
697
698         </div>
699       );
700
701     return (
702       <div className="active-prompt">
703         <h2>The Game of Empathy</h2>
704         <p>
705           Remember, you're trying to match your answers with
706           what the other players submit.
707           Give {this.props.prompt.items} answers for the following prompt:
708         </p>
709         <h2>{this.props.prompt.prompt}</h2>
710         <form onSubmit={this.handle_submit}>
711           {[...Array(this.props.prompt.items)].map((whocares,i) => {
712             return (
713               <div
714                 key={i}
715                 className="form-field large">
716                 <input
717                   type="text"
718                   name={`answer_${i}`}
719                   required
720                   autoComplete="off"
721                   onChange={this.handle_change}
722                   ref={this.answers[i]}
723                 />
724               </div>
725             );
726           })}
727
728           <div
729             key="submit-button"
730             className="form-field large">
731             <button type="submit">
732               Send
733             </button>
734           </div>
735
736         </form>
737       </div>
738     );
739   }
740 }
741
742 class Game extends React.PureComponent {
743   constructor(props) {
744     super(props);
745     this.state = {
746       game_info: {},
747       player_info: {},
748       other_players: [],
749       prompts: [],
750       active_prompt: null,
751       players_answered: new Set(),
752       players_answering: {},
753       end_answers_votes: new Set(),
754       ambiguities: null,
755       players_judged: new Set(),
756       players_judging: {},
757       end_judging_votes: new Set(),
758       scores: null
759     };
760   }
761
762   set_game_info(info) {
763     this.setState({
764       game_info: info
765     });
766   }
767
768   set_player_info(info) {
769     this.setState({
770       player_info: info
771     });
772   }
773
774   set_other_player_info(info) {
775     const other_players_copy = [...this.state.other_players];
776     const idx = other_players_copy.findIndex(o => o.id === info.id);
777     if (idx >= 0) {
778       other_players_copy[idx] = info;
779     } else {
780       other_players_copy.push(info);
781     }
782     this.setState({
783       other_players: other_players_copy
784     });
785   }
786
787   reset_game_state() {
788     this.setState({
789       prompts: [],
790       active_prompt: null,
791       players_answered: new Set(),
792       players_answering: {},
793       end_answers_votes: new Set(),
794       ambiguities: null,
795       players_judged: new Set(),
796       players_judging: {},
797       end_judging_votes: new Set(),
798       scores: null
799     });
800   }
801
802   set_prompts(prompts) {
803     this.setState({
804       prompts: prompts
805     });
806   }
807
808   add_or_update_prompt(prompt) {
809     const prompts_copy = [...this.state.prompts];
810     const idx = prompts_copy.findIndex(p => p.id === prompt.id);
811     if (idx >= 0) {
812       prompts_copy[idx] = prompt;
813     } else {
814       prompts_copy.push(prompt);
815     }
816     this.setState({
817       prompts: prompts_copy
818     });
819   }
820
821   set_active_prompt(prompt) {
822     this.setState({
823       active_prompt: prompt
824     });
825   }
826
827   set_players_answered(players) {
828     this.setState({
829       players_answered: new Set(players)
830     });
831   }
832
833   set_player_answered(player) {
834     const new_players_answering = {...this.state.players_answering};
835     delete new_players_answering[player];
836
837     this.setState({
838       players_answered: new Set([...this.state.players_answered, player]),
839       players_answering: new_players_answering
840     });
841   }
842
843   set_players_answering(players) {
844     const players_answering = {};
845     for (let player of players) {
846       players_answering[player] = {active: false};
847     }
848     this.setState({
849       players_answering: players_answering
850     });
851   }
852
853   set_player_answering(player) {
854     this.setState({
855       players_answering: {
856         ...this.state.players_answering,
857         [player]: {active: true}
858       }
859     });
860   }
861
862   set_end_answers(players) {
863     this.setState({
864       end_answers_votes: new Set(players)
865     });
866   }
867
868   set_player_vote_end_answers(player) {
869     this.setState({
870       end_answers_votes: new Set([...this.state.end_answers_votes, player])
871     });
872   }
873
874   set_player_unvote_end_answers(player) {
875     this.setState({
876       end_answers_votes: new Set([...this.state.end_answers_votes].filter(p => p !== player))
877     });
878   }
879
880   set_ambiguities(ambiguities) {
881     this.setState({
882       ambiguities: ambiguities
883     });
884   }
885
886   set_players_judged(players) {
887     this.setState({
888       players_judged: new Set(players)
889     });
890   }
891
892   set_player_judged(player) {
893     const new_players_judging = {...this.state.players_judging};
894     delete new_players_judging[player];
895
896     this.setState({
897       players_judged: new Set([...this.state.players_judged, player]),
898       players_judging: new_players_judging
899     });
900   }
901
902   set_players_judging(players) {
903     const players_judging = {};
904     for (let player of players) {
905       players_judging[player] = {active: false};
906     }
907     this.setState({
908       players_judging: players_judging
909     });
910   }
911
912   set_player_judging(player) {
913     this.setState({
914       players_judging: {
915         ...this.state.players_judging,
916         [player]: {active: true}
917       }
918     });
919   }
920
921   set_end_judging(players) {
922     this.setState({
923       end_judging_votes: new Set(players)
924     });
925   }
926
927   set_player_vote_end_judging(player) {
928     this.setState({
929       end_judging_votes: new Set([...this.state.end_judging_votes, player])
930     });
931   }
932
933   set_player_unvote_end_judging(player) {
934     this.setState({
935       end_judging_votes: new Set([...this.state.end_judging_votes].filter(p => p !== player))
936     });
937   }
938
939   set_scores(scores) {
940     this.setState({
941       scores: scores
942     });
943   }
944
945   render() {
946     const state = this.state;
947     const players_total = 1 + state.other_players.length;
948
949     if (state.scores) {
950       return (
951         <div className="scores">
952           <h2>Scores</h2>
953           <ul>
954             {state.scores.scores.map(score => {
955               return (
956                 <li key={score.player}>
957                   {score.player}: {score.score}
958                 </li>
959               );
960             })}
961           </ul>
962           <h2>Words submitted</h2>
963           <ul>
964             {state.scores.words.map(word => {
965               return (
966                 <li key={word.word}>
967                   {`${word.word}: ${word.players.join(', ')}`}
968                 </li>
969               );
970             })}
971           </ul>
972           <button
973             className="new-game"
974             onClick={() => fetch_post_json('reset') }
975           >
976             New Game
977           </button>
978         </div>
979       );
980     }
981
982     if (state.ambiguities){
983       return <Ambiguities
984                prompt={state.active_prompt}
985                words={state.ambiguities}
986                players_judged={state.players_judged}
987                players_judging={state.players_judging}
988                votes={state.end_judging_votes}
989              />;
990     }
991
992     if (state.active_prompt) {
993       return <ActivePrompt
994                prompt={state.active_prompt}
995                players_answered={state.players_answered}
996                players_answering={state.players_answering}
997                votes={state.end_answers_votes}
998              />;
999     }
1000
1001     return [
1002       <GameInfo
1003         key="game-info"
1004         id={state.game_info.id}
1005         url={state.game_info.url}
1006       />,
1007       <PlayerInfo
1008         key="player-info"
1009         game={this}
1010         player={state.player_info}
1011         other_players={state.other_players}
1012       />,
1013       <p key="spacer"></p>,
1014       <CategoryRequest
1015         key="category-request"
1016       />,
1017       <PromptOptions
1018         key="prompts"
1019         prompts={state.prompts}
1020       />,
1021       <LetsPlay
1022         key="lets-play"
1023         num_players={1+state.other_players.length}
1024         prompts={state.prompts}
1025       />
1026     ];
1027   }
1028 }
1029
1030 ReactDOM.render(<Game
1031                   ref={(me) => window.game = me}
1032                 />, document.getElementById("empathy"));