SmallTown1AI - Germanunkol/trAInsported GitHub Wiki

Simple AI for the challenge-map SmallTown1.

-- SmallTown1_AI-2.lua
-- AI for trAInsported, challenge-map "SmallTown1".

dgb=0

function ai.init()
	AI="SmallTown1_AI-2  2014-02-15  by HaJo Gurt"
	print("AI:" .. AI)
	buyTrain(1,1, 'E')
	transported=0
end

function ai.enoughMoney()
	print("Yay")
	buyTrain(1,1,"E")		-- not possible on SmallTown1
end


function ai.foundPassengers(train,passengers)
-- pick up first passenger on list
	print( train.name, "found P." .. #passengers )
	return passengers[1]
end

function ai.foundDestination(train)
	dropPassenger(train)
	transported=transported+1
	print( train.name .. " dropped off passenger", transported )
end


function ai.chooseDirection(train,dirs)
-- When train is empty, move "W"est to get more passengers.
-- When train is full, move "E"ast to the destination
	if train.passenger == nil then
		if dgb>0 then  print(train.name, "empty --> W")  end
		return "W"
	else
		if dgb>0 then  print(train.name, ":", train.passenger.name, "--> E")  end
		return "E"
	end
end

--.