Solved

Board Game - how to display?

Posted on 2001-07-07
12
533 Views
Last Modified: 2010-04-06
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 screen...my 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?
0
Comment
Question by:knowlton
  • 4
  • 4
  • 2
  • +2
12 Comments
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6262069
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.
0
 

Expert Comment

by:felonious
ID: 6263537
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)

felonious
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6263693
No, i would prefer the absolute coordinates chess already has and extend it t other games.
0
 
LVL 5

Author Comment

by:knowlton
ID: 6290703
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.
0
 
LVL 5

Author Comment

by:knowlton
ID: 6290711
websites?

books?

anyone?
0
 
LVL 5

Author Comment

by:knowlton
ID: 6290718
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.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 5

Author Comment

by:knowlton
ID: 6290721
robert_marquardt

I think I see where you are going with this.

Have you actually programmed board games before?

Thanks.
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6290807
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.
0
 

Accepted Solution

by:
comptebidon81 earned 90 total points
ID: 6299685
I would simply do that:

Always take the playing user perspective.
Suppose you work with a grid like this:
(x,y)
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
GunDamn
0
 
LVL 33

Expert Comment

by:Slick812
ID: 6300241
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.

checkers
http://www.zdnet.com/downloads/stories/info/0,10615,77351,00.html

backgammon
http://www.zdnet.com/downloads/stories/info/0,10615,77343,00.html

+ + +
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
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6300954
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.
0
 

Expert Comment

by:comptebidon81
ID: 6321875
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;
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now