Pseudo code

ytwendy
ytwendy used Ask the Experts™
on
I am trying to make a two player game.
How would I think about the way the players change after each move?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2013

Commented:
What kind of game?
Are the players collaborative or competitive?
Is it turn-based?
Need some more information to help you please.

Author

Commented:
sorry ,It.s a chess game
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Author

Commented:
how would I think about the way the players alternate. after each move change side?

Commented:
If you are asking when they will calcualte there next move it depends on how indepth you want to go.  You can make a simple game of chess or you can make it complex.  You have to put in many variables for every senario.  Most common is moves at the start of there turn.

Or maybe i am not getting the question.

Author

Commented:
sorry. i.ll explain.
I have constants that tell me whether the piece is black or white.
when the white player finishes the move it is the black players turn.
how do i stop the white player pieces from moving? or the other way around

I have made some pseudocode but don.t know how to code it[java]. I am confused on the sequence of events.
Commented:
Pseudocode:

1) The game starts. White (human, for example) plays selecting a valid position and press the button PLAY. If the position is invalid tell him why it is invalid and let him play again. If the position is valid, go to step 3.
2) Black (computer, for example) verifies the intern array with the position of all pieces (black and white) on the board, selects the best move and move it slowly (if graphically) and/or print on the screen the move (H1-B2, for example). Go to step 3.
3) Check whether it is check mate. If yes, it is game over. Congratulations for the winner. Show msg: "Play again?". If it is not game over, pass the turn to the next player. If variable next player is 1, go to step 1 else go to step 2.



Commented:
I'm going to assume that this is a two player game, with real people (no computer opponent).  

If this is a client/server application...

Server (Start of new game)
      1)  Randomly assign each player the black or white pieces.
      2)  Notify the white pieces player with a game packet that it is their turn, with a status of 'active'
      3)  Notify the other player in the game that it is their opponents turn to move, Their status is "waiting"
      4)  Server shall keep track of which player is active or waiting, and ignores any "move" requests from a player that is "waiting".

Server (game play loop)
      if (move request is received from the "active" player)
            case VALID MOVE:  Move piece and update both clients.  Check for checkmate, and if not, swap the state of each players status.  If it is checkmate, notify "active" player that they've won, and the "waiting" player that they've lost.
            case INVALID MOVE:  Notify the "active" client that this move is invalid.

Client (Loop)
            "active" packet received:  Allow the player to move their own pieces.  Submit a "move" request to the server when one of their pieces is moved.
            "waiting" packet received:  Disable movement of any pieces on the board.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial