Get game after n moves.
770486
function getGameAfterMoves(game, moves) {
    return moves.reduce(function (lastGame, move) {
        return getGameAfterMove(lastGame, move);
    }, game);
}
1341772
function addPlayerToGame(game, playernm) {
    var p = new Player(playernm);
    p.pieces = game.drawPieces(6);
    game.players[p.name] = p;

    // if first player, make it his turn
    if (Object.keys(game.players).length === 1) {
        p.has_turn = true;
    }
}
634787
def gameloop(self):
        
        try:
            while True:
                self.handle_events()
                self.update()
                self.render()
        except KeyboardInterrupt:
            pass
1348974
function restartGame(players) {
    // Replace the current instance with a new instance
    let newGame = new RockPaperScissors(game, players, winCounter, id);
    proxy.swap(newGame);

    q.delay(RESULTS_DELAY)
      .done(function() {
        deferred.resolve(newGame.handleIt(callbacks));
      });
  }
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();
      }
276690
def is_done(self):
        """"""
        return self.position.is_game_over() or self.position.n >= FLAGS.max_game_length
946518
def game(game_seeds, ranks)
      game_seeds.each_with_index do |iseed, i|
        game_seeds.each_with_index do |jseed, j|
          next if i == j
          @raters[iseed].add(player(jseed).rating, Util.ranks_to_score(ranks[i], ranks[j]))
        end
      end
    end
528467
def update_picks(self, games=None, points=None):
        '''
        
        '''
        if games:
            game_dict = {g.id: g for g in self.gameset.games.filter(id__in=games)}
            game_picks = {pick.game.id: pick for pick in self.gamepicks.filter(game__id__in=games)}
            for key, winner in games.items():
                game = game_dict[key]
                if not game.has_started:
                    pick = game_picks[key]
                    pick.winner_id = winner
                    pick.save()

        if points is not None:
            self.points = points
            self.save()

        if games or points:
            self.updated_signal.send(sender=self.__class__, pickset=self, auto_pick=False)
1316549
def parse_game_result(result):
    ""
    if re.match(r'[bB]\+', result):
        return 1
    if re.match(r'[wW]\+', result):
        return -1
    return 0
724061
def tictactoe(w, i, player, opponent, grid=None):
    ""
    grid = grid or empty_grid
    while True:
        w.render_to_terminal(w.array_from_text(view(grid)))
        if is_won(grid):
            print(whose_move(grid), "wins.")
            break
        if not successors(grid):
            print("A draw.")
            break
        grid = player(w, i, grid)
        player, opponent = opponent, player
478243
def game_counts(n_back=20):
    """"""
    for _, model_name in get_models[-n_back:]:
        games = get_games(model_name)
        print("Model: {}, Games: {}".format(model_name, len(games)))
256579
def main_loop(self):
        """"""
        while True:
            for e in pygame.event.get():
                self.handle_event(e)

            self.step()
            pygame.time.wait(5)
271964
async def step(self):
        
        result = await self._execute(step=sc_pb.RequestStep(count=self.game_step))
        return result
1040516
def fight(self, moves, print_console):
        
        for _ in range(1, moves):
            #if i == 1 and random.randint(1,100) > 50:   # randomly choose who moves first
            # player 1
            result, dmg = self.calc_move(self.c1)
            self.show_message(self.c1, self.c2, result, dmg, print_console)
            self.take_damage(self.c2, dmg)
            if self.is_character_dead(self.c2):
                #print(self.c2.name + ' has died')
                return self.c1.name
                
            # player 2
            result, dmg = self.calc_move(self.c2)
            self.show_message(self.c2, self.c1, result, dmg, print_console)
            self.take_damage(self.c1, dmg)
            if self.is_character_dead(self.c1):
                #print(self.c1.name + ' has died')
                return self.c2.name
480840
public void previous() {
        final PlayList pl = getPlaylist();

        final int previousPosition = pl.getCurrentSlide();
        pl.previous();
        final int currentPosition = pl.getCurrentSlide();

        playSlide(currentPosition, previousPosition);
    }
771592
def learn(self, initial_state_key, limit=1000, game_n=1):
        '''
        
            
        '''
        end_flag = False
        state_key_list = [None] * len(self.q_learning_list)
        action_key_list = [None] * len(self.q_learning_list)
        next_action_key_list = [None] * len(self.q_learning_list)
        for game in range(game_n):
            state_key = initial_state_key
            self.t = 1
            while self.t <= limit:
                for i in range(len(self.q_learning_list)):
                    state_key_list[i] = state_key
                    if game + 1 == game_n:
                        self.state_key_list.append(tuple(i, state_key_list))
                    self.q_learning_list[i].t = self.t
                    next_action_list = self.q_learning_list[i].extract_possible_actions(tuple(i, state_key_list))
                    if len(next_action_list):
                        action_key = self.q_learning_list[i].select_action(
                            state_key=tuple(i, state_key_list),
                            next_action_list=next_action_list
                        )
                        action_key_list[i] = action_key
                        reward_value = self.q_learning_list[i].observe_reward_value(
                            tuple(i, state_key_list), 
                            tuple(i, action_key_list)
                        )

                        # Check.
                        if self.q_learning_list[i].check_the_end_flag(tuple(i, state_key_list)) is True:
                            end_flag = True

                        # Max-Q-Value in next action time.
                        next_next_action_list = self.q_learning_list[i].extract_possible_actions(
                            tuple(i, action_key_list)
                        )
                        if len(next_next_action_list):
                            next_action_key = self.q_learning_list[i].predict_next_action(
                                tuple(i, action_key_list), 
                                next_next_action_list
                            )
                            next_action_key_list[i] = next_action_key
                            next_max_q = self.q_learning_list[i].extract_q_df(
                                tuple(i, action_key_list), 
                                next_action_key
                            )

                            # Update Q-Value.
                            self.q_learning_list[i].update_q(
                                state_key=tuple(i, state_key_list),
                                action_key=tuple(i, action_key_list),
                                reward_value=reward_value,
                                next_max_q=next_max_q
                            )

                            # Update State.
                            state_key = self.q_learning_list[i].update_state(
                                state_key=tuple(i, state_key_list),
                                action_key=tuple(i, action_key_list)
                            )
                            state_key_list[i] = state_key

                    # Epsode.
                    self.t += 1
                    self.q_learning_list[i].t = self.t
                    if end_flag is True:
                        break
1174779
function getGameBeforeLastMove(game) {
    // $Fix I do NOT know if it is the best way to make game immutable.
    game = Object.assign({}, game);
    let lastMove = game.moves.pop();
    if (lastMove)
        game = getGameAfterMove(game, getBackMove(lastMove), true);
    if (Game.getPlayerTurn(game).isAi) {
        lastMove = game.moves.pop();
        if (lastMove) {
            game = getGameAfterMove(game, getBackMove(lastMove), true);
        }
    }
    return game;
}