Posted 16 May 2013 - 09:26 PM
Hello! This is my project thread for all my computercraft programs for my upcoming custom map "Technical Training." The goal of the map is to simulate a model railroad, and give the player an assignment to complete as a train engineer. I'm using Traincraft, but I believe the majority of work for this map will be on the computer programs.
So my plan is to have a master computer at spawn and the central railyard which will give players their assignment. Players will push a button (either in game, or on a touchscreen) and receive a printout of their job. My current conundrum is how to assign which cars for the job number. I figured I'd use global variables and Rednet to make the job easier.
Global variables:
Stops - Table containing all locations which could possibly have cars.
StopName - Table containing all cars currently in the local railyard.
My plan is to identify cars by what they're carrying. Each car will only have 1 type of resource. Cars in the table will be stored as "Oak Logs" , "White Wool" , "Advanced Rails" , "Milk" , etc. The program would pick 5 random strings from "Stops" and then pick so many cars from each "StopName" to be picked up and dropped off at other Stops. I don't know exactly how to implement this, but I think it would be the most efficient way to do it, if I used global variables like that. I'm open to other methods, currently I'm still in the brainstorming and planning phases of the project.
As I said, this is my project thread. I don't have any code yet, because I'm still trying to figure out what method would be the easiest to implement and most efficient. I will be updating this post with code as I write it. I'll try to include as many comments as I can to help you guys understand what I'm trying to do. The only question I currently have is: Does anyone know how real life programs for model railroading generate task lists like this? I know they exist because I've been to a big model railroad several times and they have a whole computer system which generates and prints the jobs and tracks all car and engine locations.
I'm sorry if this is in the wrong spot. I put it in Ask a Pro because I know I'll need help with this project later on, and I figured it would be more efficient to keep it all in one thread. I'm really excited about this project and I'm looking forward to working on it! All help and constructive criticism is appreciated and encouraged! :lol:/>
Code:
Pseudo Code
5/18 6:15pm
So my plan is to have a master computer at spawn and the central railyard which will give players their assignment. Players will push a button (either in game, or on a touchscreen) and receive a printout of their job. My current conundrum is how to assign which cars for the job number. I figured I'd use global variables and Rednet to make the job easier.
Global variables:
Stops - Table containing all locations which could possibly have cars.
StopName - Table containing all cars currently in the local railyard.
My plan is to identify cars by what they're carrying. Each car will only have 1 type of resource. Cars in the table will be stored as "Oak Logs" , "White Wool" , "Advanced Rails" , "Milk" , etc. The program would pick 5 random strings from "Stops" and then pick so many cars from each "StopName" to be picked up and dropped off at other Stops. I don't know exactly how to implement this, but I think it would be the most efficient way to do it, if I used global variables like that. I'm open to other methods, currently I'm still in the brainstorming and planning phases of the project.
As I said, this is my project thread.
Code:
Pseudo Code
Spoiler
function Assignment()
Pick 0 to 3 random from Stop1 for Stop2
Pick 0 to 3 random from Stop1 for Stop3
Pick 0 to 3 random from Stop1 for Stop4
Pick 0 to 3 random from Stop1 for Stop5
Pick 0 to 4 random from Stop2 for Stop3
Pick 0 to 3 random from Stop2 for Stop4
Pick 0 to 2 random from Stop2 for Stop5
Pick 0 to 1 random from Stop2 for Stop6
Pick 0 to 3 random from Stop3 for Stop4
Pick 0 to 2 random from Stop3 for Stop5
Pick 0 to 1 random from Stop3 for Stop6
Pick 0 to 2 random from Stop4 for Stop5
Pick 0 to 1 random from Stop4 for Stop6
Print Results
Update Incoming and Outgoing Lists for each stop as necessary
end
5/18 6:15pm
Spoiler
-- Technical Training
-- Description: This program is for use with the Technical Training custom map. This is the main program for
-- use in the mainframe computer system.
-- Author: Ben Crews (Czarified)
-- Variable Definition
StopNames = { "Stop1" , "Stop2" , "Stop3" , "Stop4" , "Stop5" , "Stop6" , "Stop7" }
Stops = { Stop1 , Stop2 , Stop3 , Stop4 , Stop5 , Stop6 , Stop7 }
Stop1 = { in = {} , available = {} , out = {} } -- Currently all these tables are equal and contain nothing,
Stop2 = { in = {} , available = {} , out = {} } -- but they will change as the program is completed.
Stop3 = { in = {} , available = {} , out = {} }
Stop4 = { in = {} , available = {} , out = {} }
Stop5 = { in = {} , available = {} , out = {} }
Stop6 = { in = {} , available = {} , out = {} }
Stop7 = { in = {} , available = {} , out = {} }
--Functions
function assignment() -- Determines the assignment given for completion.
local StopsLeft = 5 -- # of Stops assigned per run.
local Temp = Stops -- Creation of temporary Stops list copy for modification.
local Jobstop = {} -- List of Stops for job to be assigned.
for i = 1, StopsLeft do
val = math.random(1, #Temp) -- Computes random index value from list of locations.
local Jobstop[i] = table.remove(Temp, val) -- Removes indexed value from Temp and places in Jobstop list.
end
for i = 1, StopsLeft do
table.insert( Stop1[3].out[#Stop1[2].out + 1], table.remove(Stop1[2], math.random(0,4) ) -- Will this work properly and can it be automated for each value generated in Jobstop?
end
end
function reward() -- Determines reward received when completed.
end
function checkcomplete() -- Checks for completion of required task.
end
-- Main Program
Edited on 19 May 2013 - 05:59 PM