The Castle Doctrine Forums

Discuss the massively-multiplayer home defense game.

You are not logged in.

#1 2013-11-11 06:23:28

joshwithguitar
Member
Registered: 2013-07-28
Posts: 538

Electronics Tutorial?

How is progress going with electronics tutorials? I was sure there were some in the works but I can't find any and there hasn't been one posted on the wiki yet.

How electronics work is not at all clear from the UI and so I think it is important that we get one up.

In the mean time, I've put together a castledraft house to act as a visual guide to electronics:
http://castledraft.com/editor/2sP62y

For those new to electronics in TCD what each row in the above example represents is the steps that the game goes through in order to determine the state of the different electronic configurations after they are powered.

To figure out what is powered and what isn't the game runs through numerous "cycles" until the state of the electronics either stabilises or repeats itself. This process occurs every time the player moves or uses a tool. The state of voltage triggered switches and  voltage triggered inverted switches (VTIS) in each cycle is determined by whether they were powered from the tile above during the previous cycle. The state of each voltage switch at the start is determined by where they had settled the previous "turn".

In the examples above the leftmost circuit of each column represents the initial state of a circuit before a pressure switch in turned on. The circuits to the right represent each cycle after the button is pressed until it repeats a state. The to the right is shown the final state as it will appear to the player.

Offline

#2 2013-11-11 10:08:46

jasonrohrer
Administrator
Registered: 2013-04-01
Posts: 1,231

Re: Electronics Tutorial?

Thanks for taking the lead here, Josh.  You certainly are qualified!

Offline

#3 2013-11-13 15:36:20

ukuko
Member
Registered: 2013-04-06
Posts: 333

Re: Electronics Tutorial?

Nice one, Josh! I'm glad those 'on' wires were finally of use to someone.

Offline

#4 2013-11-13 16:03:00

iceman
Member
Registered: 2013-11-09
Posts: 687
Website

Re: Electronics Tutorial?

This is more logic based than electronics based, but here are the basic boolean logic operators, for anyone who needs them for something.

http://castledraft.com/editor/IKQ3dU

The order is:
OR
AND
NOT
EXCLUSIVE OR

I'm pretty sure implication is easier to do by breaking it into NOT and OR, so I'm not including it.


Fortress Theory Mod - New objects, tools, and paintings!

I keep dying of a natural cause - Stupidity
The biggest thing that Castle Doctrine has taught me is that the price of your house is proportional to the stupidity of the mistake that kills you.

Offline

#5 2013-11-13 16:22:54

joshwithguitar
Member
Registered: 2013-07-28
Posts: 538

Re: Electronics Tutorial?

ukuko wrote:

Nice one, Josh! I'm glad those 'on' wires were finally of use to someone.

Thanks for the tripped voltage switches as well!

iceman: it seems that your AND can be simplified: http://castledraft.com/editor/ue8rVt
I can understand why you might want to use voltage switches though smile.

Offline

#6 2013-11-13 16:42:00

iceman
Member
Registered: 2013-11-09
Posts: 687
Website

Re: Electronics Tutorial?

Good catch!  I didn't think of that, but with the voltage switches you have the option of having multiple combinations.

Last edited by iceman (2013-11-13 16:43:42)


Fortress Theory Mod - New objects, tools, and paintings!

I keep dying of a natural cause - Stupidity
The biggest thing that Castle Doctrine has taught me is that the price of your house is proportional to the stupidity of the mistake that kills you.

Offline

#7 2013-11-15 21:35:49

iceman
Member
Registered: 2013-11-09
Posts: 687
Website

Re: Electronics Tutorial?

I realized that my OR circuit also has an issue in combining with other gates.  If you, say, want to test both (X OR Y) and (X AND Y) for some reason, using that form of the or gate will mean if X is on, Y will appear to be on as well(since their wires are directly connected), so the AND will pass as true (regardless of what Y is).  I've changed that Castle Draft to have the most basic ones on the left side, then the circuits that work with multiple circuits on the right side.

http://castledraft.com/editor/bEeaCm

