Guest User

KOS-GOL

a guest
Sep 29th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. //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."
  2. //MIT License - do with this code whatever you like.
  3. @lazyglobal off.
  4. global fields to list(). //two set of fields for playing Conway's Game of Life
  5. global rows to list(). //build a 3-dimensional array fields/rows/cells
  6. global currfieldno to 0. //one field to be repopulated
  7. global prevfieldno to 0. //based on the population in the previous turn
  8. global beer to 0. //loop counter (defined globally because it is being manipualted in 'on'-statement)
  9. global texts to list(). //just a list of the textsnippets used.
  10. 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 !!!").
  11. declare function X_Clacks_Overhead {return "GNU Terry Pratchett".}
  12. lights on.
  13. on lights //runs whenever lights are toggled
  14. {
  15. if beer > 0 and beer < 100 and not(lights) //if there is enough beer and lights have been toggled off.
  16. {
  17. local steal to round(random()*9+1,0). //steel 1 to 9 bottles of beer
  18. if steal > beer-1 {set steal to beer-1.} //leave at least 1
  19. print "Jeb stole "+steal+" bottles of beer from Bob. Bob turns the lights back on. " at (0,22).
  20. set beer to beer-steal.
  21. }
  22. preserve. //enable on statement to be toggled again.
  23. }
  24. if terminal:width < 80 {set terminal:width to 80.} //minimum required screen width to fit the text on the terminal.
  25. if terminal:height < 25 {set terminal:height to 25.}
  26. clearscreen.
  27. print "Something wonderful has happened". //here we go
  28. wait 1.
  29. print "Your "+core:part:title+" is alive!!!". //no Amiga was available.
  30. wait 1.
  31. print "and, even better...".
  32. from {local xval to 0.} until xval>9 step {set xval to xval+1.} do //create 10 by 10 grid with
  33. {
  34. from {local yval to 0.} until yval>9 step {set yval to yval+1.} do
  35. {
  36. if random()>0.44 //start with an average of 4 of 9 fields populated
  37. {fields:add(true).}
  38. else {fields:add(false).}
  39. }
  40. rows:add(fields).
  41. set fields to list().
  42. }
  43. fields:add(rows).
  44. fields:add(rows). //add a copy to the second (inactive) field for overwriting in next step.
  45. from {set beer to 3.} until beer<-3 step {set beer to beer-1.} do//main loop 106
  46. {
  47. from {local xval to 0.} until xval>9 step {set xval to xval+1.} do //print field
  48. {
  49. from {local yval to 0.} until yval>9 step {set yval to yval+1.} do
  50. {
  51. if fields[currfieldno][xval][yval]
  52. {print "O" at ((xval+2),yval+5).}
  53. else {print " " at ((xval+2),yval+5).}
  54. }
  55. }
  56. print "+----------+" at (1,4). //(re)print frame
  57. from {local loop to 0.} until loop>9 step {set loop to loop+1.} do
  58. {
  59. print "|" at (1,loop+5).
  60. print "|" at (12,loop+5).
  61. }
  62. print "+----------+" at (1,15).
  63. if currfieldno=0 //switch current and previous field
  64. {set currfieldno to 1. set prevfieldno to 0.}
  65. else {set currfieldno to 0. set prevfieldno to 1.}
  66. from {local xval to 0.} until xval>9 step {set xval to xval+1.} do //calculate next iteration
  67. {
  68. from {local yval to 0.} until yval>9 step {set yval to yval+1.} do
  69. {
  70. local cellcount to 0.
  71. from {local dx to max(0,xval-1).} until dx > min(9,xval+1) step {set dx to dx+1.} do
  72. {
  73. from {local dy to max(0,yval-1).} until dy > min(9,yval+1) step {set dy to dy+1.} do
  74. {
  75. if fields[prevfieldno][dx][dy]
  76. {set cellcount to cellcount +1.}
  77. }
  78. }
  79. if fields[prevfieldno][xval][yval] //check conditions for populated field
  80. {
  81. if cellcount<3 or cellcount >4 //<2 neighbours or >3 neighbours: living cell dies
  82. {set fields[currfieldno][xval][yval] to false.}
  83. else {set fields[currfieldno][xval][yval] to true.}
  84. }
  85. else //check conditions for empty field
  86. {
  87. if cellcount=3 //3 neighbours: new cell created
  88. {set fields[currfieldno][xval][yval] to true.}
  89. else {set fields[currfieldno][xval][yval] to false.}
  90. }
  91. }
  92. }
  93. if beer > 99 {print texts[beer-107+texts:length]+" " at (0,17).}
  94. else if beer > 0
  95. {
  96. print beer+" bottles of beer in front of the terminal, "+beer+" bottles of beer. " at (0,19).
  97. if beer > 1
  98. {
  99. print "Take one down and pass it around, "+(beer-1)+" bottles in front of the terminal. " at (0,20).
  100. print "Toggle the lights to allow Jeb to steal some of Bobs beer. " at (0,22).
  101. }
  102. else
  103. {
  104. print"Take one down and pass it around, no more bottles in front of the terminal. " at (0,20).
  105. print" " at (0,21).
  106. print" " at (0,22).
  107. }
  108.  
  109. lights on.
  110. }
  111. else {print texts[beer+3] at (0,19-beer).}
  112. } //exit
  113. wait 5.
Advertisement
Add Comment
Please, Sign In to add comment