[PATCH] Remove arguments, patch vixen, add hunter AI
[progcomp2012.git] / judge / manager / stratego.h
1 #ifndef STRATEGO_H
2 #define STRATEGO_H
3
4 #include <stdlib.h>
5 #include <stdio.h>
6
7 #include <assert.h>
8
9 #include "graphics.h"
10 #include "array.h"
11
12 #include <vector>
13
14 /**
15  * Contains classes for a game of Stratego
16  */
17
18
19 /**
20  * Class for a game piece
21  */
22 class Piece
23 {
24         public:
25                 typedef enum {ERROR=14,BOMB=13,MARSHAL=12, GENERAL=11, COLONEL=10, MAJOR=9, CAPTAIN=8, LIEUTENANT=7, SERGEANT=6, MINER=5, SCOUT=4, SPY=3, FLAG=2,BOULDER=1, NOTHING=0} Type; //Type basically defines how strong the piece is
26                 
27
28         
29                 typedef enum {RED=0, BLUE=1, NONE=2, BOTH=3} Colour; //Used for the allegiance of the pieces - terrain counts as NONE.
30
31                 static Colour OppositeColour(const Colour & compare);
32         
33
34                 Piece(const Type & newType, const Colour & newColour) : type(newType), colour(newColour), beenRevealed(false) {}
35                 virtual ~Piece() {}
36
37
38                 //Operators compare the strength of two pieces
39                 bool operator==(const Piece & equ) const {return type == equ.type;}
40                 bool operator<(const Piece & equ) const {return type < equ.type;}
41                 bool operator>(const Piece & equ) const {return type > equ.type;}
42                 
43                 bool operator!=(const Piece & equ) const {return !operator==(equ);}
44                 bool operator<=(const Piece & equ) const {return (operator<(equ) || operator==(equ));}
45                 bool operator>=(const Piece & equ) const {return (operator>(equ) || operator==(equ));}
46
47                 //Contains the characters used to identify piece types when the board is printed to a stream
48                 static  char tokens[];
49                 static int maxUnits[];
50
51                 static Type GetType(char fromToken);
52
53                 int PieceValue() const {if (type == BOMB || type == FLAG) {return 0;} return (int)(type) - (int)(SPY) + 1;}
54
55                 //Attributes of the piece
56                 const Type type; 
57                 const Colour colour;
58
59                 bool beenRevealed;
60
61                 public:
62
63                         #ifdef BUILD_GRAPHICS
64                         class TextureManager : public Graphics::TextureManager<LUint>, private Array<Texture*>
65                         {
66                                 public:
67                                         TextureManager() : Graphics::TextureManager<LUint>(), Array<Texture*>() {}
68                                         virtual ~TextureManager();
69
70                                         virtual Texture & operator[](const LUint & at);
71                         };
72                         static TextureManager textures;
73
74                         static Graphics::Colour GetGraphicsColour(const Piece::Colour & colour)
75                         {
76                                 switch (colour)
77                                 {
78                                         case RED:
79                                                 return Graphics::Colour(1.0,0,0);
80                                                 break;
81                                         case BLUE:
82                                                 #ifdef __MACOSX__ //Horrible HACK to make pieces green on Mac OSX, because Blue doesn't exist on this operating system.
83                                                         return Graphics::Colour(0,1.0,0);
84                                                 #else
85                                                         return Graphics::Colour(0,0,1.0);
86                                                 #endif //__MACOSX__
87                                                 break;
88                                         case NONE:
89                                                 return Graphics::Colour(0.5,0.5,0.5);
90                                                 break;
91                                         case BOTH:
92                                                 return Graphics::Colour(1,0,1);
93                                                 break;
94                                 }
95                         }
96                         #endif //BUILD_GRAPHICS
97                         
98                         
99
100                 
101 };
102
103 #include "movementresult.h"
104
105 /**
106  * A Stratego board
107  */
108 class Board
109 {
110         public:
111                 Board(int newWidth, int newHeight); //Constructor
112
113                 virtual ~Board(); //Destructor
114
115                 void Print(FILE * stream, const Piece::Colour & reveal=Piece::BOTH); //Print board
116                 void PrintPretty(FILE * stream, const Piece::Colour & reveal=Piece::BOTH, bool showRevealed=true); //Print board using colour
117                 
118                 #ifdef BUILD_GRAPHICS
119                 void Draw(const Piece::Colour & reveal=Piece::BOTH, bool showRevealed = true); //Draw board
120                 #endif //BUILD_GRAPHICS
121
122                 bool AddPiece(int x, int y, const Piece::Type & newType, const Piece::Colour & newColour); //Add piece to board
123
124
125                 Piece * GetPiece(int x, int y); //Retrieve piece from a location on the board
126
127
128                 typedef enum {UP, DOWN, LEFT, RIGHT} Direction;
129
130                 
131                 
132                 static bool LegalResult(const MovementResult & result)
133                 {
134                         return (result == MovementResult::OK || result == MovementResult::DIES || result == MovementResult::KILLS || result == MovementResult::BOTH_DIE || result == MovementResult::VICTORY_FLAG || result == MovementResult::VICTORY_ATTRITION || result == MovementResult::DRAW || result == MovementResult::DRAW_DEFAULT || result == MovementResult::SURRENDER);
135                 }
136
137                 static bool HaltResult(const MovementResult & result)
138                 {
139                         return (result == MovementResult::VICTORY_FLAG || result == MovementResult::VICTORY_ATTRITION || result == MovementResult::DRAW || result == MovementResult::DRAW_DEFAULT || result == MovementResult::SURRENDER || !LegalResult(result));
140                 }               
141
142                 MovementResult MovePiece(int x, int y, const Direction & direction, int multiplier=1,const Piece::Colour & colour=Piece::NONE); //Move piece from position in direction
143         
144
145                 Piece::Colour winner;
146
147                 int Width() const {return width;}
148                 int Height() const {return height;}
149
150                 int MobilePieces(const Piece::Colour & colour) const;
151                 int TotalPieceValue(const Piece::Colour & colour) const;
152                 bool RemovePiece(Piece * piece);
153         private:
154                 int width;
155                 int height;
156                 Piece ** * board;
157                 std::vector<Piece*> pieces;
158 };
159
160 #endif //STRATEGO_H
161
162 //EOF
163
164

UCC git Repository :: git.ucc.asn.au