Play one Game page.
969006
public function playOneGamePage($uuid) {
    $gameResult = $this->generateGameResult($uuid);

    /** @var \Drupal\openy_campaign\Entity\MemberGame $game */
    $game = $this->entityRepository->loadEntityByUuid('openy_campaign_member_game', $uuid);

    $result = $game->result->value;
    /** @var \Drupal\Node\Entity\Node $campaign */
    $campaign = $game->member->entity->campaign->entity;

    $pallete = $this->campaignMenuService->getCampaignPalette($campaign);

    if (!empty($gameResult['already_used_chance'])) {
      $link = Link::fromTextAndUrl($this->t('Back to Campaign'), new Url('entity.node.canonical', ['node' => $campaign->id()]))->toString();
      return [
        '#markup' => $link . ' ' . $this->t('You have played this chance already. Your result: @result.', ['@result' => $result]),
      ];
    }

    $coverImagePath = NULL;
    if (!empty($campaign->field_flip_cards_cover_image->entity)) {
      /** @var \Drupal\file\Entity\File $coverImage */
      $coverImage = $campaign->field_flip_cards_cover_image->entity;
      $coverImagePath = $this->streamWrapperManager->getViaUri($coverImage->getFileUri())->getExternalUrl();
    }
    else {
      $coverImagePath = base_path() . $this->themeManager->getActiveTheme()->getPath() . '/img/instant_game_cover_1.png';
    }

    $title = $campaign->field_campaign_game_title->value;
    $description = $campaign->field_campaign_game_description->value;

    $gameType = $campaign->field_campaign_game_type->value;
    if (!in_array($gameType, self::$gamesList)) {
      return;
    }

    $isWinner = $gameResult['is_winner'];
    $result = $gameResult['result'];

    // Output different messages.
    // Get default values from settings.
    $messageNumber = mt_rand(1, 5);
    $message = $this->config->get('instant_game_' . ($isWinner ? 'win' : 'loose') . '_message_' . $messageNumber);

    $message = check_markup($message['value'], $message['format']);
    $messageTitle = $this->config->get('instant_game_' . ($isWinner ? 'win' : 'loose') . ' _title');
    $messageTitle = check_markup($messageTitle['value'], $messageTitle['format']);

    if ($isWinner) {
      $message = str_replace('[game:result]', $result, $message);
    }

    $isUnplayedGamesExist = $this->gameService->isUnplayedGamesExist($campaign);

    $isAllowedToPlay = TRUE;
    if ($campaign->field_campaign_game_one_time_win->value == 1 &&
      $this->gameService->isMemberWinner($campaign)) {
      $isAllowedToPlay = FALSE;
    }

    $nextGame = NULL;
    if ($isUnplayedGamesExist && $isAllowedToPlay) {
      $unPlayedGames = $this->gameService->getUnplayedGames($campaign);
      $nextGame = reset($unPlayedGames);
      $nextGameUrl = Link::fromTextAndUrl($this->t('Play again'), Url::fromRoute('openy_campaign.campaign_game', [
          'uuid' => $nextGame->uuid()
        ], [
          'query' => [
            'campaign_id' => $campaign->id()
          ],
          'attributes' => [
            'class' => [
              'btn'
            ]
          ]
        ]));
    } else {
      $activePage = $this->campaignMenuService->getActiveCampaignPage($campaign);
      $nextGameUrl = Link::fromTextAndUrl($this->t('Back to campaign'), Url::fromRoute('entity.node.canonical', [
        'node' => $activePage->id()
      ], [
        'attributes' => [
          'class' => [
            'btn'
          ]
        ]
      ]));
    }

    return [
      '#theme' => 'openy_campaign_game_' . $gameType,
      '#result' => $result,
      '#title' => $title,
      '#description' => $description,
      '#coverImagePath' => $coverImagePath,
      '#message' => $message,
      '#messageTitle' => $messageTitle,
      '#isWinner' => $isWinner,
      '#isUnplayedGamesExist' => $isUnplayedGamesExist,
      '#nextGameUrl' => $nextGameUrl,
      '#attached' => [
        'library' => [
          'openy_campaign/game_' . $gameType,
        ],
        'drupalSettings' => [
          'openy_campaign' => [
            'pallete' => $pallete['colors'],
            'result' => $result,
          ],
        ],
      ]
    ];
  }
