Advertisement
zitot

Untitled

Jul 27th, 2018
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.43 KB | None | 0 0
  1.  
  2. io.stdout:setvbuf("no") -- console out put for someline text
  3. CONTINENT = {}
  4. SPECIES = {}
  5. do for u = 1, 8 do SPECIES[u] = {} end end
  6. TRAITS_DECK = {}
  7.  
  8. function autotroph(N)
  9.     -- an autotrophic protist
  10.     SPECIES[N]["cell-type"] = "single-celled"
  11.     SPECIES[N]["aquatic"] = true
  12.     SPECIES[N]["land"] = false
  13.     SPECIES[N]["organism-type"] = "autotroph"
  14.     SPECIES[N]["traits"] = {"protist",[6]="photosynthesis"}
  15.     SPECIES[N]["morphology"] = {"eukaryotic"}
  16. end
  17.  
  18. function setup()
  19.     -- create continent board: 4 resources
  20.     local terrestial    = 10
  21.     local aquatic       = 10
  22.     local organic       = 10
  23.     local inorganic     = 10
  24.  
  25.     -- create species board
  26.     autotroph(1)
  27. end
  28.  
  29. function update_species(N)
  30.     -- find dominant traits
  31.     -- if trait appears more than 4 times, remove it from the species board
  32.     -- add it to the species morphology, add one new trait card to the species
  33.     local traits = {}
  34.     for i = #SPECIES[N]["traits"], 1, -1 do
  35.         local v = SPECIES[N]["traits"][i]
  36.         traits[v] = traits[v] and traits[v] + 1 or 1
  37.  
  38.         if traits[v] > 4 then
  39.             print("Found Dominant Trait '"..v.."' in Species["..N.."]")
  40.             print"Updating morphology and removing dominant trait..."
  41.             table.insert(SPECIES[N]["morphology"], v)
  42.  
  43.             for j = #SPECIES[N]["traits"], 1, -1 do
  44.                 if SPECIES[N]["traits"][j] == v then
  45.                     table.remove(SPECIES[N]["traits"], j)
  46.                 end
  47.             end
  48.         end
  49.     end
  50. end
  51.  
  52. function print_species(N)
  53.     for k,v in pairs(SPECIES[N]) do
  54.         if type(v)=="table" then
  55.             for l,b in pairs(v) do
  56.                 print(k,v,b)
  57.             end
  58.         else
  59.             print(k,v)
  60.         end
  61.     end
  62. end
  63.  
  64. function love.load()
  65.     setup()
  66.     print_species(1)
  67.     update_species(1)
  68.     print"..."
  69.     SPECIES[1]["traits"][2] = "protist"
  70.     SPECIES[1]["traits"][3] = "protist"
  71.     SPECIES[1]["traits"][4] = "protist"
  72.     SPECIES[1]["traits"][5] = "protist"
  73.     --update_species will see 5 same traits and remove those traits
  74.     --and add it to the morphology
  75.     --haven't implemented adding new traits yet
  76.     --also, should there be a chance to draw a card of the trait just removed?
  77.     update_species(1)
  78.     print_species(1)
  79.     update_turn(1)
  80. end
  81.  
  82. function HasPhotosynthesis(N)
  83.     return not not string.find(table.concat(SPECIES[N]["traits"]),"photosynthesis")
  84.         or not not string.find(table.concat(SPECIES[N]["morphology"]),"photosynthesis")
  85. end
  86.  
  87. local turn_count = 1
  88. function update_turn(N)
  89.     print(HasPhotosynthesis(N) and "Ate sunlight" or "Did not eat sunlight")
  90.    
  91.     turn_count=turn_count+1
  92.     print("Another turn has passed")
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement