<commit_before>var VERSION_STRING = 'v0.1';

function randomizeROM(buffer, seed)
{
	var ext = '.nes';

	var random = new Random(seed);
	var vseed = random.seed.toHex(8);

	$('#custom-seed').val('');
	$('#used-seed').text(vseed);

	var rom = new Uint8Array(buffer);

	if ($('#randomize_roundlength').is(':checked'))
		randomizeRoundLength(random, rom);

	if ($('#randomize_hearts').is(':checked'))
		randomizeHearts(random, rom);

	if ($('#glassjoe_patterns' ).is(':checked')) randomizeGlassJoePatterns(random, rom);
	if ($('#glassjoe_damage'   ).is(':checked')) randomizeGlassJoeDamage(random, rom);
	if ($('#glassjoe_threshold').is(':checked')) randomizeGlassJoeThreshold(random, rom);

	// update the location.hash
	var preset = +$('#preset').val();
	if (!preset) preset = 'x' + getRandomizerSettings();

	// return the modified buffer
	return { seed: vseed, preset: preset, buffer: rom.buffer, type: ext || '.nes' };
}

function randomizeRoundLength(random, rom)
{
	rom[0x0E7D2] = 1 + random.nextInt(5);
	rom[0x0E80E] = rom[0x0E7D2] + 1;
}

function randomizeHearts(random, rom)
{
	// hearts lost when opponent lands punch on Mac
	rom[0x0E154] = random.nextIntRange(0x06, 0x10);

	// hearts lost when Mac blocks a punch
	rom[0x0E0E2] = random.nextIntRange(0x01, 0x06);

	// Glass Joe
	rom[0x0132C] = 1 + random.nextInt(20); // start round 1
	rom[0x0132F] = 1 + random.nextInt(20); // start round 2
	rom[0x01330] = 1 + random.nextInt(20); // start round 3
	rom[0x0132D] = 1 + random.nextInt(15); // after running out and dodging
	rom[0x0132E] = 1 + random.nextInt( 9); // after getting up from KO
}