706526
def cmd(send, msg, args):
    
    if not msg:
        send("Choose what?")
        return
    choices = msg.split(' or ')
    action = [
        'draws a slip of paper from a hat and gets...', 'says eenie, menie, miney, moe and chooses...', 'picks a random number and gets...',
        'rolls dice and gets...', 'asks a random person and gets...', 'plays rock, paper, scissors, lizard, spock and gets...'
    ]
    send("%s %s" % (choice(action), choice(choices)), 'action')
965767
function() {
        // Compute the amount of play left to go
        t.playLeft = t.playEnd - Date.now();

        // Done playing
        if (t.playLeft <= 0) {
          clearInterval(t.timer);
          t.next();
        }

        // Set the progress bar width
        t.setProgress();
      }
315541
public function game() : ?Game
    {
        if (!isset($this->info()->titleId)) return null;

        return new Game($this->client, $this->info()->titleId);
    }
658023
function handleGame(request, response, game, path) {
    var resp;
    switch(path[0]) {
    case 'board':
        // add pieces to the board
        if (request.method === "POST") {
            requestBody(request, function(form) {

                var player = playerFromReq(request, response, game);
                // console.info('adding pieces, player:'+player.name);
                // console.info('form info:'+JSON.stringify(form));

                if (form && form.shape && form.color &&
                    form.row && form.column && player) {

                    // TODO should do form check?
                    var row = parseInt(form.row, 10);
                    var column = parseInt(form.column, 10);
                    var piece = new Piece(form.shape, form.color);

                    // check player has piece
                    var idx = -1, _idx = 0;
                    for (var p in player.pieces) {
                        var _piece = player.pieces[p];
                        //console.log('check:'+JSON.stringify(p)+', and:'+
                        //          JSON.stringify(piece));
                        if (piece.equals(_piece)) {
                            idx = _idx;
                            break;
                        }
                        _idx += 1;
                    }

                    if (idx > -1) {
                        var gp = new GamePiece(piece, row, column);
                        // console.info('adding piece:'+JSON.stringify(gp));
                        resp = addGamePiece(game, gp);
                        if (typeof resp === "string") {
                            // add gamepiece failed
                            response.writeHead(409, {'Content-Type': 'text/json'});
                            response.write(resp, 'utf-8');
                            response.end();
                            return;
                        } else {
                            // add gamepiece succeeded
                            player.points += resp;
                            player.pieces.splice(idx, 1);
                            respOk(response, '', 'text/json');
                        }
                    }
                }
            });
            return;
        }
        // get pieces on the board
        resp = JSON.stringify(game.board);
        break;
    case 'players':
        handlePlayers(request, response, game, path.slice(1));
        return;
    case 'pieces':
        // get pieces in the bag
        resp = JSON.stringify(game.pieces);
        break;
    case 'chat':
        handleChat(request, response, game.chat);
        break;
    case 'dimensions':
        resp = JSON.stringify(game.dimensions);
    }
    respOk(response, resp, 'text/json');
}
926992
def select_page(self, limit, offset=0, **kwargs):
        
        start = offset
        while True:
            result = self.select(limit=[start, limit], **kwargs)
            start += limit
            if result:
                yield result
            else:
                break
            if self.debug:
                break
825058
def play(self, url=None, loop=None, digits=None, **kwargs):
        
        return self.nest(Play(url=url, loop=loop, digits=digits, **kwargs))
890976
def select_one(self, tag):
        """"""

        tags = self.select(tag, limit=1)
        return tags[0] if tags else None
381330
def run(self, once=False):
        """"""
        self._once = once
        self.start()
        while self.running:
            try:
                time.sleep(1.0)
            except KeyboardInterrupt:
                self.stop()
                self.join()
885868
function(widget, data) {
            var str;
            str = 'There are more players in this waiting room ' +
                'than playslots in the game. ';
            if (widget.poolSize === 1) {
                str += 'Each player will play individually.';
            }
            else {
                str += 'Only ' + data.nGames + ' players will be selected ' +
                    'to play the game.';
            }
            return str;
        }
966103
async def playing(self):
        """"""
        # TODO: This is hack-ish
        if self._setstate is None:
            await self.protocol.start()

        # No SET_STATE_MESSAGE received yet, use default
        if self._setstate is None:
            return MrpPlaying(protobuf.SetStateMessage(), None)

        return MrpPlaying(self._setstate, self._nowplaying)
