| Game Code for ROM |
This idea was inspired by Robert "Sembiance" Schultz after seeing his excellent game code (the version I saw had two good games - a card game, and a slot machine). My idea was to make a game that could be played by two or more players in the MUD.
| Checkers |
I wanted to make a board game such as chess with the board as an object,
but I didn't want to start adding variables to the OBJ_DATA structure.
The solution was a simple one, just use the bits in the obj->value array
to represent pieces.
The problem with this method is that it is extremely limiting on the
number of pieces you can have. For this reason I decided that chess
would be impossible, but with some creative use of the arrays, checkers
was perfect.
Although there are 64 squares on a chess board, checkers only uses 32 of
them. This means that we can have one bit per square in each of the five
obj->value array elements. This gives us a five bit number for each usable
square on the board to represent the location of the pieces. Here's one
possible scheme:
Using this scheme we actually only need three of the five array elements available! The only problem now is to piece the bits of the three elements into a usable number for each square to display the board with. I used this code (if the ascii art doesn't show up properly on your browser, it's just single lines to make boxes around the text):
void look_checkers( CHAR_DATA *ch, OBJ_DATA *obj )
{
int i, j, k, a, b, c, d;
char buf[MAX_STRING_LENGTH];
|
My color codes are a single '`' character followed by one letter describing the color. They are described in detail in another document. The code will properly display a checkers board using ascii art and assemble the bits of the array elements into usable numbers. The only thing left to do is simply create a control function to enable a player to move the pieces. This is a simple matter of using the SET_BIT, REMOVE_BIT and IS_SET defines from stock ROM to see what's in a square already and move a piece. The only technical detail is that to take a piece (eg a black piece), you must first move your piece (a white piece) onto the black piece, then again to move over it. This will result in the black piece being removed from the array as it is overwritten by the white piece.
"MERC/Derivative Programmers" webring [Next] [Index] [Prev] [Joining]