Of course, after I realized this, it didn't really register until I was connecting the wires to the lights on my attempt at a circuit to have a number show up (and increase by 1 each step).

original.jpg

Everything up to that point worked, suprisingly... if you put lights at that bottom right diagonal, one light would light up at a time, in order.  I'm actually really surprised I was able to fit all of that in a house - as you can see, it just barely fit.  If someone want's a repeating circuit with period 8 and doesn't care about having half of their house, feel free to use this wink.  This, along with my attempt at a button counter (see how many buttons are pressed - again, pretty much completely useless, but interesting all the same), have both been killed because I keep thinking current flows one way =P.  If only we had a one-way current tile =P


Fortress Theory Mod - New objects, tools, and paintings!

I keep dying of a natural cause - Stupidity
The biggest thing that Castle Doctrine has taught me is that the price of your house is proportional to the stupidity of the mistake that kills you.

Offline

#8 2013-11-15 23:28:53

ukuko
Member
Registered: 2013-04-06
Posts: 333

Re: Electronics Tutorial?

You make your own one way voltage tile:

one-way-voltage.png

Nothing on the lower half of the circuit can travel back up and interfere with the higher part.

Offline

#9 2013-11-18 15:26:11

jasonrohrer
Administrator
Registered: 2013-04-01
Posts: 1,231

Re: Electronics Tutorial?

Yeah, I was thinking about adding a "diode" tile that only passes power in one direction to help with this, but I think it can generally be accomplished with the existing voltage-triggered switches.

Offline

#10 2013-11-18 16:33:52

iceman
Member
Registered: 2013-11-09
Posts: 687
Website

Re: Electronics Tutorial?

jasonrohrer wrote:

Yeah, I was thinking about adding a "diode" tile that only passes power in one direction to help with this, but I think it can generally be accomplished with the existing voltage-triggered switches.

They just take up so much room :'(


Fortress Theory Mod - New objects, tools, and paintings!

I keep dying of a natural cause - Stupidity
The biggest thing that Castle Doctrine has taught me is that the price of your house is proportional to the stupidity of the mistake that kills you.

Offline

#11 2013-11-18 17:44:41

jasonrohrer
Administrator
Registered: 2013-04-01
Posts: 1,231

Re: Electronics Tutorial?

Well, that's the point, really....

I mean, the system already clearly allows for NP-hard stuff to be built, even with full visibility.  Partial visibility makes it even worse... combo locks are a great example of this:  a 10-bit lock effectively requires 2^10 guesses to guarantee that you find the solution (or 2^9 guesses on average).

The only thing that de-tooths NP hard problems is a limit on the size of the problem space.  If something is truly NP-hard, it means that for a problem of size K, there is no algorithm that can solve the problem in polynomial time... meaning polynomial in K.  You should be able to scale K up to any value and still have sensible problem instances (a salesman who must visit K cities, where K can be 10 cities or 10,000 cities).  If K can never be bigger than a certain value, we're not really playing by the NP-hard rules.

And in our case, K might be something like 32, which is fixed the dimension of the map.  It's never bigger than that.

And the difficulty of squeezing electronics into that 32x32 space makes our prospects even better.  Yes, you can build full-visibility problems in The Castle Doctrine that are instances of truly NP-hard problems, but these constraints limit you only to the smaller, more trivial instances of those problems.


But in general, the problem instance in TCD is, "Given this house map, what is the optimally cheapest tool set and movement path that will get the robber to the vault without dying?"  I'm pretty sure that for NxN maps, that is an NP-hard problem (no polynomial time way to solve it, polynomial in N).  Obviously, we know part of the answer already:  the cheapest toolset is alwasy $0, because the owner provided us with that 0-tool solution (though this is not the case for reaching the wife, or dealing with a house that has already been partially broken).


Summary:  it's good that building complex electronics is quite limited by space constraints!

Offline

#12 2013-12-01 18:59:41

Hippasus
Member
Registered: 2013-09-03
Posts: 32

Re: Electronics Tutorial?

For anyone who wants a repeating circuit with period 8 and does care about it taking up half the house this might be a better option. No offence iceman! smile
Electronics!

Offline