804585
function play() {
    var _this2 = this;

    var fullscreen = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;

    if (!this.isShown || this.played) {
      return this;
    }

    var options = this.options,
        player = this.player;

    var onLoad = this.loadImage.bind(this);
    var list = [];
    var total = 0;
    var index = 0;

    this.played = true;
    this.onLoadWhenPlay = onLoad;

    if (fullscreen) {
      this.requestFullscreen();
    }

    addClass(player, CLASS_SHOW);
    forEach(this.items, function (item, i) {
      var img = item.querySelector('img');
      var image = document.createElement('img');

      image.src = getData(img, 'originalUrl');
      image.alt = img.getAttribute('alt');
      total += 1;
      addClass(image, CLASS_FADE);
      toggleClass(image, CLASS_TRANSITION, options.transition);

      if (hasClass(item, CLASS_ACTIVE)) {
        addClass(image, CLASS_IN);
        index = i;
      }

      list.push(image);
      addListener(image, EVENT_LOAD, onLoad, {
        once: true
      });
      player.appendChild(image);
    });

    if (isNumber(options.interval) && options.interval > 0) {
      var play = function play() {
        _this2.playing = setTimeout(function () {
          removeClass(list[index], CLASS_IN);
          index += 1;
          index = index < total ? index : 0;
          addClass(list[index], CLASS_IN);
          play();
        }, options.interval);
      };

      if (total > 1) {
        play();
      }
    }

    return this;
  }
612639
def run_game(load_file, selfplay_dir=None, holdout_dir=None,
             sgf_dir=None, holdout_pct=0.05):
    """"""
    if sgf_dir is not None:
        minimal_sgf_dir = os.path.join(sgf_dir, 'clean')
        full_sgf_dir = os.path.join(sgf_dir, 'full')
        utils.ensure_dir_exists(minimal_sgf_dir)
        utils.ensure_dir_exists(full_sgf_dir)
    if selfplay_dir is not None:
        utils.ensure_dir_exists(selfplay_dir)
        utils.ensure_dir_exists(holdout_dir)

    with utils.logged_timer("Loading weights from %s ... " % load_file):
        network = dual_net.DualNetwork(load_file)

    with utils.logged_timer("Playing game"):
        player = play(network)

    output_name = '{}-{}'.format(int(time.time()), socket.gethostname())
    game_data = player.extract_data()
    if sgf_dir is not None:
        with gfile.GFile(os.path.join(minimal_sgf_dir, '{}.sgf'.format(output_name)), 'w') as f:
            f.write(player.to_sgf(use_comments=False))
        with gfile.GFile(os.path.join(full_sgf_dir, '{}.sgf'.format(output_name)), 'w') as f:
            f.write(player.to_sgf())

    tf_examples = preprocessing.make_dataset_from_selfplay(game_data)

    if selfplay_dir is not None:
        # Hold out 5% of games for validation.
        if random.random() < holdout_pct:
            fname = os.path.join(holdout_dir,
                                 "{}.tfrecord.zz".format(output_name))
        else:
            fname = os.path.join(selfplay_dir,
                                 "{}.tfrecord.zz".format(output_name))

        preprocessing.write_tf_examples(fname, tf_examples)
974217
def main(argv):
    """"""
    del argv  # Unused
    flags.mark_flag_as_required('load_file')

    run_game(
        load_file=FLAGS.load_file,
        selfplay_dir=FLAGS.selfplay_dir,
        holdout_dir=FLAGS.holdout_dir,
        holdout_pct=FLAGS.holdout_pct,
        sgf_dir=FLAGS.sgf_dir)
114365
def play(file_or_url, options = {})
      @players = @devices.map { |device| device.play(file_or_url, options) }
      Players.new(@players)
    end
891684
def log_player_plays_monopoly(self, player, resource):
        
        self._logln('{0} plays monopoly on {1}'.format(
            player.color,
            resource.value
        ))
1113409
def play
      @start = Time.now
      results = body.map { |line| Line.new(line:line, stats:stats).play unless line == ""}
      self.time = Time.now - @start
      self.chars = results.map {|s| s[:chars] }.inject(:+)
      self.correct_chars = results.map {|s| s[:correct_chars] }.inject(:+)
      self.words = results.map {|s| s[:words] }.inject(:+)
      self.keystrokes  = results.map {|s| s[:keystrokes] }.inject(:+)
      self.typing_accuracy = (correct_chars.to_f / keystrokes.to_f * 100).to_i
      self.word_accuracy   = (correct_chars.to_f / chars.to_f * 100).to_i # TODO
      self.gross_wpm = words / (time / 60)
      stats.record_exercise(self)
      return results
    end