hiding the values in a string array

• 01-25-2005
Chaplin27
hiding the values in a string array
Hey guys...I'm trying to make a trivial pursuit board with all the different colors being represented by 2 letter words (pink = PK, etc) and I'm trying to make it look like a piece would be moving around this board so let's say on the first square you start on (array[0] = "F S") is it possible to change the value stored in that array temporarily to a 'O' or something to signal a player's piece is in that square at that moment...but once the player leaves that square it will return to the value "F S"...this is all being done in the console window (because my skills arent advanced enough to do anything else yet hehe)...any ideas or pieces of code would be cool...thanks a lot, Chap
• 01-25-2005
sean
Well you could have one array that stores data about the colors of the board squares, etc.. and then have another value for each square that specifies the status of the board (i.e. if someone's there, and if so, what character). It would be much more efficient if you worked driectly with binary. You could use a lot less space, and learn more about C/C++ in the process. Look for the site's tutorial on bit-shifting. PM me if you want a bit more help as to how it applies to a board game.
• 01-25-2005
Chaplin27
hmmm...So first off...thanks so much for the advice...however, the bitwise tutorial lead me to an error page...I'm going to fish around the net some more and see if I can dig up some good info...the best I got so far was bitwise FAQs which didnt really make sense to me because I suck at binary math (well less sucking and more of just a lack of any exposure :) )
So once again...thanks again...if you know of any good, credible tutorials or books don't be afraid to spread the good word ;) haha, thanks a lot-Chap
• 01-25-2005
sean
Basically you just need to learn how to manipulate individual bits in a char variable, and determine if certain bits are set. If you can learn that from a tutorial, you're all set. From there it's not a huge jump to see how you can use it for storing the information about your board. I'm about to go to bed, but if you can't find anything, PM me and I'll send you a little tutorial of my own.
• 01-26-2005
quzah
I don't really see it being more efficient. They've already stated that they're using a board (an array of characters), because since this is text based, they have to have something to represent what's going on. So manipulating bits really isn't going to do anything other than waste time. (Not that bitwise operations are slow, it's just unneeded.)

Consider the following:
Code:

```[xx][xx][xx][xx][xx][xx][xx][xx][xx][xx] [xx]                                [xx] [xx]                                [xx] [xx]                                [xx] [xx]                                [xx] [xx]                                [xx] [xx]                                [xx] [xx]                                [xx] [xx]                                [xx] [xx][xx][xx][xx][xx][xx][xx][xx][xx][xx]```
Here's our board. I'll use the standard Monopoly style board, because it's easy for me to quickly draw using ascii. Some place in your program you're going to have a "drawboard" function. It's really quite simple:
Code:

```for each section of the board:     if( character_is_here )         draw_character_representation();     else         draw_board_section( here );```
So if we were to start with this one, drawing them square by square, we'd start in the upper left. If I was there, you'd draw "[Q.]", if not, you'd draw "[xx]". Then you'd move on to the next piece. If I was there, you'd draw "[Q.]". If not, you'd draw "[xx]", and so on.

This can be even simpler if you've got objects which store their own symbol. Assuming you've got some classes, or even if you don't, you can have each player and each board piece contain the information for that type of piece. For example, my piece would be [Q.]. Pink pieces would be [Pk] or what not. Then you invoke something like:
Code:

```board::drawboard() {     for each piece in the board list         if( thispiece.isoccupied() )             thispiece.draw( (thispiece.getplayer()).getsymbol() );         else             thispiece.draw( thispiece.getsymbol() ); }```
It's a crude example, but the point should be easy enough to follow. The hard part is figuring out what to do if you have more than one person on the same square. ;)

Quzah.
• 01-26-2005
Chaplin27
haha awesome suggestion...I'll see what I can do with it..thanks a lot