What you learn today
- Separate ores, ice and the rest
- Counter per class
- Report jams
The sorting week ends with the plant that should stand in front of every smelter: everything that comes out of drill and centrifuge ends up in the right place – and you know how much of what.
The plant
| Device | Prefab | Name |
|---|---|---|
| sorter in front of the smelter | StructureSorter | “Weiche1” |
| sorter in front of the ice crusher | StructureSorter | “Weiche2” |
| three LED displays | StructureConsoleLED5 | “Erze”, “Eis”, “Rest” |
| wall light | StructureWallLight | “Stau” |
“Weiche1” sends real ores to output 2 to the smelter, everything else to output 1 on to “Weiche2”. “Weiche2” sends ice to output 2 to the ice crusher, the rest to output 1 into storage.
Counting every item exactly once
The sorter sets Output to −1 after passing an item on – and also after every write of Mode. That is why the chip only writes Mode when it is not already 2. If Output is still at 0 or 1, a decision is waiting to be carried out – then the chip must not see and count the item a second time. That is why it only decides and counts while Output is −1:
lbn tmp SORTER HASH("Weiche1") Output Average
sgez tmp tmp
bnez tmp diverter2
The counters simply add the result of the comparison: add ores ores target counts 1 for an ore, 0 for everything else.
Reporting a jam
A decision that is not carried out for a long time means: the output is full. The same counter trick as for the jam at the output slot measures how long Output has been at 0 or 1. Above 20 ticks “Stau” lights up. The light also shows when “Weiche1” is unreachable.
Milestones
- Ores at diverter 1 to the smelter, special cases onwards
- Ice at diverter 2 to the ice crusher, rest into storage
- Counters per class
- An item is not counted twice
- Report a jam and a missing diverter
The counters live in registers and start at 0 after every restart of the chip. For counts across restarts the value belongs in a logic memory – or you read the devices' ExportCount, as next week.
Project task
Task
Build the sorting plant following the description. The chip only writes logic mode when a diverter is not already at Mode 2 – and then does not decide at it in this pass, because the write only clears Output after the tick. At each diverter, decisions and counts only happen when Output is −1 and an item lies in the input slot. “Erze”, “Eis” and “Rest” show the counters. “Stau” lights up when at a diverter Output stays at 0 or 1 for more than 20 ticks or “Weiche1” is missing.
Milestones
- Milestone 1: ores to the smelter
- Milestone 2: ice and rest
- Milestone 3: counters per class
- Milestone 4: no double counting
- Milestone 5: jam and missing diverter
Hints
Hint 1
Per diverter first check Mode: not LOGIC, then write it once and jump to the next diverter. Then read Output, sgez, jam counter with add/mul, jump on when Output is set.
Hint 2
Diverter 1 as yesterday, plus add ores ores target. Diverter 2: add ice ice target, seqz tmp target, add rest rest tmp.
Hint 3
Jam: max tmp jam1 jam2, sgt with JAM, plus snan on the Mode of diverter 1.
Quiz
2 questions. You pass from 60 % – the server does the grading.
Complete the day
- Passed all milestones of the project
- Passed the quiz with at least 60 %
Without an account progress is saved in this browser only.
Report a mistake in this lesson
Please sign in to report. Sign in