Get the total number of moves in a game
168337
function () {
			var localSequence = this.game;
			var moves = 0;
			while(localSequence) {
				moves += localSequence.nodes.length;

				if (localSequence.sequences) {
					localSequence = localSequence.sequences[0];
				} else {
					localSequence = null;
				}
			}

			// TODO: Right now we're *assuming* that the root node doesn't have a
			// move in it, which is *recommended* but not required practice.
			// @see http://www.red-bean.com/sgf/sgf4.html
			// "Note: it's bad style to have move properties in root nodes.
			// (it isn't forbidden though)"
			return moves - 1;
		}
420312
def fight(self, moves=10):
        
        for i in range(1, moves):
            # player 1
            result, dmg = self.calc_move(self.c1, self.c2)
            print (self.c1.name + ' ' + result + ' for ' + str(dmg))
            self.c1.sta = self.c1.sta - dmg
            if self.is_character_dead(self.c1):
                print(self.c1.name + ' has died')
                return
            # player 2
            result, dmg = self.calc_move(self.c2, self.c1)
            print (self.c2.name + ' ' + result + ' for ' + str(dmg))
            self.c2.sta = self.c2.sta - dmg
            if self.is_character_dead(self.c2):
                print(self.c2.name + ' has died')
                return
1253802
def x_rolls(self, number, count=0):
        '''
        '''
        for x in range(number):
            yield super(FuncRoll, self).roll(count, self._func)
726459
def traceCount(self):
        
        nsegs = sum([len(track) for track in self._segments])
        if nsegs == 0:
            return 0
        ntraces = 1
        for irow in range(self._autoParams.nrows()):
            ntraces = ntraces*self._autoParams.numSteps(irow)
        return ntraces
701172
protected function calculateActionCount()
    {
        $counter = 0;
        foreach ($this->actions as $actions) {
            $counter += count($actions);
        }

        return $counter;
    }
19198
function (hands, table, dead) {
		// Preprocesses the input data.
		table = table ? _.map(table, getCode) : [];
		dead = dead ? _.map(dead, getCode) : [];
		hands = _.map(hands, function (hand) {
			return _.map(hand, getCode);
		});
		var res = deckSize + 1;
		for (var c = 0; c < table.length; c++)
			res = evaluator[res + table[c]];
		var deck = _.chain(_.range(1, deckSize + 1)).difference(table)
				.difference(_.flatten(hands)).difference(dead).value();
		var player = _.map(hands, function (hand) {
			return evaluator[evaluator[res + hand[0]] + hand[1]];
		});
		var combinations = function (n, k, res, callback) {
			if (k <= 0) {
				callback(res);
			} else {
				while (n < deck.length) {
					var parcial = evaluator[res + deck[n++]];
					combinations(n, k - 1, parcial, callback);
				}
			}
		};
		
		// Calculates the outcome of each play.
		var remaining = 5 - table.length;
		var plays = deck.length / remaining;
		for (var c = 1; c < remaining; c++)
			plays *= (deck.length - c) / c;
		var values = new Array(hands.length);
		for (var p = 0; p < hands.length; p++) {
			var s = 0;
			values[p] = new Int32Array(plays);
			combinations(0, remaining, player[p], function (res) {
				values[p][s++] = res;
			});
		}
		
		// Determines the results.
		var wins = new Int32Array(hands.length);
		var splits = new Int32Array(hands.length);
		for (var s = 0; s < plays; s++) {
			var winner = [0];
			for (var p = 1; p < hands.length; p++) {
				if (values[p][s] > values[winner[0]][s])
					winner = [p];
				else if (values[p][s] == values[winner[0]][s])
					winner.push(p);
			}
			if (winner.length == 1) {
				wins[winner[0]]++;
			} else {
				for (var p = 0; p < winner.length; p++)
					splits[winner[p]]++;
			}
		}
		
		// Formats odds output.
		var odds = [];
		for (var p = 0; p < hands.length; p++)
			odds[p] = {win: wins[p] / plays, split: splits[p] / plays};
		return odds;
	}
163462
def numKeys(self) -> int:
        
        chunks = self._listChunks()
        num_chunks = len(chunks)
        if num_chunks == 0:
            return 0
        count = (num_chunks-1)*self.chunkSize
        last_chunk = self._openChunk(chunks[-1])
        count += sum(1 for _ in last_chunk._lines())
        last_chunk.close()
        return count
