Dealing with a turn based application with using a global static variable

Hi there. I read some articles about JavaFX concurrency,so as a newbie i have to practice on it. Now i'm trying to implement a turn based application that can be played among 3-6 players. Moreover, i use a scene imported from a .fxml file and i have to update it correctly depends on some calculations of each thread (in other word players ). My main issue is, i don't wanna use a while loop which checks the state of game like;
while( GameState != State.GAME_OVER ){
     currentPlayer = GameBoard.getNextPlayer();
     // do some actions,calculations etc.
So, i want to use worker threads instead of this while loop. I guess using Service class for iterating and assigning the next player will be suitable instead of using the while loop and Tasks for doing each player's calculation,or waiting for some responses from Human players on UI based,however, i'm struggling with two problems.
There should a global static variable ( like GameState which is an Enumarator ) determines the state of the game,so it should be updated and should be checked by each turn. Is there any way to do this ?
How can i get rid off this while loop ?
I will appreciate for every answer. Thanks anyway.

It shouldn't make too much difference. The basic idea is that you have a model class representing your game state (the Game class in jsmith's example). When a player makes a move, you update the state of the game. Since this will result in changes to the UI, this update should be performed on the FX Application Thread.
If the player making the move is a human player, the move will likely be made by a user action (button press or mouse click, etc); this will be handled on the FX Application thread anyway.
When the state of the game changes so it is the turn of an "artificial" player to make a move, have the object representing the artificial player calculate its next move, and then update the game state. Since this is a response to the game state changing (it's now the turn of the artificial player), this will also be on the FX Application Thread.
The only (slight) complexity comes if the calculation of the move for the artificial player takes a long time. You don't want to perform this long running calculation on the FX Application Thread. The cleanest way to manage this is to launch a Task which calculates the desired move, and then updates the game state when the move is ready. So, something like this:
GameState game = ... ;
// UI is bound to the game state.
ExecutorService executorService = ... ;
final Player currentPlayer = game.getCurrentPlayer() ;
final Task<Move> calculateMoveTask = new Task<Move>() {
     @Override
     public Move call() {
          Move move = // compute next move...
          return move ;
calculateMoveTask.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
     @Override
     public void handle(WorkerStateEvent event) {
          gameState.makeMove(currentPlayer, calculateMoveTask.getValue());
executorService.submit(calculateMoveTask);
If you're doing more threading than that, you're probably doing it wrong... . There should also be no need for anything to be held as a "global" static variable (the idea above is the only structural modification you need to the example posted by jsmith).

Similar Messages

  • Which is better approach to manage sharepoint online - PowerShell Script with CSOM or Console Application with CSOM?

    Which is better approach to manage sharepoint online - PowerShell Script with CSOM or Console Application with CSOM?
    change in sharepoint scripts not require compilation but anything else?

    Yes, PowerShell is great, since you can quick change your code without compilation.
    SP admin can write ps scripts without specific tools like Visual Studio.
    With powershell you can use cmdlets,
    which could remove a lot of code, for example restarting a service.
    [custom.development]

  • Building a simple field based application with OA framework

    Hello everyone,
    I have an assignment to build a simple form that takes in some parameters and in which some of the fields will be validated with a value set. Using the information from this form, I then have to use the parameters in a PL/SQL function/procedure and return a value of successful or not.
    Basically a simple form based application.
    I was wondering if it is possible to do this in OA Framework. All I hear about is extensions and personalizations but is it possible to build a simple application with it?
    Also, can anyone point me to a good tutorial showing how to build a simple application in OA framework?
    Or if OA framework won't do the job, can I use ADF (on oracle 11i) to accomplish this?
    Thanks a lot in advance

    Please visit
    http://oracle.anilpassi.com/oa-framework-tutorials-training.html
    It would be really helpful :)

  • How to start an Swing based Application with a display of an Image

    I want that when I run my swing based application, first a specified image should me displayed

    I was talking about the determination of the resolution of image in (int). Resolution means number of pixels in per unit area of the image, I think it has nothing to do with image magnification. If you have some another idea ,tell me on [email protected]

  • Install PeopleTools 8.53 with Linux Issue: Configure Application Server using psadmin

    Folks,
    Hello. I am installing PeopleTools 8.53 Internet Architecture. Database Server is Oracle Database 11gR1. OS is Oracle Linux 5. I have installed JDK7, WebLogic 10.3.6, Tuxedo 11gR1 and PeopleTools 8.53 successfully into Oracle Linux 5. I have set up PeopleTools 8.53 Database Instance into Oracle Database Server successfully. Data Mover and Application Designer login into the Database Instance successfully. Web Server has been configured successfully.
    Now, I confront the issue regarding configuring Application Server as below:
    In Windows, I run /PT8.53/appserv/psadmin.exe to create a domain for the PeopleTools Database Instance successfully. But in Linux, the file /PT8.53/appserv/psadmin is light blue color and not executable, I try to run it in the following way:
    [user@userlinux appserv]$ ./psadmin
    Its output: ./psadmin: error while loading shared libraries: libtrio64.so: cannot open shared object file: No such file or directory
    My question is:
    Can any folk tell me how to configure Application Server using psadmin in Linux for PeopleTools Internet Architecture ? How to solve the above issue ?
    Thanks.

    Folks,
    Hello. Thanks a lot for replying. I run psadmin in the way below:
    [user@userlinux PT8.53]$ . ./psconfig.sh
    [user@userlinux appserv]$ export TUXDIR=/home/user/Oracle/Middleware/tuxedo11gR1
    [user@userlinux appserv]$ export LD_LIBRARY_PATH=$TUXDIR/lib:$LD_LIBRARY_PATH
    [user@userlinux appserv]$ export PATH=$TUXDIR/bin:$PATH
    [user@userlinux appserv]$ ./psadmin
    For Application Designer login, I use UserId PSADMIN and password PSADMIN, it works successfully.
    For Data Mover Bootstrap Mode login, I use UserId MYNAME and password MYNAME, it works successfully.
    When configure Application Server, I use UserID PSADMIN and password PSADMIN. But when boot the domain, the current server log file "APPSRV_0919.LOG" indicates that "Database Signon: Could not sign on to database PT853 with user PSADMIN."
    Then I use UserId MYNAME and password MYNAME to configure the Application server again. I boot this domain again. Strangely, the log file APPSRV_0919.LOG gets the same error message "Database Signon: Could not sign on to database PT853 with user PSADMIN."
    I purge the cache and clean IPC resources of this domain, and boot this domain again but get the same error message as above.
    The content of current server log file /home/user/psft/pt/8.53/appserv/PT853/LOGS/APPSRV_0919.LOG is below:
    PSADMIN.5732 (0) [2013-09-19T11:01:10.841](0) Begin boot attempt on domain PT853
    PSAPPSRV.9537 (0) [2013-09-19T11:01:30.338](0) PeopleTools Release 8.53 (Linux) starting. Tuxedo server is APPSRV(99)/1
    PSAPPSRV.9537 (0) [2013-09-19T11:01:30.484](0) Cache Directory being used: /home/user/psft/pt/8.53/appserv/PT853/CACHE/PSAPPSRV_1/
    PSAPPSRV.9537 (0) [2013-09-19T11:01:30.539](1) GenMessageBox(200, 0, M): PS General SQL Routines: Missing or invalid version of SQL library libpsora64 (200,0)
    PSAPPSRV.9537 (0) [2013-09-19T11:01:30.548](0) Database Options: override_connection_reset: 0
    PSAPPSRV.9537 (0) [2013-09-19T11:01:30.550](1) GenMessageBox(0, 0, M): Database Signon: Could not sign on to database PT853 with user PSADMIN.
    PSAPPSRV.9537 (0) [2013-09-19T11:01:30.551](0) Server failed to start
    PSADMIN.5732 (0) [2013-09-19T11:01:38.906](0) End boot attempt on domain PT853
    PSADMIN.10674 (0) [2013-09-19T11:02:20.766](0) Begin boot attempt on domain PT853
    PSAPPSRV.11239 (0) [2013-09-19T11:02:34.736](0) PeopleTools Release 8.53 (Linux) starting. Tuxedo server is APPSRV(99)/1
    PSAPPSRV.11239 (0) [2013-09-19T11:02:34.823](0) Cache Directory being used: /home/user/psft/pt/8.53/appserv/PT853/CACHE/PSAPPSRV_1/
    PSAPPSRV.11239 (0) [2013-09-19T11:02:34.848](1) GenMessageBox(200, 0, M): PS General SQL Routines: Missing or invalid version of SQL library libpsora64 (200,0)
    PSAPPSRV.11239 (0) [2013-09-19T11:02:34.854](0) Database Options: override_connection_reset: 0
    PSAPPSRV.11239 (0) [2013-09-19T11:02:34.855](1) GenMessageBox(0, 0, M): Database Signon: Could not sign on to database PT853 with user PSADMIN.
    PSAPPSRV.11239 (0) [2013-09-19T11:02:34.856](0) Server failed to start
    PSADMIN.10674 (0) [2013-09-19T11:02:41.270](0) End boot attempt on domain PT853
    PSADMIN.5107 (0) [2013-09-19T11:56:37.435](0) Begin boot attempt on domain PT853
    PSAPPSRV.5182 (0) [2013-09-19T11:56:57.842](0) PeopleTools Release 8.53 (Linux) starting. Tuxedo server is APPSRV(99)/1
    PSAPPSRV.5182 (0) [2013-09-19T11:56:58.068](0) Cache Directory being used: /home/user/psft/pt/8.53/appserv/PT853/CACHE/PSAPPSRV_1/
    PSAPPSRV.5182 (0) [2013-09-19T11:56:58.134](1) GenMessageBox(200, 0, M): PS General SQL Routines: Missing or invalid version of SQL library libpsora64 (200,0)
    PSAPPSRV.5182 (0) [2013-09-19T11:56:58.142](0) Database Options: override_connection_reset: 0
    PSAPPSRV.5182 (0) [2013-09-19T11:56:58.144](1) GenMessageBox(0, 0, M): Database Signon: Could not sign on to database PT853 with user PSADMIN.
    PSAPPSRV.5182 (0) [2013-09-19T11:56:58.145](0) Server failed to start
    PSADMIN.5107 (0) [2013-09-19T11:57:05.737](0) End boot attempt on domain PT853
    PSADMIN.4966 (0) [2013-09-19T18:55:48.131](0) Begin boot attempt on domain PT853
    PSAPPSRV.5009 (0) [2013-09-19T18:56:08.869](0) PeopleTools Release 8.53 (Linux) starting. Tuxedo server is APPSRV(99)/1
    PSAPPSRV.5009 (0) [2013-09-19T18:56:09.071](0) Cache Directory being used: /home/user/psft/pt/8.53/appserv/PT853/CACHE/PSAPPSRV_1/
    PSAPPSRV.5009 (0) [2013-09-19T18:56:09.130](1) GenMessageBox(200, 0, M): PS General SQL Routines: Missing or invalid version of SQL library libpsora64 (200,0)
    PSAPPSRV.5009 (0) [2013-09-19T18:56:09.138](0) Database Options: override_connection_reset: 0
    PSAPPSRV.5009 (0) [2013-09-19T18:56:09.140](1) GenMessageBox(0, 0, M): Database Signon: Could not sign on to database PT853 with user PSADMIN.
    PSAPPSRV.5009 (0) [2013-09-19T18:56:09.141](0) Server failed to start
    PSADMIN.4966 (0) [2013-09-19T18:56:16.253](0) End boot attempt on domain PT853
    PSADMIN.4966 (0) [2013-09-19T19:40:11.049](0) Begin boot attempt on domain PT853
    PSAPPSRV.6475 (0) [2013-09-19T19:40:26.633](0) PeopleTools Release 8.53 (Linux) starting. Tuxedo server is APPSRV(99)/1
    PSAPPSRV.6475 (0) [2013-09-19T19:40:26.731](0) Cache Directory being used: /home/user/psft/pt/8.53/appserv/PT853/CACHE/PSAPPSRV_1/
    PSAPPSRV.6475 (0) [2013-09-19T19:40:26.776](1) GenMessageBox(200, 0, M): PS General SQL Routines: Missing or invalid version of SQL library libpsora64 (200,0)
    "~/psft/pt/8.53/appserv/PT853/LOGS/APPSRV_0919.LOG" 64L, 7012C
    My question are:
    1) I have changed UserId from PSADMIN to MYNAME and password from PSADMIN to MYNAME in Application Server configuration, why the log file APPSRV_0919.LOG gets the same error message "Database Signon: Could not sign on to database PT853 with user PSADMIN." ?
    2) I purge the cache and clean IPC resources of this domain and reboot this doamin, why the log file APPSRV_0919.LOG gets the same error message "Database Signon: Could not sign on to database PT853 with user PSADMIN." ?
    3) How to solve the above issues ?
    Thanks.

  • I installed firefox 10 - it was offered on startup. I absolutely does not work with a cloud based program I use (corecon) and I want to GO BACK TO FIREFOX 9. how do i do this?

    firefox 10 ABSOLUTELY does not work with a cloud based program, Corecon. I want to UNINSTALL firefox 10 and GO BACK TO FIREFOX 9 . How do I do this? This is a subscription service, you may not be able to try it. v9 works fine.

    http://support.mozilla.com/en-US/kb/Installing+a+previous+version+of+Firefox
    http://www.mozilla.com/en-US/firefox/

  • Grey screen with message "turn off computer with power button until switch off then press again power button"

    Dear all,
    I'm very hungry with my iMac and my Time Capsule :
    I try for two weeks to restore my iMac without any success...
    I wait 80 hours to finally have the message again and again : "to restart your computer : turn off computer with power button until switch off then press again power button".
    But my iMac do not work !
    Could you help me?

    Hello, that's a kernel panic...
    http://thexlab.com/faqs/kernelpanics.html
    Could be many things, we should start with this...
    "Try Disk Utility
    1. Insert the Mac OS X 10.6 Install disc, then restart the computer while holding the C key.
    2. When your computer finishes starting up from the disc, choose Disk Utility from the Installer menu at top of the screen. (In Mac OS X 10.4 or later, you must select your language first.)
    *Important: Do not click Continue in the first screen of the Installer. If you do, you must restart from the disc again to access Disk Utility.*
    3. Click the First Aid tab.
    4. Select your Mac OS X volume.
    5. Click Repair Disk, (not Repair Permissions). Disk Utility checks and repairs the disk."
    http://docs.info.apple.com/article.html?artnum=106214
    Then try a Safe Boot, (holding Shift key down at bootup), run Disk Utility in Applications>Utilities, then highlight your drive, click on Repair Permissions, reboot when it completes.
    (Safe boot may stay on the gray radian for a long time, let it go, it's trying to repair the Hard Drive.)
    If perchance you can't find your install Disc, at least try it from the Safe Boot part onward.

  • Application Builder - Use of Global Variables

    Hello,
    I have an application which consists one one main VI running for the user interface, and one VI running in the background dealing with CAN communications.  These two VIs must communicate using global variables.  In the main VI, I have to open a reference to the global variable VI in order to write data to it.  The application works correctly in LabVIEW environment.  However when I build the application using application builder, I receive an error with the open reference VI in opening the global variable VI.  The error given is Error Code 7: File not found.  The path to the Global variable VI is correct however.  I am pretty sure of this because in my main VI, I open up other VIs based on the open reference function and a path.
    Therefore:
    1) I can open references to normal VIs and use properties such as run VI without a problem.
    2) This does not work for my global variable vi.
    Build settings:
    Im dont understand all the build options completely but the settings I use are:
    1) Single target file contening all the VIs
    2) All the VIs I use are located in the same folder
    I hope the explaination is clear enough.
    Do you have any suggestion to explain what happens and how can I make it work correctly?
    Thanks
    Julien

    Duplicate.
    Try to take over the world!

  • I have a g5 desktop and I am having an issue with it turning off while im using it. I think it may be something to do with the cooling system

    I am wondering what could be causing my computer to shut off while i'm using it. I think it is something to do with the cooling system because it feels hot to the touch and will not turn back on for awhile until it cools down

    Is yours an iMac G5:
    or a PowerMac G5:
    There is a big difference in the cooling systems. If you have the tower, we can get your post moved to the forum where all the G5 tower gurus hang out.

  • We just  bought an iMac.  We have a new HP printer that we've been using wirelessly with our windows based computers with no problem.  the iMac can find the printer, but it will not set up.  Any ideas?

    Our iMac can find the wireless printer, but it will not set it up.  Any ideas?

    I have to disagree with BGreg about downloading the driver from HP.com. I would recommend using Apple's instructions in
    http://support.apple.com/kb/HT4670?viewlocale=en_US&locale=en_US
    specifically the section on How to Add a Printer then check for the section on Wi-Fi printers.

  • How can I make a bootable disk with some third party applications to use?

    My Macbook's performance has slowed WAY down and I want to try running a couple of different tools on it to optimize it.
    Thing is, some if not all of them require you to boot from a different disk, and since I got them online, I don't have bootable CDs for them.
    The OS X install disk doesn't allow you to access files on your HD and neither does DiskWarrior's DVD, so is there any way at all to make a bootable CD which will show me a finder window with the tools I need or anything like that?
    I KNOW that BootCD exists for older versions of mac, and frustratingly that's the only answer I have come across online despite the fact that it doesn't work for Tiger.
    Please help, any advice would be greatly appreciated.

    Argh, posted this in the wrong section, AND I figured out how to do it myself anyway...
    Could a mod please close this? Apologies to everyone for making a balls of this

  • Help with speeding up Hadoop application with Jrockit vm

    Hi all,
    This is Grace. I am using JRockit JVM to run some Hadoop tests. In the test, there are many short time(within 1 minute) processes running. Comparing with the Sun JVM (with -Xmx option only), the test is completed much more slowly by Jrockit JVM. I have already tried to adjust some of the Jrockit basic options, such as –Xmx, -XXaggressive and etc. But there is no big difference. Have anyone seen this problem before? And does anyone can offer some advices about optimization or tuning? Thanks a lot for your time and help.
    Here is some basic information of the testing environment:
    OS: Redhat 5.3 x86_64
    Sun vm version is 1.6.0_11 (64bits), Jrockit vm version is 3.1.0-1.6.0(64bits)
    Regards, Grace

    Most of your objects are large and goes to the old space. When you are running with a nursery all large objects are allocated in the old space. (An object larger than 2k is typically considered large). This will result in a lot of GC of the old space. I guess that this is causing a lof of memCopyBlock() which is the performance blocker.
    So, I have a few suggestions:
    * Always set initial heap size equal to maximum heap size. -Xms=Xmx (1024m in your case) Set the maximal heap size as large as possible (without resulting in page faults).
    * With such high amount of large objects you could profit a static GC, for example -Xgc:singlepar (or -Xgc:genpar with a very small nursery).
    * If the large objects in your application live shortly then you may still profit from using a nursery.
    ** Set GC strategy to -Xgc:genpar (or -Xgc:gencon) to get a nursery.
    ** You will also need to modify the threshold for large objects by setting: -XXlargeObjectLimit="a limit, a little larger than the size of your objects".
    ** Tune nursery size. You will probably have to test a few nursery sizes before you find the best suited nursery size
    ** I see that you tune TLA. TLA tuning is preferably combined with tuning the large object limit for example: -XXtlasize:min=4k, preferred=128k - XXlargeObjectLimit=4k
    I would not use -XXaggressive if it does not give you performance improvements. The same for LazyUnlcoking - it gives a performance boost for some applications, but not all.
    Edited by: TuvaPalm on May 12, 2009 6:08 AM

  • I have a customer looking for a high speed vision system 500 fps. Anyone been successfull (or not) with this kind of application with NI hardware?

    Stu

    The digital boards can handle these high frame rates as long as the bytes/sec is within specs of the board, as Bruce mentioned. The question is still what you want to do with these images. You mentioned memory storage, how much memory will it take? The 1424 can have 80MBytes of onboard memory, so you could store it all there and then bring it to the host computer at your convienence. If you bring it directly to the host computer, keep in mind the maximum sustained bandwidth of the PCI bus is about 100 MBytes/sec and if you have 3 digital boards outputting data, this could be a limiting factor (overhead of the three boards communicating on PCI may reduce bandwidth also). Make sure you have plenty of RAM to hold all this data if you do bring it directly to t
    he host computer. Graftek is very good at recommending specific cameras and Robert Eastlund with www.graftek.com (a imageing alliance member witrh NI) has done these type of applications before and could give you more specific advise.
    So in summary, our boards should have no problem withg high frame rates as long as the cameras meet our specs (pixel clock of 40MHz max and the new 1424's have a 100MBytes/sec max data transfer)
    Hope this helps,
    Brad Buchanan
    National Instruments

  • WebStart with console based applications

    Hi:
    I've been struggling all day to get WebStart to work with a console based application (i.e., an application with no user interface that's launched from a shell window). When I launch the application with WebStart, the shell window is not visible. I've tried turning on the advanced option to show the console window, but only System.out and System.err go to there -- you cannot enter user input. Is there a way to run a console based application for a console based application? Thanks.
    -- Greg

    Hi,
    WebStart cannot get input from the console window.
    You may have to use some dialog boxes to get your input.
    zamir

  • Identity SSO API with non-web based appilcations

    hi,
    i can appreciate hwo this works with cookies etc for web based applications that use the api or one of the agents on apache etc.
    but how does it go with non web based java and say windows applications?
    can anyone point me to some docs?
    thanks

    I don't work for Sun but here are my thoughts
    1. Yes, if you don't want to use the AM SDK then the
    XML auth service is the way to go.
    2 & 3. dunno
    4. I think if you pass around the SSOToken ID
    generated by AM then any application can issue a SAML
    query to see if the session is still valid and get
    identity/auth attributes back
    5. I think SAML 2.0 supports authentication and
    single signoff
    6. If you are doing a lot of thick client apps you
    should use kerberos instead of AM web based
    Authentication. AM supports kerberos authentication,
    most modern browsers support SPEGNO for passing
    credentials to web server, AD supports Kerberos, and
    even Solaris 10 comes with a free KDC built into the
    OS. There is plenty of documentation around kerberos
    and the JDK out of the box supports GSS-API for
    Kerberos authenticationThank you for your feedback.
    We looked at the use of kerberos as well, but this is not really an option as we are dealing with fat clients installed on desktops of clients. So these desktops do not fall within our span control (multiple domain controllers etc.).
    Regards,
    Thomas

Maybe you are looking for