forked from github/server
new players are now read from a players.txt file
check for duplicates start with better miners
This commit is contained in:
parent
e55c2d63bf
commit
5291b32459
|
@ -1,4 +1,20 @@
|
||||||
function seed(r, email, race, lang)
|
dofile("config.lua")
|
||||||
|
p = require("populate")
|
||||||
|
|
||||||
|
local function read_players()
|
||||||
|
-- return {{ email = "noreply@mailinator.com", race = "dwarf", lang = "de" }}
|
||||||
|
local players = {}
|
||||||
|
local input = open("players.txt", "r")
|
||||||
|
while input do
|
||||||
|
local str = input:read("*line")
|
||||||
|
if str==nil then break end
|
||||||
|
local email, race, lang = str:match("([^ ]*) ([^ ]*) ([^ ]*)")
|
||||||
|
table.insert(players, { race = race, lang = lang, email = email })
|
||||||
|
end
|
||||||
|
return players
|
||||||
|
end
|
||||||
|
|
||||||
|
local function seed(r, email, race, lang)
|
||||||
local f = faction.create(email, race, lang)
|
local f = faction.create(email, race, lang)
|
||||||
local u = unit.create(f, r)
|
local u = unit.create(f, r)
|
||||||
u:set_skill("perception", 30)
|
u:set_skill("perception", 30)
|
||||||
|
@ -17,7 +33,6 @@ function seed(r, email, race, lang)
|
||||||
u = nil
|
u = nil
|
||||||
skills ={
|
skills ={
|
||||||
"crossbow",
|
"crossbow",
|
||||||
"mining",
|
|
||||||
"bow",
|
"bow",
|
||||||
"building",
|
"building",
|
||||||
"trade",
|
"trade",
|
||||||
|
@ -32,7 +47,6 @@ function seed(r, email, race, lang)
|
||||||
"sailing",
|
"sailing",
|
||||||
"polearm",
|
"polearm",
|
||||||
"espionage",
|
"espionage",
|
||||||
"quarrying",
|
|
||||||
"roadwork",
|
"roadwork",
|
||||||
"tactics",
|
"tactics",
|
||||||
"stealth",
|
"stealth",
|
||||||
|
@ -42,6 +56,8 @@ function seed(r, email, race, lang)
|
||||||
"stamina"
|
"stamina"
|
||||||
}
|
}
|
||||||
unit.create(f, r, 50):set_skill("entertainment", 15)
|
unit.create(f, r, 50):set_skill("entertainment", 15)
|
||||||
|
unit.create(f, r, 5):set_skill("mining", 30)
|
||||||
|
unit.create(f, r, 5):set_skill("quarrying", 30)
|
||||||
for _, sk in ipairs(skills) do
|
for _, sk in ipairs(skills) do
|
||||||
u = u or unit.create(f, r, 5)
|
u = u or unit.create(f, r, 5)
|
||||||
if u:set_skill(sk, 15)>0 then u=nil end
|
if u:set_skill(sk, 15)>0 then u=nil end
|
||||||
|
@ -49,13 +65,9 @@ function seed(r, email, race, lang)
|
||||||
return f
|
return f
|
||||||
end
|
end
|
||||||
|
|
||||||
turn = 923
|
local function dump_selection(sel)
|
||||||
dofile("config.lua")
|
local best = { score = 0, r = nil }
|
||||||
p = require("populate")
|
local r, score
|
||||||
eressea.read_game(("%d.dat"):format(turn))
|
|
||||||
best = { score = 0, r = nil }
|
|
||||||
limit = 30000
|
|
||||||
sel = p.select(regions(), limit)
|
|
||||||
for _, r in ipairs(sel) do
|
for _, r in ipairs(sel) do
|
||||||
score = p.score(r)
|
score = p.score(r)
|
||||||
if score > best.score then
|
if score > best.score then
|
||||||
|
@ -64,26 +76,51 @@ for _, r in ipairs(sel) do
|
||||||
end
|
end
|
||||||
print(score, r, r.terrain)
|
print(score, r, r.terrain)
|
||||||
end
|
end
|
||||||
-- print(best.r, best.score)
|
return best
|
||||||
|
end
|
||||||
|
|
||||||
|
players = read_players()
|
||||||
|
local limit = 30000
|
||||||
|
local turn = get_turn()
|
||||||
|
local sel
|
||||||
|
if #players > 0 then
|
||||||
|
read_game(turn)
|
||||||
|
eressea.read_game(("%d.dat"):format(turn))
|
||||||
|
sel = p.select(regions(), limit)
|
||||||
|
if #sel > 0 then
|
||||||
|
local best = dump_selection(sel)
|
||||||
|
print("finest region, " .. best.score .. " points: " .. tostring(best.r))
|
||||||
|
end
|
||||||
|
end
|
||||||
math.randomseed(os.time())
|
math.randomseed(os.time())
|
||||||
|
|
||||||
print(#sel, limit)
|
local newbs = {}
|
||||||
|
|
||||||
players = {
|
|
||||||
{ email = "noreply@mailinator.com", race = "dwarf", lang = "de" }
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, p in ipairs(players) do
|
for _, p in ipairs(players) do
|
||||||
local index = math.random(#sel)
|
local index = math.random(#sel)
|
||||||
local start = nil
|
local start = nil
|
||||||
while not start or start.units() do
|
while not start or start.units() do
|
||||||
start = sel[index]
|
start = sel[index]
|
||||||
end
|
end
|
||||||
|
local dupe = false
|
||||||
|
for f in factions() do
|
||||||
|
if f.email==p.email then
|
||||||
|
print("seed: duplicate email " .. p.email .. " already used by faction " .. tostring(f))
|
||||||
|
dupe = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not dupe then
|
||||||
f = seed(start, p.email, p.race or "human", p.lang or "de")
|
f = seed(start, p.email, p.race or "human", p.lang or "de")
|
||||||
print(f, start)
|
print("new faction ".. tostring(f) .. " starts in ".. tostring(start))
|
||||||
init_reports()
|
table.insert(newbs, f)
|
||||||
write_report(f)
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if #newbs > 0 then
|
||||||
|
init_reports()
|
||||||
|
for _, f in ipairs(newbs) do
|
||||||
|
write_report(f)
|
||||||
|
end
|
||||||
eressea.write_game(("%d.dat.new"):format(turn))
|
eressea.write_game(("%d.dat.new"):format(turn))
|
||||||
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue