Page 1 of 1

making code wait on Input

PostPosted: 04 Jul 2011, 14:25
by slapshot5
Hi all,

I know I've run across this before, but don't remember if I solved it.

Basically, I have:

Code: Select all
public void resolve() {
player.discard();
player.drawCard();
}
What needs to happen is the discard happens, then the draw.

What actually happens is showMessage() for discard, card is drawn, now I can Input my discard (and discard the card that was drawn, which is incorrect).

Do we have a way to do this correctly?

Thanks,
slapshot5

Re: making code wait on Input

PostPosted: 04 Jul 2011, 14:37
by friarsol
I don't believe this exists currently. It would be great if it did, because there are definitely some other timing issues related to anything that resolves with a Custom Input.

Re: making code wait on Input

PostPosted: 04 Jul 2011, 15:28
by Hellfish
As far as I understand the Input system, there is no way to do this save for modifying the Input base class to contain a Command object that can be run when the Input's stop() method is called.

FAKE EDIT: I don't think you could mod InputControl to do such a thing, but it's possible.

Re: making code wait on Input

PostPosted: 07 Jul 2011, 14:35
by Braids
slapshot5 wrote:. . . What needs to happen is the discard happens, then the draw . . . Do we have a way to do this correctly?
my understanding of the code is shaky, but maybe you could consider one of these?
  • extend the Input for discarding a card so that, during its custom resolution method {selectCard i think}, call super's version of selectCard, then draw the card.
  • use the MagicStack. push a draw action/trigger/whatever, then immediately push the discard action. this is fairly elegant, but it violates atomicity/inseverability/indivisibility of the card's resolution. either player could respond after the discard, before the draw. i don't think that's supposed to happen.
  • i seem to recall some references to an Input stack. this is an Input stack, not a MagicStack.
    does it work? if it is supported, perhaps you could push a dummy Input for drawing a card that calls its own selectX method from showMessage, then push the one for discarding. then they resolve in reverse order.

edit 1: fixed list tag.

Pipe dreaming Re: making code wait on Input

PostPosted: 07 Jul 2011, 14:41
by Braids
slapshot5 wrote:
Code: Select all
public void resolve() {
player.discard();
player.drawCard();
}
Code: Select all
public void resolve() {
    final Player finalPlayer = player;
    Thunk<Null> drawThunk = new Thunk<Null> {
        public Null apply() { finalPlayer.drawCard(); return null; }
    };
    player.discardThen(drawThunk);
}
a thunk is a function that takes no arguments. it's like a simplified lambda. you can pass the thunk around without applying/invoking it to defer execution. too ugly? too strange?

there are thunks and lambdas on the minimax branch. :-)

edit 1: fixed bugs in code #-o
edit 2: fixed typo
edit 3: improved indentation

Re: making code wait on Input

PostPosted: 07 Jul 2011, 14:46
by Hellfish
So it's like a Command object with a return type? :P

Re: making code wait on Input

PostPosted: 07 Jul 2011, 14:48
by Braids
yes. yes, it is. Null is a special class that cannot be instantiated by anyone ever, so about the only value it can take on is an actual {null}.

Re: making code wait on Input

PostPosted: 08 Jul 2011, 11:52
by Rob Cashwalker
a thunk is a function that takes no arguments.
What, did Dr. Suess have a hand in designing Java?

Re: making code wait on Input

PostPosted: 08 Jul 2011, 13:45
by Braids
Rob Cashwalker wrote:
a thunk is a function that takes no arguments.
What, did Dr. Suess have a hand in designing Java?
.
.
if there's a funk in your thunk that's passed by reference,
and your lesser professor is demanding more deference,
then junk your thunk for a grander scheme;
and pass lambda on as an internet meme.


from http://dictionary.reference.com/browse/thunk under "Computing Dictionary":
In fact, according to the inventors, it was coined after they realised (in the wee hours after hours of discussion) that the type of an argument in ALGOL 60 could be figured out in advance with a little compile-time thought, simplifying the evaluation machinery. In other words, it had "already been thought of"; thus it was christened a "thunk", which is "the past tense of "think" at two in the morning".

Re: making code wait on Input

PostPosted: 09 Jul 2011, 15:00
by friarsol
Did you get anywhere with this Slap? Looks like here's another issue we have with it: http://code.google.com/p/cardforge/issu ... 1310223583

Re: making code wait on Input

PostPosted: 09 Jul 2011, 15:53
by slapshot5
friarsol wrote:Did you get anywhere with this Slap? Looks like here's another issue we have with it: http://code.google.com/p/cardforge/issu ... 1310223583
I tried a post-input command implementation, but the Input object I wanted didn't exist when I expected.

I ended up just coding around it for the card I wanted to add: Chains of Mephistopheles

-slapshot5