Welcome Guest, Not a member yet? Register   Sign In
Psuedo Code Needed...
#1

[eluser]troy_mccormick[/eluser]
So I'm building an AJAX (gotta use the nice keywords...) poker script which will be open source (link in signature) and I've come across something that I need some help wrapping my head around.

Here's how it breaks down:

Players play a hand up to showdown. At showdown, all players involved have their cards flipped over and the best hand wins.

What I need code for would be how to 'delay' the start of the next hand and to show those hands flipped over for x amount of time.

The first thing that popped into my mind on this was a php sleep command, but I don't think that is what I'm after. I then got an idea that I'm not sure how to implement. I would go ahead and start the new hand behind the scenes but not allow each of the players to receive the data for the new hand until x amount of time had passed on the client side since they received an update on game data. Again, no idea how I would implement that one...

Does this make sense at all? Tongue

Thanks,
#2

[eluser]Nick Husher[/eluser]
This is all very abstract. Solutions to your problem would depend greatly upon your architecture, so I think we'd need to know more about your program structure.
#3

[eluser]troy_mccormick[/eluser]
What information do you need?

The backend of the application is all CI and MySQL and the front end is ExtJS...not sure if that helps any.

What details I guess do you need Tongue
#4

[eluser]jedd[/eluser]
From a UI POV I'd suggest you flip the cards, and provide some means for the user to proceed (yes, a button of some sort). Don't force timers on users - it's impolite.
#5

[eluser]troy_mccormick[/eluser]
Unfortunately that is the nature of the game, though...otherwise the game may never end! Smile
#6

[eluser]Phil_B[/eluser]
This should all be clienside. Delaying a response from the server would be awkward. Have javascript wait the amount of time required before making the next request to the server.
#7

[eluser]Nick Husher[/eluser]
I disagree that it should be entirely client-side. If game-critical logic is executed by your client, you're handing your players a potential means of exploitation. Were I creating something like this, I'd have a 10-second tick function on the client that requests the game state from the server. The server stores the game state in a database or other persistent solution, and hands back updates to the game state to any registered requesting clients. Think about it like a double-blind game of Axis and Allies played over the phone.

Player A calls Controller: "What's the change in state of the game since the last time I called?"
Controller: "Since that time, the Germans have moved into Spain. The Japanese were pushed back in northern China. You received X production points."
Player B calls Controller: "What's the change in state of the game since the last time I called?"
Controller: "::as above::"
Player A: "I would like to move into western Africa, here."
Controller: "Okay. Since the last time you called, the Japanese invaded northern China."

etc...

In this way, all the game logic is held on the server-side and it represents the "blind" in a double-blind game. Almost all card games are such double-blind imperfect-knowledge games, which makes this model suitable.

The details of how you pass those messages back and forth is up to you. I'd use JSON-RPC for simplicity's sake, but you may already have something thought out.
#8

[eluser]Phil_B[/eluser]
Sorry, my suggestion was too generic. I meant the timing and when to display the cards.

Your example is a good one. Hopefully what Troy was looking for.
#9

[eluser]jacobc[/eluser]
Exactly as Nick Husher said... the only thing that should be clientside is requests to the controller to see what is happening...

There are going to be some fun things to play with though... Deciding if a user is AFK and the like...

Cool project.
#10

[eluser]troy_mccormick[/eluser]
[quote author="Nick Husher" date="1236842353"]The server stores the game state in a database or other persistent solution, and hands back updates to the game state to any registered requesting clients. Think about it like a double-blind game of Axis and Allies played over the phone.[/quote]

This is about exactly how I have it setup. The database stores the game_data and player_data in a table as a PHP serialized array along with a date/time when each was last updated. Right now I have the client side "pinging" the server for changes every three or so seconds. If there is an update, it pulls down a JSON response and updates the table view as needed.

However, I'm still left with the fact that I want to delay the update on the client side table view during the showdown stage of the hand. If I hold off to start a new hand after x seconds and start that new hand when a new ping comes in from any of the players, there could be a race situation in that the hand could be started multiple times by multiple players. Should a player close their browser window and not return, it then may be possible for the whole game to come to a hault, which would anger the rest of the players Tongue

Thank you for all the ideas though...keep 'em coming!!! Tongue




Theme © iAndrew 2016 - Forum software by © MyBB