Random level generator

Safer than Professor Rex's office hours
Post Reply
A Random Player
Posts: 523
Joined: Mon Jun 03, 2013 4:54 pm

Random level generator

Post by A Random Player »

Code: Select all

import random
#[My Level 1, [o,o,o,o,o,o,o,o,o,o,o,o,o,o,o;o,x,o,w,o,t-4-0,o,f-15-12,o,s,o,g,o,k-600,o;o,o,o,o,o,o,o,o,o,o,o,o,o,o,o;o,b1-2.2-2,o,b2-2.2-2,o,b3-2.2-2,o,b4-2.2-2,o,o,o,o,o,o,o;o,o,o,o,o,o,o,o,o,o,o,o,o,o,o;o,o,o,o,o,o,o,o,o,o,o,o,o,o,o;o,o,o,o,o,o,o,o,o,o,o,o,o,o,o;o,o,o,o,o,o,o,o,o,o,o,o,o,o,o;o,o,o,o,o,o,o,o,o,o,o,o,o,o,o;c-1-0-0,c-1-14.9-8.9,cw-1-11.1-4.5,g1-0.8-0-7,g1-0.8-13.7-0,g2-0.8-13-0,g2-0.8-0-7.8;]]
output = "[ARP's random level, ["
for a in range(9):
 for b in range(15):
  tiletype = random.random()
  if tiletype > .31 or (a == 9 and b == 15):
   output = output + "o,"
  elif tiletype > .24:
   output = output + "x,"
  elif tiletype > .19:
   output = output + "w,"
  elif tiletype > .13:
   output = output + "t-" + str(random.uniform(1,10)) + "-" + str(random.uniform(0,10)) + ","
  elif tiletype > .11:
   output = output + "f-" + str(random.uniform(5,30)) + "-" + str(random.uniform(5,20)) + ","
  elif tiletype > .09:
   output = output + "s,"
  elif tiletype > .08:
   output = output + "g,"
  elif tiletype > .06:
   output = output + "k-" + str(random.uniform(400,900)) + ","
  else:
   output = output + "b" + str(random.randint(1,4)) + "-" + str(random.uniform(1.5,2.7)) + "-" + str(random.uniform(1,6)) + ","
 output = output[:-1] + ";"
for a in range(random.randint(0,4)):
 addtype = random.randint(1,3)
 if addtype == 1:
  output = output + "c-" + str(random.uniform(.5,2)) + "-" + str(random.uniform(0,15)) + "-" + str(random.uniform(0,9)) + ","
 elif addtype == 2:
  output = output + "cw-" + str(random.uniform(.5,2)) + "-" + str(random.uniform(0,15)) + "-" + str(random.uniform(0,9)) + ","
 elif addtype == 3:
  output = output + "g" + str(random.randint(1,2)) + "-" + str(random.uniform(.5,3)) + "-" + str(random.uniform(0,15)) + "-" + str(random.uniform(0,9)) + ","
if output[-1] == ",":
 output = output[:-1]
output = output + ";]]"
print output
http://codepad.org/5qKnyXd8
So apparently I made a random level generator. It makes levels like this:

Code: Select all

[ARP's random level, [o,o,o,o,o,s,o,o,o,o,o,k-521.740442053,o,b1-2.68109337555-5.68242959863,o;x,o,o,o,o,o,o,f-8.02453189842-17.2500176641,o,b1-2.47473225561-4.13223064348,o,o,o,b2-2.57015100139-1.36581023988,k-618.567564542;o,o,w,o,o,o,o,o,o,o,b3-1.98905222673-3.54633219109,t-2.1761335776-5.90915841767,o,o,o;b1-2.47601734472-2.11511355285,o,t-9.69671977565-5.41942957983,o,o,o,o,x,o,t-7.80473577771-5.1835222225,o,o,b1-1.62682627353-2.96954296361,w,o;o,s,o,w,o,f-6.07455896551-6.83652723416,k-403.415712218,o,o,o,o,o,x,o,f-18.3175456303-19.0070804615;k-714.081037298,o,o,o,x,o,x,o,t-1.16113784588-0.324628695179,o,t-5.21492370658-9.95544645871,o,o,o,o;b2-2.38052851941-5.08223121117,o,o,x,o,s,o,t-1.73528349109-5.33572606105,o,o,t-5.63517135056-6.67727324279,o,w,b4-1.58093631578-4.6446465737,o;x,o,o,o,o,k-877.367782606,o,w,o,o,t-1.29830178389-1.26635820209,o,o,o,t-5.73038457352-4.50114524899;o,k-550.646372021,o,x,o,o,o,t-1.65790773038-3.90106161098,o,o,o,o,o,w,o;;]]
They're not always beatable, but it can be fun to see how one would beat them (and then beating them). You can post one's you've generated. (Click Create a new paste, and then submit, at the link to rerun the code if you don't have a python interpreter)
$1 = 100¢ = (10¢)^2 = ($0.10)^2 = $0.01 = 1¢ [1]
Always check your units or you will have no money!
User avatar
testtubegames
Site Admin
Posts: 1148
Joined: Mon Nov 19, 2012 7:54 pm

Re: Random level generator

Post by testtubegames »

Whoa, neat! I love random levels.

You're pretty crafty with that python code, ARP. Could you possibly write one that makes full science games from scratch? That'd really help me out ;)
Post Reply