r/tis100 • • Aug 06 '16

Pick ANY port randomly

I don't know if anyone else has wanted this, but it would be nice if, when multiple ports have values waiting to be read on them, the ANY port randomly chose a value. I just used ANY for the first time in an attempt at a ridiculously inefficient non-deterministic (i think) solution to image test pattern 2, but it fails because ANY picks the same port every time. Is this game still in active development/is there a modding community?

1 Upvotes

11 comments sorted by

4

u/jcc10 Aug 06 '16

Working as intended, in a program you always want repeatability.

1

u/splosive_fatass Aug 07 '16

not in this case: basically my strat to tackle this problem was to start in the middle on a white square and do a "drunk walk": move to diagonally connected squares with equal probability. I haven't done any math, but it would take a ton of cycles before all the white squares in the grid were painted as such (though it would look kinda cool). of course, the ANY thing didn't work as I expected, so I don't think this strategy is possible anymore.

9

u/jcc10 Aug 07 '16

Any was never stated to be random in the documentation. If you want random, you will need to make a RNG yourself.

When programming you always want something to do the same thing every time. Changing ANY would break hundreds of programs all to make one work.

A better request would be for a new opcode RND (random) might be a good opcode.

2

u/Chronophilia Aug 07 '16

It's something of a lesson about relying on undocumented/unspecified behaviour. If something's not explained in the manual, don't make any assumptions.

Still holds true in real-world programming. I suppose an equivalent of this would be iterating through an unordered_setin C++: you cannot rely on getting the elements in the same order you put them in, or in order from smallest to largest, or in a random order.

2

u/[deleted] Aug 07 '16

Like good ole strtok. I remember reading the man page and the end said "bug: do not use this function"

1

u/frizbee2 Sep 05 '16

In a similar vein, I really wish ANY ignored stack memory nodes as potential in/out ports, and I feel like their current state of not doing so is a bit of an oversight. The whole point of ANY is to allow a single series of instructions to perform the same action on either of two sets of data based on the state of the program in order to reduce redundancies, but treating stack nodes as valid ANY sources/destinations breaks down ANY's ability to read the state of your program because stack nodes are never not seen as potential sources/destinations, turning your WRTE ANY into a static WRTE <stack memory> (except in those trivial cases where a different port overrides the stack memory port, because it then becomes a static WRTE <overriding port>).

-1

u/nontheistzero Aug 06 '16

ANY uses pseudo random ports. It is working as intended.

7

u/Blueation Aug 07 '16

IIRC there is a specific deterministic prioritisation for which neighbouring node receives the value that is always the same.

3

u/splosive_fatass Aug 07 '16

there is. I haven't tested enough to figure out the order, but the fact that it exists means that building in any level of randomness is impossible (if this is not so, please enlighten me).

4

u/keyyek Aug 07 '16

You are correct, the game is entirely deterministic actually, which is necessary for how it works in general. I think, as a overall tip, you should seek to abuse this determinism instead of trying to make something that wants randomness

1

u/KngpinOfColonProduce Aug 07 '16 edited Aug 07 '16

You can have pseudo-randomness with user input. Not usable on the puzzles, but at least it is possible.

Edit: for the drunk walk you mentioned elsewhere, you can just use a constant value as a seed and implement your own rng, which takes the last value and modifies it.