Ping Pong game model
162982
function Game(scene) {
    var isOver = false,
        overCallbacks = [],
        cachedPos = new Geometry.Point(),
        ball = new Ball(scene),

        gameOver = function (side) {
            var i;
            isOver = true;
            for (i = 0; i < overCallbacks.length; ++i) {
                overCallbacks[i](side);
            }
        };

    this.leftHandle = new Handle(true, scene);
    this.rightHandle = new Handle(false, scene);
    this.ball = ball;

    this.step =  function () {
        if (isOver) {
            return;
        }
        ball.move();
        var outSide = ball.isOut();
        if (this.leftHandle.hit(ball)) {
            cachedPos.x = settings.handleWidth;
            cachedPos.y = ball.y;
            ball.setPosition(cachedPos);
            ball.vx = -ball.vx;
        } else if (this.rightHandle.hit(ball)) {
            cachedPos.x = this.rightHandle.x;
            cachedPos.y = ball.y;
            ball.setPosition(cachedPos);
            ball.vx = -ball.vx;
        } else if (outSide) {
            gameOver(outSide);
        }

        scene.render(this.leftHandle, this.rightHandle, ball);
    };
    this.isOver = function () {
        return isOver;
    };
    this.onOver = function (callback) {
        if (typeof callback === 'function') {
            overCallbacks.push(callback);
        }
    };
}
1339753
def start_pinging(self) -> None:
        """"""
        assert self.ping_interval is not None
        if self.ping_interval > 0:
            self.last_ping = self.last_pong = IOLoop.current().time()
            self.ping_callback = PeriodicCallback(
                self.periodic_ping, self.ping_interval * 1000
            )
            self.ping_callback.start()
1044976
private function calculateBestMove($player, $stopOpponentPlayer = true, &$playerMoveScore = 0)
    {
        $winningMoves = []; // the best tile(s)

        $opponentMoveScore = 0; // the higher moveScore of the opponent

        $opponentMove = []; // keep opponent best move

        if (!$this->checkPlayer($player) || $this->isFinished()) {
            return $winningMoves;
        }

        // try to stop the opponent from winning
        if ($stopOpponentPlayer) {
            // get the opponent's best move
            $opponentMove = $this->calculateBestMove($this->getOpponentPlayer($player), false, $opponentMoveScore);
        }

        foreach ($this->board->getBoard() as $positionX => $col) {

            foreach ($col as $positionY => $tile) {

                $moveScore = $this->calculateMoveScore($player, [$positionX, $positionY]);

                if (!is_null($moveScore)) {
                    if ($moveScore > $playerMoveScore) {

                        $winningMoves = [[$positionX, $positionY]];
                        $playerMoveScore = $moveScore;

                        continue;
                    }

                    if ($moveScore == $playerMoveScore) {

                        array_push($winningMoves, [$positionX, $positionY]);

                        continue;
                    }
                }
            }
        }

        if ($stopOpponentPlayer && $opponentMoveScore >= 10 && $playerMoveScore < 10) {
            return $opponentMove;
        }

        if (count($winningMoves)) {

            return $winningMoves[array_rand($winningMoves)];
        }

        return $winningMoves;
    }
755844
function (p, maxr) {
  // model position as y = 2^(k+1) + c_k2^k + 1
  // where k(maxr) = floor(roundDiff/2)
  // works upto and including LB final (gf players must be positioned manually)
  var metric = 2*p - maxr;
  var k = Math.floor(metric/2) - 1; // every other doubles
  if (k < 0) {
    throw new Error('lbPos model works for k>=0 only');
  }
  var ck = Math.pow(2, k) * (metric % 2);
  return Math.pow(2, k + 1) + 1 + ck;
}
761432
function GameMsgGenerator(gameServer) {
    this.session = gameServer.session;
    this.sender = gameServer.name;
    this.stage = null;
}
1274464
def _process_ping(self):
        
        yield self.send_command(PONG_PROTO)
        if self._flush_queue.empty():
            yield self._flush_pending()
618743
function (p, round, game) {
  // we know round <= p
  var numGames = Math.pow(2, p - round);
  var midPoint = Math.floor(Math.pow(2, p - round - 1)); // midPoint 0 in finals

  // reverse the match list map
  var reversed = $.odd(Math.floor(round/2));
  // split the match list map in two change order and rejoin the lists
  var partitioned = $.even(Math.floor((round + 1)/2));

  if (partitioned) {
    if (reversed) {
      return (game > midPoint) ? numGames - game + midPoint + 1 : midPoint - game + 1;
    }
    return (game > midPoint) ?  game - midPoint : game + midPoint;
  }
  return reversed ? numGames - game + 1 : game;
}
903437
def pong(self, message=None):
        '''
        '''
        return self.write(self.parser.pong(message), encode=False)
