Terminate function on System.in .. possible?

Posted by Ronald on Stack Overflow See other posts from Stack Overflow or by Ronald
Published on 2012-09-26T15:36:03Z Indexed on 2012/09/26 15:37 UTC
Read the original article Hit count: 211

Filed under:

I am currently working on a project where I have to make an agent to interact with a server.

Each 50ms, the server will receive the last thing I outputted to System.out and send me a new set of lines as a 'state' through the System.in printstream to analyze and send my next message to System.out.

Also, if the server receives multiple outputs from me, it only regards the most recent one.

..

As for my question:

My program originally constructed a tree and then analyzed each leaf node to see which would be optimal, and then waited around for the next input, but I can recursively do a deeper tree search that would make my output 'better' (and again and again to keep returning a better result).

Using this and the fact that if the server receives multiple outputs, it only takes the most recent one, I could do each level, print my result and start the next level. But here comes my problem...

I can't be stuck in some complex algorithm while I am supposed to receiving the next input as I will then miss it. So I was wondering if there is a way to cancel anything else I am doing when I receive something via System.in and then go back to the beginning of the function and start the search again with the new set of input (and rinse and repeat..)

I hope this all makes sense,

Thank ye all

© Stack Overflow or respective owner

Related posts about JavaScript