The Castle Doctrine Forums

Discuss the massively-multiplayer home defense game.

You are not logged in.

#1 2013-05-30 20:22:10

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

Inverted switch bug

Bug, or logic peculiarity?

If you chain an inverted switch into another and feed the first one back into itself, the second one will behave as if it is tripped, yet it doesn't show the tripped sprite and an indicator light on that part of the circuit doesn't receive any power.

inverted-switch-bug.png

Offline

#2 2013-05-30 21:23:56

dalleck
Member
Registered: 2013-04-13
Posts: 250

Re: Inverted switch bug

Mind.  Blown.

I swear that little inverted switch is wigging out there.


The rich aren't safe. Nobody is safe. -jere                   ...but the smell wafts out from the pit, obviously. - Jason Rohrer

And the more dickish they are, the more I feel like beating a house to destruction after finally figuring it out. -bey bey

Offline

#3 2013-05-31 01:36:13

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

Re: Inverted switch bug

That's no bug, that's just how electronics works in this game wink

If you think of inverted switches as "not gates", then wiring one into itself is forming a contradiction - the output is on if and only if it is not on. Just as with real electricity and transistors, this leads to strange and cool effects!

Here's how to make sense of it: if you think it through logically, you'll see that the power should be oscillating between two states. In one state the lights are powered, in the other not. The way the game is coded, tiles like lights which need power to activate are only activated if they get continuous, non-oscillating power.

Offline

#4 2013-05-31 04:32:55

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

Re: Inverted switch bug

Ah, yes. I thought as much. My confusion was mainly concerning the lack of visual feedback, but I guess there is no 'oscillation' sprite. smile

Offline

#5 2013-05-31 06:22:36

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

Re: Inverted switch bug

From the code:

.
        // make sure that all looping elements "settle down" into a 
        // consistent state (otherwise, we see various flip-flops due
        // to propagation times elsewhere in the map)
        
        // in case of looping, all elements involved in the loop settle
        // down into the lowest-seen state number that they encounter 
        // during execution of the loop

So, when a loop is detected in power transmission (state keeps changing with each propagation step, but keeps returning to the same house-wide state somewhere in there over and over), then the transmission simulation is run a few more times through the loop, and all elements are watched for their lowest-seen state number during the looping process.  That is the state they are set to, individually.  So, in this case, the inverted switches here are set to their "untripped" state, and the wires and things on the other side of them are set to their "unpowered" state (those happen to be their lowest state numbers as seen through the looping process).

Yeah, it looks inconsistent.  But the point is that ANY visualization of this would look inconsistent.  Let's' say the light past the north-most inverted voltage-triggered switch (IVTS) was ON instead.  Well, that would mean that there was power on that wire that loops back, which would mean the north-most IVTS should be tripped (so that part would be inconsistent looking).  And if we tripped the switch visually AND had the light on, that would look inconsistent too (how is that light and IVTS getting power?).  And if we tripped the switch visually and had the light off (how is that IVTS getting tripped)?

So, the code says:  if we have to display something inconsistent, at least make it predictable (everything drops down into its lowest-seen state in the loop... which is always its powered-off state).

I agree that this stuff is REALLY confusing.  Then again, low-level electronics in real life is quite a bit more confusing than this....

Something much less confusing is using a non-inverted VTS to make a simple set-and-hold flip-flop.  This doesn't involve any inconsistencies.

I also realize that some people (ahem, Mr. Zed) are using some of these "nuances" to make really hard houses that have remained unbroken for days.  I'm pretty sure that the only way to make progress in cracking such houses is to replicate pieces of the circuitry in your own house and play around with it to figure out how it works.

Offline

#6 2013-05-31 09:42:35

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

Re: Inverted switch bug

Yes, this is in my opinion one of the best features of the game. It allows for some real richness, especially when combined with pets.

It would be nice if the mechanics were more easily discoverable. I recall finding it quite mysterious until I read the source code.

How about animating the switches each turn, so they flash in turn through all states they pass through during propagation, showing the eventual loop twice? That should be enough to give the idea. It would have to be fast enough not to be annoying, and preferably configurable.

Anyway, someone should solve my house. It shouldn't be hard once you grok the ideas of this thread.

Offline

#7 2013-05-31 12:33:17

jere
Member
Registered: 2013-05-31
Posts: 540

Re: Inverted switch bug

Anyway, someone should solve my house. It shouldn't be hard once you grok the ideas of this thread.

Are you the guy with all the money?

I painstakingly recreated that house (the bottom portion) and then realized memory was involved. Well, damn. That's a little bit more than I was expecting.


Golden Krone Hotel - a vampire roguelike

Offline

#8 2013-05-31 12:46:46

Matrix
Member
Registered: 2013-04-06
Posts: 137

Re: Inverted switch bug

jasonrohrer wrote:

Yeah, it looks inconsistent.  But the point is that ANY visualization of this would look inconsistent.

I understand that maybe animating it is not viable, but having a third state and a special sprite for such a state would be consistent. After all, the switch is in a new (unstable) state. Since the 3rd sprite would be a static sprite it could be used on the blueprints as well, if showing unstable IVTS on the blueprints is desired.

Offline

#9 2013-05-31 13:09:45

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

Re: Inverted switch bug

jere wrote:

Anyway, someone should solve my house. It shouldn't be hard once you grok the ideas of this thread.

Are you the guy with all the money?

I painstakingly recreated that house (the bottom portion) and then realized memory was involved. Well, damn. That's a little bit more than I was expecting.

Sounds like you're nearly there!

Offline

#10 2013-05-31 13:16:14

jere
Member
Registered: 2013-05-31
Posts: 540

Re: Inverted switch bug

There!

It's not about the money. It's about sending a message.

That was pretty damn difficult though. I almost gave up several times. And I can't claim to have understood most of the wiring. It was a lot of trial and error.

Last edited by jere (2013-05-31 13:20:48)


Golden Krone Hotel - a vampire roguelike

Offline

#11 2013-05-31 14:01:31

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

Re: Inverted switch bug

Oh... good to see a top house fall, but that wasn't mine! Mine's the one with a load of trapdoors just in front of the entrance, and around 140 skulls.

Offline

#12 2013-05-31 14:22:28

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

Re: Inverted switch bug

I know the one Jere was talking about.  That was a good one!

I'm sure someone will get you, Zed.  And you have no family left as a parachute...

Offline

#13 2013-05-31 14:32:46

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

Re: Inverted switch bug

As a matter of fact, I just completed my new wiring puzzle. It takes up a massive amount of space, but by using some of these electronic idiosyncrasies, like the "sticky" switch made of a voltage and an inverted voltage switch, I built a three-bit lock controlled by only two buttons. I was going to add more bits total, but I built the first three too high up and didn't have room to expand while also letting my family be protected. My next house I'll probably go for a six-bit, three button lock. Just as a tip for robbers, it featured a press counter on one of the switches, my favorite new invention that allows one switch to have multiple outputs depending on the amount of times it is stepped on. Of course, it's an absolutely massive setup, but a cool step forward in CD electronics. I'll probably post the design for the step counter (not the rest of the house, though) once my current house gets robbed.


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

Offline

#14 2013-05-31 15:15:24

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

Re: Inverted switch bug

Amazing!

Offline

#15 2013-05-31 19:14:39

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

Re: Inverted switch bug

jere wrote:

That was pretty damn difficult though. I almost gave up several times. And I can't claim to have understood most of the wiring. It was a lot of trial and error.

I see I have been toppled. Congrats. It gave me enough of a headache completing my trial run.

Offline

Board footer

Powered by FluxBB 1.5.8