function randomizeGlassJoePatterns(random, rom)
{
	rom[0x01434] = random.nextIntRange(0x0A, 0xB6); // timing of round 1 charge attack
	rom[0x01450] = random.nextIntRange(0x0A, 0xB6); // timing of round 2 charge attack
	rom[0x0145F] = random.nextIntRange(0x0A, 0xB6); // timing of round 3 charge attack

	rom[0x0146C] = random.from([0x73, 0x78]); // wait until charge in round 1 before punching (73=y, 78=n)
	rom[0x01476] = random.from([0x80, 0x50]); // can dodge? (80=y, 50=n)

	// number of punches before being awarded stars 1st and subsequent times
	rom[0x01336] = 3 + Math.min(Math.floor(Math.abs(random.nextGaussian() * 10)), 100);
	rom[0x01337] = 5 + Math.min(Math.floor(Math.abs(random.nextGaussian() * 10)), 100);

	// downtime values
	for (var i = 0; i < 8; ++i) rom[0x01366+i] = random.nextIntRange(0x9B, 0xA3);

	// special scenario downtime values (XY, X = count, Y = health when up)
	rom[0x013D7] = (random.nextIntRange(0x01, 0x0A) << 4) | random.nextIntRange(0x01, 0x0D);

	rom[0x01083] = 1 + random.nextInt(0xFF); // GJ waiting time before charging
	rom[0x01387] = random.nextInt(0x08); // # of hits when stunned (dodge hook)
	rom[0x00C1B] = random.nextInt(0x08); // # of hits when stunned (block)
	rom[0x00C25] = random.nextInt(0x08); // # of hits when stunned (jab and ducking)

	rom[0x17A87] = random.from([0x04, 0x05]); // situation 1 (04=blocks, 05=punch lands)
	rom[0x17AD3] = random.from([0x04, 0x05]); // situation 2 (04=blocks, 05=punch lands)
	rom[0x17B73] = random.from([0x04, 0x05]); // situation 3 (04=blocks, 05=punch lands)

	rom[0x01473] = random.nextIntRange(0x05, 0x61); // delay after blocking GJ's hook<commit_msg>Heart variables are stored as binary-coded decimal<commit_after>var VERSION_STRING = 'v0.1';

function randomizeROM(buffer, seed)
{
	var ext = '.nes';

	var random = new Random(seed);
	var vseed = random.seed.toHex(8);

	$('#custom-seed').val('');
	$('#used-seed').text(vseed);

	var rom = new Uint8Array(buffer);

	if ($('#randomize_roundlength').is(':checked'))
		randomizeRoundLength(random, rom);

	if ($('#randomize_hearts').is(':checked'))
		randomizeHearts(random, rom);

	if ($('#glassjoe_patterns' ).is(':checked')) randomizeGlassJoePatterns(random, rom);
	if ($('#glassjoe_damage'   ).is(':checked')) randomizeGlassJoeDamage(random, rom);
	if ($('#glassjoe_threshold').is(':checked')) randomizeGlassJoeThreshold(random, rom);

	// update the location.hash
	var preset = +$('#preset').val();
	if (!preset) preset = 'x' + getRandomizerSettings();

	// return the modified buffer
	return { seed: vseed, preset: preset, buffer: rom.buffer, type: ext || '.nes' };
}

function toBinaryCodedDecimal(dec)
{ return (Math.floor(dec/10) << 4) | (dec%10); }

function randomizeRoundLength(random, rom)
{
	rom[0x0E7D2] = 1 + random.nextInt(5);
	rom[0x0E80E] = rom[0x0E7D2] + 1;
}

function randomizeHearts(random, rom)
{
	// hearts lost when opponent lands punch on Mac
	rom[0x0E154] = random.nextIntRange(0x06, 0x10);

	// hearts lost when Mac blocks a punch
	rom[0x0E0E2] = random.nextIntRange(0x01, 0x06);

	// Glass Joe
	rom[0x0132C] = toBinaryCodedDecimal(1 + random.nextInt(20)); // start round 1
	rom[0x0132F] = toBinaryCodedDecimal(1 + random.nextInt(20)); // start round 2
	rom[0x01330] = toBinaryCodedDecimal(1 + random.nextInt(20)); // start round 3
	rom[0x0132D] = toBinaryCodedDecimal(1 + random.nextInt(15)); // after running out and dodging
	rom[0x0132E] = toBinaryCodedDecimal(1 + random.nextInt( 9)); // after getting up from KO
}

function randomizeGlassJoePatterns(random, rom)
{
	rom[0x01434] = random.nextIntRange(0x0A, 0xB6); // timing of round 1 charge attack
	rom[0x01450] = random.nextIntRange(0x0A, 0xB6); // timing of round 2 charge attack
	rom[0x0145F] = random.nextIntRange(0x0A, 0xB6); // timing of round 3 charge attack

	rom[0x0146C] = random.from([0x73, 0x78]); // wait until charge in round 1 before punching (73=y, 78=n)
	rom[0x01476] = random.from([0x80, 0x50]); // can dodge? (80=y, 50=n)

	// number of punches before being awarded stars 1st and subsequent times
	rom[0x01336] = 3 + Math.min(Math.floor(Math.abs(random.nextGaussian() * 10)), 100);
	rom[0x01337] = 5 + Math.min(Math.floor(Math.abs(random.nextGaussian() * 10)), 100);

	// downtime values
	for (var i = 0; i < 8; ++i) rom[0x01366+i] = random.nextIntRange(0x9B, 0xA3);

	// special scenario downtime values (XY, X = count, Y = health when up)
	rom[0x013D7] = (random.nextIntRange(0x01, 0x0A) << 4) | random.nextIntRange(0x01, 0x0D);

	rom[0x01083] = 1 + random.nextInt(0xFF); // GJ waiting time before charging
	rom[0x01387] = random.nextInt(0x08); // # of hits when stunned (dodge hook)
	rom[0x00C1B] = random.nextInt(0x08); // # of hits when stunned (block)
	rom[0x00C25] = random.nextInt(0x08); // # of hits when stunned (jab and ducking)

	rom[0x17A87] = random.from([0x04, 0x05]); // situation 1 (04=blocks, 05=punch lands)
	rom[0x17AD3] = random.from([0x04, 0x05]); // situation 2 (04=blocks, 05=punch lands)
	rom[0x17B73] = random.from([0x04, 0x05]); // situation 3 (04=blocks, 05=punch lands)

	rom[0x01473] = random.nextIntRange(0x05, 0x61); // delay after blocking GJ's hook
{'fraction_non_alphanumeric': 0.1666171666171666, 'fraction_numerical': 0.08716958716958717, 'mean_word_length': 4.811044003451251, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7172890', 'n_tokens_mistral': 2930, 'n_tokens_neox': 2585, 'n_words': 617}