Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Starting to learn KOS and beeing genereally bored by "Hello World" scripts I decided to try doing something really seful with all the computing power available on board. This will also explain why on the last mission the batteries were depleted after half the trip, the kerbonauts too drunk to give a status report to mission control and the ships board computer claiming that he is feeling just great, guys "and I know I'm going to get a bundle of kicks out of any program you care to run through me."
- //MIT License - do with this code whatever you like.
- @lazyglobal off.
- global fields to list(). //two set of fields for playing Conway's Game of Life
- global rows to list(). //build a 3-dimensional array fields/rows/cells
- global currfieldno to 0. //one field to be repopulated
- global prevfieldno to 0. //based on the population in the previous turn
- global beer to 0. //loop counter (defined globally because it is being manipualted in 'on'-statement)
- global texts to list(). //just a list of the textsnippets used.
- set texts to list("Devide By Cucumber Error. Please Reinstall Universe And Reboot +++","++?????++ Out of Beer Error. Redo From Start. +++","Better use that $*&#%! computer for getting your crew back to Kerbin. ","No more bottles of beer in front of the terminal, no more bottles of beer.","Bob is now sitting happily in front of the terminal and drinking beer.","...or the life support system.","...with the enignes...","and might keep him from tinkering...","the good thing is - this will keep Bob busy","Another masterpiece of the Mega-Mighty umm... Conway !!","...some of your Engineers are infected by COMPUTERGAMES !!!").
- declare function X_Clacks_Overhead {return "GNU Terry Pratchett".}
- lights on.
- on lights //runs whenever lights are toggled
- {
- if beer > 0 and beer < 100 and not(lights) //if there is enough beer and lights have been toggled off.
- {
- local steal to round(random()*9+1,0). //steel 1 to 9 bottles of beer
- if steal > beer-1 {set steal to beer-1.} //leave at least 1
- print "Jeb stole "+steal+" bottles of beer from Bob. Bob turns the lights back on. " at (0,22).
- set beer to beer-steal.
- }
- preserve. //enable on statement to be toggled again.
- }
- if terminal:width < 80 {set terminal:width to 80.} //minimum required screen width to fit the text on the terminal.
- if terminal:height < 25 {set terminal:height to 25.}
- clearscreen.
- print "Something wonderful has happened". //here we go
- wait 1.
- print "Your "+core:part:title+" is alive!!!". //no Amiga was available.
- wait 1.
- print "and, even better...".
- from {local xval to 0.} until xval>9 step {set xval to xval+1.} do //create 10 by 10 grid with
- {
- from {local yval to 0.} until yval>9 step {set yval to yval+1.} do
- {
- if random()>0.44 //start with an average of 4 of 9 fields populated
- {fields:add(true).}
- else {fields:add(false).}
- }
- rows:add(fields).
- set fields to list().
- }
- fields:add(rows).
- fields:add(rows). //add a copy to the second (inactive) field for overwriting in next step.
- from {set beer to 3.} until beer<-3 step {set beer to beer-1.} do//main loop 106
- {
- from {local xval to 0.} until xval>9 step {set xval to xval+1.} do //print field
- {
- from {local yval to 0.} until yval>9 step {set yval to yval+1.} do
- {
- if fields[currfieldno][xval][yval]
- {print "O" at ((xval+2),yval+5).}
- else {print " " at ((xval+2),yval+5).}
- }
- }
- print "+----------+" at (1,4). //(re)print frame
- from {local loop to 0.} until loop>9 step {set loop to loop+1.} do
- {
- print "|" at (1,loop+5).
- print "|" at (12,loop+5).
- }
- print "+----------+" at (1,15).
- if currfieldno=0 //switch current and previous field
- {set currfieldno to 1. set prevfieldno to 0.}
- else {set currfieldno to 0. set prevfieldno to 1.}
- from {local xval to 0.} until xval>9 step {set xval to xval+1.} do //calculate next iteration
- {
- from {local yval to 0.} until yval>9 step {set yval to yval+1.} do
- {
- local cellcount to 0.
- from {local dx to max(0,xval-1).} until dx > min(9,xval+1) step {set dx to dx+1.} do
- {
- from {local dy to max(0,yval-1).} until dy > min(9,yval+1) step {set dy to dy+1.} do
- {
- if fields[prevfieldno][dx][dy]
- {set cellcount to cellcount +1.}
- }
- }
- if fields[prevfieldno][xval][yval] //check conditions for populated field
- {
- if cellcount<3 or cellcount >4 //<2 neighbours or >3 neighbours: living cell dies
- {set fields[currfieldno][xval][yval] to false.}
- else {set fields[currfieldno][xval][yval] to true.}
- }
- else //check conditions for empty field
- {
- if cellcount=3 //3 neighbours: new cell created
- {set fields[currfieldno][xval][yval] to true.}
- else {set fields[currfieldno][xval][yval] to false.}
- }
- }
- }
- if beer > 99 {print texts[beer-107+texts:length]+" " at (0,17).}
- else if beer > 0
- {
- print beer+" bottles of beer in front of the terminal, "+beer+" bottles of beer. " at (0,19).
- if beer > 1
- {
- print "Take one down and pass it around, "+(beer-1)+" bottles in front of the terminal. " at (0,20).
- print "Toggle the lights to allow Jeb to steal some of Bobs beer. " at (0,22).
- }
- else
- {
- print"Take one down and pass it around, no more bottles in front of the terminal. " at (0,20).
- print" " at (0,21).
- print" " at (0,22).
- }
- lights on.
- }
- else {print texts[beer+3] at (0,19-beer).}
- } //exit
- wait 5.
Advertisement
Add Comment
Please, Sign In to add comment