#13 2013-12-02 08:43:52

jasonrohrer
Administrator
Registered: 2013-04-01
Posts: 1,231

Re: Electronics Tutorial?

Amazing feeling when a game that I make far outstrips my own comprehension.

Offline

#14 2014-01-17 16:42:52

arakira
Member
Registered: 2013-12-01
Posts: 176

Re: Electronics Tutorial?

Can anyone please explain how the final state is computed if there is a loop in the electronics sub-steps sequence? I read somewhere on the forum that it is about a "lowest state" of the components, but I don't understand exactly what it is.
Also, I don't understand Josh's last example from http://castledraft.com/editor/2sP62y (the last 6 diagrams, 2 bottom rows). What is the order in this sequence, row by row or clockwise? And why the switch is off, then on, then off again...
The current trend seems to be a loop of electric floors which you can't disconnect because you get instantly fried, which is very counter-intuitive (for example in Morel's house).
In order to survive in such houses, you have to know how these sub-steps arecomputed, that means, you have to know how the algorithm is implemented. This electronic stuff is very interesting and allows some funny tricks, but I imagine this can be frustrating for new players.

Offline

#15 2014-01-17 17:00:28

colorfusion
Member
Registered: 2013-04-02
Posts: 537

Re: Electronics Tutorial?

arakira wrote:

Can anyone please explain how the final state is computed if there is a loop in the electronics sub-steps sequence? I read somewhere on the forum that it is about a "lowest state" of the components, but I don't understand exactly what it is.
Also, I don't understand Josh's last example from http://castledraft.com/editor/2sP62y (the last 6 diagrams, 2 bottom rows). What is the order in this sequence, row by row or clockwise? And why the switch is off, then on, then off again...
The current trend seems to be a loop of electric floors which you can't disconnect because you get instantly fried, which is very counter-intuitive (for example in Morel's house).
In order to survive in such houses, you have to know how these sub-steps arecomputed, that means, you have to know how the algorithm is implemented. This electronic stuff is very interesting and allows some funny tricks, but I imagine this can be frustrating for new players.

If it loops, each individual tile goes to the lowest state that it was seen in. This means if a component was switching between powered and unpowered, it will end up unpowered. If a component is part of a looping circuit but is only ever powered then it will stay powered.

The lowest example is a toggle. If you give it a pulse while it is off, then it will turn on. If you give it a pulse when it is on, then it will turn off. I think it's read row by row, the upper row showing the button being pressed while the latch is powered, and the lower row showing the button being pressed while the latch is unpowered.

Last edited by colorfusion (2014-01-17 17:04:49)

Offline

#16 2014-01-17 18:31:02

jasonrohrer
Administrator
Registered: 2013-04-01
Posts: 1,231

Re: Electronics Tutorial?

By "lowest state," we mean the state number in the gameElements/houseObjects folder for that object.

Colorfusion is correct that for all objects, their unpowered state happens to be state 0, which is the lowest state.  Thus, somewhere in the loop, if the object hits state 0, it will be set to 0 once the loop is detected and dealt with.

Offline

#17 2014-01-18 06:20:33

arakira
Member
Registered: 2013-12-01
Posts: 176

Re: Electronics Tutorial?

OK, I see, thanks. I guess you are you looking for looping states locally, in each whole circuitry? (where "circuitry" is a maximum cluster of connected electronic devices)

Offline

#18 2014-01-20 09:27:40

jasonrohrer
Administrator
Registered: 2013-04-01
Posts: 1,231

Re: Electronics Tutorial?

No, looping states globally, actually, for the whole map.

The game engine actually takes a hash of states all across the map and watches for the map to return to a place where a hash reoccurs.

Offline

#19 2014-01-22 19:35:59

Blip
Member
Registered: 2013-05-07
Posts: 505

Re: Electronics Tutorial?

You know, I used to think I was good at TCD electronics. Then I leave for a couple months and you guys come up with THIS? I have some catching up to do. tongue


Current life: Not dead, but I have no clue who I am
The Life and Times of Christopher Alvin Harris
Record: 149 Paintings!

Offline

#20 2014-01-23 11:50:57

