Skip to content

Instantly share code, notes, and snippets.

@luckytyphlosion
Created February 27, 2020 00:41
Show Gist options
  • Save luckytyphlosion/195b8b76bd1a43570a170b56405358e7 to your computer and use it in GitHub Desktop.
Save luckytyphlosion/195b8b76bd1a43570a170b56405358e7 to your computer and use it in GitHub Desktop.
simulate spawns
import random
def get_num_endermen(simulating, chunks):
chunks = [{} for i in range(256)]
num_mobs = 0
MOB_CAP = 70
num_endermen = 0
MOB_CHOICES = ("spider", "zombie", "zombie_villager", "skeleton", "creeper", "slime", "enderman", "witch")
MOB_WEIGHTS = (100, 95, 5, 100, 100, 100, 10, 5)
while num_mobs < MOB_CAP:
hit_chunk_cap = False
for i in range(256):
num_mobs_in_chunk = 0
good_spawn = False
if random.random() >= 0.0125:
continue
for j in range(3):
random_lim = random.randint(1, 4)
mob_type = random.choices(MOB_CHOICES, MOB_WEIGHTS)[0]
y = 0
for k in range(random_lim):
y += random.randint(0, 1) - random.randint(0, 1)
if y == 0:
if mob_type == "enderman":
num_endermen += 1
if mob_type in chunks[i]:
chunks[i][mob_type] += 1
else:
chunks[i][mob_type] = 1
num_mobs_in_chunk += 1
num_mobs += 1
if num_mobs_in_chunk >= 4:
hit_chunk_cap = True
break
if hit_chunk_cap:
break
if simulating:
return num_endermen
output = ""
for i, chunk in enumerate(chunks):
if len(chunk) != 0:
output += f"{i:03d}: " + ", ".join(f"{key}: {item}" for key, item in chunk.items()) + "\n"
output += f"num_endermen: {num_endermen}\nnum_mobs: {num_mobs}\n"
print(output)
def main():
num_endermen = 0
chunks = [{} for i in range(256)]
distribution = []
max_endermen = 0
for i in range(10000):
cur_num_endermen = get_num_endermen(True, chunks)
if cur_num_endermen >= len(distribution):
distribution.extend([0] * (cur_num_endermen + 1 - len(distribution)))
distribution[cur_num_endermen] += 1
num_endermen += cur_num_endermen
if cur_num_endermen > max_endermen:
max_endermen = cur_num_endermen
for i in range(256):
chunks[i].clear()
output = f"average_endermen: {num_endermen/10000}, max_endermen: {max_endermen}\n"
for i, count in enumerate(distribution):
output += f"{i:02d}: {count}\n"
print(output)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment