Board Game - how to display?

I know this is probably a really stupid question, but what is the best way to handle the display of my pieces vs my opponents pieces during a board game?

What I mean is, say I am playing a turn-based game, where I make a move, send it to my opponent via e-mail, he responds back, etc.

When I am playing the game on my end, my pieces will always be at the "bottom" of the opponents pieces will be at the top of the screen.

When my opponent plays on his machine, his pieces will be at the bottom, and mine at the top.  We're playing the same game on the same board, but with different perspectives.

A piece that I move "up" one square at the bottom right corner of my board will move "down" from the top left corner on my opponents display (perspective).

What is the SMART way to handle this transition of how the pieces look?  Have any of you ever programmed a simple board game?

What way will accomodate future changes to the game (say there are 3 players in version 2.0 of my game, or 4 players? 10 players?
Tom KnowltonWeb developerAsked:
Who is Participating?
I would simply do that:

Always take the playing user perspective.
Suppose you work with a grid like this:
1.1  2.1  3.1
1.2  2.2  3.2
1.3  2.3  3.3
When the user choose his move, send it to the oppent with negative values (for two players...) or any other necessary conversion. ex.: IPlayed(-x, -y) to (-x, -y).

To keep track of wath happens, I suggest you maintain a record instead of using your visual components, it will be faster. Build a record of what the user see. That means every players will have differrent data, as if they were playing alone.

ok, now the real thing.
To be ensure every player will be able to communicate with each other, you will need an algorithm that you can use everywhere for convertion(like I said above). for example, if player1 "talks" to player3, there will be something like Convert(Player3, x1, y1, x2, y2).

If you build your game like this, only the convertion will change.(unless you add a parameter, like iNumberOfPlayer). If you have more than two players, you will need to assign him a number, depending of his position. That way, he will send a different information to the right player than to the left one...

I would like to say more, but I got to go.
Hope this helps
You will have a data structure describing the board with lists of piece data structures which describe where the piece is currently placed. For each player you will have a list with his pieces.
The board data structure needs a list of sides the board has with each side connected to a player (chess having two sides).
Now the board painting function needs to be able to paint the board with a side as parameter.
like robert said you could use a data structure to describe everything.  like if it was chess.. each player has a color, white or black.  if your game is like this you could referance you players peice set with 'white' or 'black' (or '1' or '2', whatever) and then each individual piece (queen, king, pawn1, pawn2, etc).  to make a move, after referancing the piece and owner, you could just use some very general directional phrases like 'forward 2', 'backward 6', 'left 5' etc.  in each case your program would have a perspective to go off of (the pieces perspective) and could move accordingly.  all this could pretty easily be simplified to 1 line of text (for email purposes). like:

(black pawn3 0 -1)
move black pawn3 left 1
(black pawn3 1 2)
move black pawn3 forward 1 right 2

etc.  this could also be expanded to fit more players (more colors, sides)

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

No, i would prefer the absolute coordinates chess already has and extend it t other games.
Tom KnowltonWeb developerAuthor Commented:
Can someone give me an example?

Say the board is 3 x 3.

I would see the board as:

X X -
- - O
- O -

My opponnet would see the board as (the reverse):

- O -
O - -
- X X

I want to keep track of piece movement, etc. so that when my opponent moves and sends the move back to me, I see his move, but from MY perspective.

I this a really hard thing to do?

Are there books, websites, etc. that can explain this to me?  It is intuitive to me when I play a board game, but I don't understand how to program it.

I feel really dumb for having trouble with such a simple concept.

Increasing points to 90.
Tom KnowltonWeb developerAuthor Commented:


Tom KnowltonWeb developerAuthor Commented:
I don't need help so much with drawing the board or displaying the game pieces.

I need to know how to store it in a data structure, and use the same data structure to display the game for opponent A or opponent B.
Tom KnowltonWeb developerAuthor Commented:

I think I see where you are going with this.

Have you actually programmed board games before?

No, i only know how to structure data.
For the lists you can use TObjectList.

Start with a game object which carries a player list and the board object. A moves history list and actual player element is needed. That is an index to the player list.
Each player object in the player list carries a pieces list and a "color" element. Each piece contains an ID element ("knight" etc). An enum is sufficient for that. Then a position element is needed for pece object. This is the connection to the board object.

With this structuring you should be able to easily create games like chess or checkers which mainly differ in pieces.

Drawing the board is drawing the game structure. The actual player determines the way you draw the board.
This is a view to your data.
Hello - , I'm not sure what kind of answer you expect for your question, you might want to ask a less "general" question. Here are a couple of Web Links to download a couple of computer games that were made by Michael J. Mefford of PC Magazine. Both of these games (checkers and backgammon) come with a .ZIP file that contains the complete Delphi project Code. Although these look like they were made in Delphi 1 and will not compile in newer Delphi's without changes, you can still see the methods and data structures he used for these programs.
. . . If you don't have much experience with this, then you might begin by making a simple "Tic, Tac, Toe" game and build from there.



+ + +
as to the second player perspective thing. .  draw a checker board on a piece of paper and label the rows "1" "2" "3" "4" ect. . . . and lable the columbs "A" "B" "C" "D" ect. .  now rotate the checker board to your opponents persctive (upside down) and look at the order of the labels, now you will have to label the rows and columbs on his board in reverse to match the rows and columbs on your board
I would prefer to have the positions numbered with a single index (chess board = 1..64).
This allows to have an abstract pices which only contains no information about the layout of the board.
So you can implement games with hex field board and more than two players.

Base class is TGame containing many lists.
Players, Board, unused Pieces, Pieces on Board, Move History. A Player list element (aka player) contains a list of Pieces and taken Pieces.
Pieces do not contain graphics. Piece graphics are located in a list in the Board class. A Tile graphic list is also a goo idea. With that you can change to a new board style by exchanging the graphics lists and repaint.

With the above general layout you can implement games like Chess or Scrabble.

The general handling should be to mimic a real game. That is move the Piece objects from unused list to player list to taken Pieces list etc.
The game is driven by moves. The moves are placed in the Move History list. Game ID and Moves are the only information exchanged if the game is played with two instances of the program (ie via email).
Saving a game is mainly writing the Move History to a file.
Loading a game is initializing a game and replaying the moves from file.
You can convert X,Y position to index and the opposite with a simple transformation, if you know the number of lines and columns.

Index := nbElemLine * (LineNumber - 1) + ColumnNumber;
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.