home *** CD-ROM | disk | FTP | other *** search
- #ifndef RULES_H
- #define RULES_H
-
- #ifndef THINK_C
- #include <Types.h>
- #endif
-
- #define kFields 61
- #define kDirections 6
- #define kVictory 6
- #define kPlayers 3
-
-
- enum _directions
- {
- right,
- botright,
- botleft,
- left,
- topleft,
- topright,
- down /* off the board */
- };
-
-
- enum _result
- {
- normal_move = 0, ball_down
- };
-
-
- enum _owner
- {
- empty,
- blak,
- whit,
- grin
- };
-
-
- // Fields are numbered starting at 1; 0 is used for 'not on the board'.
- // The actual number of fields on the board is kFields, but the first field isn't
- // used so the number of a field can be used as an index.
-
- typedef unsigned char Arrow;
- typedef unsigned char Field;
- typedef Field Fields[kFields+1], *FieldsPtr;
- typedef unsigned char Loot[kPlayers][kVictory+1], *LootPtr;
- // The balls currently won by the players.
- // updated in DoMove.
- // Loot[<player>-1][<ball>] ::= color of victim for ball # <ball>
- // Special case:
- // Loot[<player>-1][0] ::= total # balls pushed off by <player>
-
- typedef struct _board
- {
- Fields field;
- Loot loot;
- unsigned char players;
-
- } Board, *BoardPtr;
-
-
- typedef unsigned char MoveData[4], *MovePtr; // first three for fields, last for direction
-
-
- // the following defines should have been functions for safety, but this is faster.
- // The tables should be initialised before use by calling InitRules
-
- #define Neighbour(field,direction) (_neighbour[(field)][(direction)])
- // Returns the neighbour of a field in a specified direction, or 0 if nonexistant
-
- #define Neighbours(field1,field2) (_neighbours[(field1)][(field2)])
- // Are the fields neighbours?
-
- #define Direction(from,to) (_direction[(from)][(to)])
- // Returns the direction from one field to another if neighbours, down otherwise
-
- #define Distance(field,direction) (_distance[(field)][(direction)])
- // Returns the distance from the edge in a certain direction
-
- void InitRules (void);
- // Initialise the tables for the defines above.
- // Should be called before using any one of them.
-
- void ResetBoard (BoardPtr);
- // Reset the board data structur to the initial position.
-
- Field LocToField (short h, short v);
- // Convert local coordinates to field number.
-
- short DoMove (BoardPtr board, MovePtr move);
- short DoFlicheMove (BoardPtr board, MovePtr move);
- // Do administration involved with a move.
- // Nothing else (sound, updates etc.) is done,
- // so the function can be used in move evaluations.
-
- short BallsWon (BoardPtr board, short player);
- // Count the number of balls the given player has won from the other player(s)
-
- #define NextPlayer(current) (((current) % gTheGame.Players) + 1)
- #define PriorPlayer(current) ((current + gTheGame.Players - 1) % gTheGame.Players)
- // Returns the next player for the given one
- // not a function to save function call overhead
-
- Boolean ValidMove (BoardPtr board, MovePtr move);
- Boolean ValidFliche (BoardPtr board, FieldsPtr field);
- Boolean ValidFlicheSorted (BoardPtr board, FieldsPtr field);
- Boolean ValidFlicheMove (BoardPtr board, MovePtr move);
- Boolean ValidFlicheMoveSorted (BoardPtr board, MovePtr move);
- // Test possible selections/moves for validity.
- // Normally, the 'unsorted' functions should be used,
- // the 'sorted' varieties assume the move is presented to them 'sort3' sorted
-
-
- #ifdef RULES_C
-
- #include "Error.h"
- #include "Game.h"
- #include "Global.h"
- #include "Settings.h"
-
-
- void sort3 (FieldsPtr fields);
- short DoPropMove (BoardPtr board, Field f, Arrow direction);
-
- #else
-
- // These tables must be exported for the defines above to work.
- // Logically, they're local to this module; they're exported for efficiency.
- // Do not modify elsewhere!
-
- extern Field _neighbour [kFields+1] [kDirections+1];
- extern Boolean _neighbours [kFields+1] [kFields+1];
- extern Arrow _direction [kFields+1] [kFields+1];
- extern unsigned char _distance [kFields+1] [kDirections];
-
- #endif
-
-
- #endif