740894
function PongMessage(arg, options) {
  Message.call(this, options);
  this.command = 'pong';
  $.checkArgument(
    _.isUndefined(arg) || (BufferUtil.isBuffer(arg) && arg.length === 8),
    'First argument is expected to be an 8 byte buffer'
  );
  this.nonce = arg || utils.getNonce();
}
439228
function gameOrLobby(games) {
    $(LOBBY).hide();
    $(GAMEROOM).hide();
    $(ADDGUEST).hide();

    if (!$.cookie("player")) {
        drawAddGuest();
        return;
    }

    // hide the fork me banner from now on
    $(FORKME).hide();

    var my_game = $.cookie("game");
    // User is not in a valid game
    if (typeof games[my_game] === 'undefined') {
        $.removeCookie('game');
        $(LOBBY).show();
        drawLobby(games);
    } else {
        $(GAMEROOM).show();
        drawGame();
    }
    $(CHATPNL).show();
    drawChatLog();
    drawChatIn();

    // setup future calls to get chat
    function pollChat() {
        drawChatLog();
        DRAWCHATTID = setTimeout(pollChat, 2000);
    }
    DRAWCHATTID = setTimeout(pollChat, 2000);
}
1044636
function runGame() {
    var totalReward = 0;
    var environment = new exampleWorld.Environment();
    var lastReward = null;

    function tick() {
        //Tell the agent about the current environment state and have it choose an action to take
        var action = sarsaAgent.decide(lastReward, environment.getCurrentState());

        //Tell the environment the agent's action and have it calculate a reward
        lastReward = environment.takeAction(action);

        //Log the total reward
        totalReward += lastReward;
    }

    for (var i = 0; i < 100; i++) {
        tick();
    }

    return totalReward;
}
225371
function(playerCards, dealerCard, handValue, handCount, dealerCheckedBlackjack, options)
    {
        // Can you split?
        if ((playerCards[0] == playerCards[1]) && (playerCards.length == 2) && (handCount < options.maxSplitHands))
        {
            // Split unless 4s, 5s, and 10s
            if ((playerCards[0] != 4) && (playerCards[0] != 5) && (playerCards[0] != 10))
            {
                return "split";
            }
        }

        // Double
        if (((playerCards.length == 2) && ((handCount == 1) || options.doubleAfterSplit)) &&
                ((handValue.total >= options.doubleRange[0]) && (handValue.total <= options.doubleRange[1])))
        {
            // Only on 9-11
            if ((handValue.total == 9) && (dealerCard < 7) && (dealerCard != 1))
            {
                return "double";
            }
            if ((handValue.total == 10) && (dealerCard < 10) && (dealerCard != 1))
            {
                return "double";
            }
            if (handValue.total == 11)
            {
                return "double";
            }
        }

        // Hit and stand
        if (handValue.soft)
        {
            // Hit until you get to 17, 18 against dealer 9-Ace
            if ((handValue.total < 18) || ((handValue.total == 18) && ((dealerCard >= 9) || (dealerCard == 1))))
            {
                return "hit";
            }
        }

        if (handValue.total <= 11)
        {
            return "hit";
        }
        else if (handValue.total >= 17)
        {
            return "stand";
        }
        else
        {
            // Hit on 7 or above, else stand
            return ((dealerCard >= 7) || (dealerCard == 1)) ? "hit" : "stand";
        }
    }
1257474
function getGameAfterMove(game, move, backMove = false) {
    if (!backMove && canNotMove(game, move))
        return game;
    const board = getBoardAfterMove(game.board, move);
    return {
        players: game.players,
        board,
        score: Score.getScore(game.board),
        moves: backMove ? game.moves : game.moves.concat(getMoveXAndY(move))
    };
}
142346
def autoencoder_discrete_pong():
  """"""
  hparams = autoencoder_ordered_discrete()
  hparams.num_hidden_layers = 3
  hparams.bottleneck_bits = 24
  hparams.batch_size = 2
  hparams.gan_loss_factor = 0.01
  hparams.bottleneck_l2_factor = 0.001
  hparams.add_hparam("video_modality_loss_cutoff", 0.02)
  return hparams
276075
protected void gotPong (PongResponse pong)
    {
        // if we're not currently calculating our delta, then we can throw away the pong
        if (_dcalc != null) {
            // we update the delta after every receipt so as to immediately obtain an estimate of
            // the clock delta and then refine it as more packets come in
            _dcalc.gotPong(pong);
            _serverDelta = _dcalc.getTimeDelta();
        }
    }
676815
def initial_state(players, small_blind: 10, big_blind: 20, deck_seed: 1)
      reversed_position_order = POSITIONS_ORDER[:preflop].reverse
      positions = players.map.with_index do |player, index|
        last_index = players.count - 1

        [player[:id], reversed_position_order[last_index - index]]
      end.to_h

      normalized_players = players.map do |id:, balance:, **|
        [
          id,
          {
            id: id,
            active: true,
            balance: balance,
            money_in_pot: 0,
            position: positions[id],
            cards: [],
            last_move: {},
          },
        ]
      end.to_h

      Hamster.from(
        players: normalized_players,
        aggressor_id: nil,
        board: [],
        small_blind: small_blind,
        big_blind: big_blind,
        pot: 0,
        pending_request: false,
        winner_ids: [],
        top_hands: {},
        game_ended: false,
        last_action: { type: :game_start },
        current_stage: nil,
        current_player_id: nil,
        deck: Card.french_deck.shuffle(random: Random.new(deck_seed))
      )
    end
26895
function(callback) {
      var t = this;
      callback = callback || function(){};
      var onPong = function() {
        t.off('pong', onPong);
        callback();
      };
      t.on('pong', onPong);
      t.emit('connection:ping');
    }