425161
def _count_extra_actions(self, game_image):
        """"""
        proportional = self._bonus_tools['extra_action_region']
        # Use ProportionalRegion to isolate the extra actions area
        t, l, b, r = proportional.region_in(game_image)
        token_region = game_image[t:b, l:r]
        # Use TemplateFinder (multiple) to check for extra actions
        game_h, game_w = game_image.shape[0:2]
        token_h = int(round(game_h * 27.0 / 960))
        token_w = int(round(game_w * 22.0 / 1280))
        sizes = (token_h, token_w),
        # sizes change every time so just remake it.
        # thresholds are tight since need to count conservatively
        finder = v.TemplateFinder(pq_data.extra_action_template,
                                  sizes=sizes,
                                  acceptable_threshold=0.1,
                                  immediate_threshold=0.1)
        found_tokens = finder.locate_multiple_in(token_region)
        return len(found_tokens)
235544
def count(self, searchString, category="", math=False, game=False, searchFiles=False, extension=""):
		""""""
		fileData = {}
		nameData = {}
		
		#Search the index
		if searchFiles:
			fileData = self.searchNamesIndex(self.fileIndex, fileData, searchString, category, math, game, extension)
		else:
			nameData = self.searchNamesIndex(self.nameIndex, nameData, searchString)
			
		#Now search the other index
		if searchFiles:
			nameData, fileData = self.searchFilesIndex(fileData, nameData, self.nameIndex, searchString)
		else:
			fileData, nameData = self.searchFilesIndex(nameData, fileData, self.fileIndex, searchString, category, math, game, extension)

		# Bail out if we failed to do either of those things.
		if fileData is None or nameData is None:
			self.repo.printd("Error: failed to load one or more of the index files for this repo. Exiting.")
			self.repo.printd("Please run 'calcpkg update' and retry this command.")
			sys.exit(1)

		#Now obtain a count (exclude "none" elements)
		count = 0
		for element in nameData:
			if not nameData[element] is None:
				count += 1

		self.repo.printd("Search for '" + searchString + "' returned " + str(count) + " result(s) in " + self.repo.name)
		return count
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
148944
def count_row(engine, table):
    
    return engine.execute(select([func.count()]).select_from(table)).fetchone()[0]
1296355
def update(self, new_games):
        
        new_games.sort(key=os.path.basename)
        first_new_game = None
        for idx, game in enumerate(new_games):
            timestamp = file_timestamp(game)
            if timestamp <= self.examples[-1][0]:
                continue
            elif first_new_game is None:
                first_new_game = idx
                num_new_games = len(new_games) - idx
                print("Found {}/{} new games".format(
                    num_new_games, len(new_games)))
                self.total_updates += num_new_games
            self.examples.extend(self.func(game))
        if first_new_game is None:
            print("No new games", file_timestamp(
                new_games[-1]), self.examples[-1][0])
514369
def tick(self):
        """"""
        for npc in self.npcs:
            self.move_entity(npc, *npc.towards(self.player))
        for entity1, entity2 in itertools.combinations(self.entities, 2):
            if (entity1.x, entity1.y) == (entity2.x, entity2.y):
                if self.player in (entity1, entity2):
                    return 'you lost on turn %d' % self.turn
                entity1.die()
                entity2.die()

        if all(npc.speed == 0 for npc in self.npcs):
            return 'you won on turn %d' % self.turn
        self.turn += 1
        if self.turn % 20 == 0:
            self.player.speed = max(1, self.player.speed - 1)
            self.player.display = on_blue(green(bold(unicode_str(self.player.speed))))
110306
def getting(self):
        
        c = Counter(self._get.copy())
        return [(n, t) for t, n in c.items()]
394997
function getPiecesLeft() {
    $.getJSON("/games/" + enc($.cookie("game")) +
              "/pieces", function(data) {
        $(GAMEPIECES).empty();
        var npieces = 0;
        for (var i in data)
            npieces += data[i].count;
        $(GAMEPIECES).html(npieces);
    });
}
1262214
def move(self):
        
        if len(self.moves) == MAX_MOVES:
            return False
        elif len(self.moves) % 2:
            active_engine = self.black_engine
            active_engine_name = self.black
            inactive_engine = self.white_engine
            inactive_engine_name = self.white
        else:
            active_engine = self.white_engine
            active_engine_name = self.white
            inactive_engine = self.black_engine
            inactive_engine_name = self.black
        active_engine.setposition(self.moves)
        movedict = active_engine.bestmove()
        bestmove = movedict.get('move')
        info = movedict.get('info')
        ponder = movedict.get('ponder')
        self.moves.append(bestmove)

        if info["score"]["eval"] == "mate":
            matenum = info["score"]["value"]
            if matenum > 0:
                self.winner_engine = active_engine
                self.winner = active_engine_name
            elif matenum < 0:
                self.winner_engine = inactive_engine
                self.winner = inactive_engine_name
            return False

        if ponder != '(none)':
            return True
863243
def get_game_logs(self):
        """"""
        logs = self.response.json()['resultSets'][0]['rowSet']
        headers = self.response.json()['resultSets'][0]['headers']
        df = pd.DataFrame(logs, columns=headers)
        df.GAME_DATE = pd.to_datetime(df.GAME_DATE)
        return df