jasonrohrer
Administrator
Registered: 2013-04-01
Posts: 1,231

Re: Electronics Tutorial?

Yeah... some people who play this game are insanely smart!

Offline

#21 2014-01-23 15:19:20

nathan
Member
From: A ditch somewhere
Registered: 2013-06-15
Posts: 61

Re: Electronics Tutorial?

jasonrohrer wrote:

Yeah... some people who play this game are insanely smart!

I am not one of them.


"I just robbed Mr. Rogers." -Ludicrosity "The wood is my desk, and I'm knocking it with my head." -Blip
"I'd rather pack 25 meats than 1 crowbar if you know what I mean..." -Jabloko
"This is one of the most disturbed things I have seen in quite a while. I blame global warming." -bey bey
"that seems like more resources than I'm willing to put into having my kids killed." -cbenny

Offline

#22 2014-01-23 22:02:43

zed
Member
Registered: 2013-04-16
Posts: 161

Re: Electronics Tutorial?

jasonrohrer:
> If something is truly NP-hard, it means that for a problem of size K, there
> is no algorithm that can solve the problem in polynomial time...

Don't suppose you have a proof of that? wink

Offline

#23 2014-01-24 10:24:17

Blip
Member
Registered: 2013-05-07
Posts: 505

Re: Electronics Tutorial?

That isn't provable, zed; however, there are some other claims we can make about the Castle Doctrine specifically.  Now, sorry if I make a mistake, I mostly do electronics and not computability theory:

There must, by the nature of the game, be some maximum difficulty problem (i.e. house) H, such that no problem designable within the house space can be more difficult than H. H may or may not be NP-Hard.
Because H is the most difficult possible problem, it can be assumed from gameplay that there is essentially a single non-tool solution. A non-deterministic Turing machine would then be able to produce a computation tree based on its transition relation (in this case, moves) of left, right, up, and down with both input and output being the position of the player character. Because the house space is finite, there is a upper bound on the size of these trees. (Note that this is under the assumption that moving up and down repeatedly eventually stops being useful, as any pets would have pressed whatever buttons they needed to already.)

As a matter of fact, these trees would obviously be largest for an empty house with the vault in a back corner, at it has the highest possibility for movement. (Again, note that an algorithm would not know if there's a magic dance in the house, and some branches of its computation tree would feature pointless dancing). This problem, of simply finding the vault in an empty house, is clearly in only NP. (This takes some math to prove, but I think I did it right. Again, I not a computability theorist. tongue) As it would take the more time than solving problem H, H must also be solvable in polynomial time by the same non-detrministric Turing machine, and thus:
H is in NP.

Now H could still be NP-hard; it would then be NP-complete. However, either way it can still be solved in polynomial time. It's still really hard though, especially for us stupid humans and our stupid ways; also, a non-deterministic turing machine wouldn't like it when one of its computability tree branches ends in death and all the others get chills.


Current life: Not dead, but I have no clue who I am
The Life and Times of Christopher Alvin Harris
Record: 149 Paintings!

Offline

#24 2014-01-24 13:23:19

SnakeAes
Member
From: SoCal, USA
Registered: 2014-01-23
Posts: 41

Re: Electronics Tutorial?

I understand probably about 5% of this. And that prospect to me is exciting, but I'm not sure how to really grasp the material. Is there a more gradual guide than this for those of us who are less electronically / computationally knowledgeable?


---
勝兵先勝而後求戰,敗兵先戰而後求勝。
"Victorious warriors win first, then go to war; defeated warriors go to war first, then seek to win."
- Sun Tzu, The Art of War

Offline

#25 2014-01-24 23:40:16

Cabnormal
Member
Registered: 2014-01-23
Posts: 18

Re: Electronics Tutorial?

I just killed myself in a self test and was wondering if there is some kind of delay built into a specific tile or wire type? Seems that I must have changed the wiring around so that power looped back around to activate four steps later than I expected. Didn't use any of the voltage activated or deactivated toggles. Had the picture of a tree in a desert if anyone saw the house.

Offline

Board footer

Powered by FluxBB 1.5.8