/* * Copyright (c) 2010 Daniel Hartmeier * All rights reserved. * */ #ifndef __BOARD_H__ #define __BOARD_H__ #include #include using namespace std; #ifdef DEBUG extern FILE *logfile; #define debug(format, ...) do { fprintf(stderr, format, ## __VA_ARGS__); \ fprintf(logfile, format, ##__VA_ARGS__); \ fflush(logfile); } while (0) #else #define debug(format, ...) #endif enum RESULT { LOSS=0, UNDECIDED=1, DRAW=2, WIN=3 }; static inline unsigned long usec() { static struct timeval tv; gettimeofday(&tv, NULL); return tv.tv_sec * 1000000 + tv.tv_usec; } class Planet { public: Planet(int id, int owner, int ships, int growth, double x, double y) : id(id), owner(owner), ships(ships), growth(growth), x(x), y(y) {} int getId() const { return id; } int getOwner() const { return owner; } void setOwner(int owner) { this->owner = owner; } int getShips() const { return ships; } void setShips(int ships) { this->ships = ships; } int getGrowth() const { return growth; } double getX() const { return x; } double getY() const { return y; } private: int id, owner, ships, growth; double x, y; }; class Fleet { public: Fleet(int owner, int ships, int src, int dst, int len, int remain) : owner(owner), ships(ships), src(src), dst(dst), len(len), remain(remain) {} int getOwner() const { return owner; } int getShips() const { return ships; } void setShips(int ships) { this->ships = ships; } int getSrc() const { return src; } int getDst() const { return dst; } int getLen() const { return len; } int getRemain() const { return remain; } int decrementRemain() { return --remain; } private: int owner, ships, src, dst, len, remain; }; class Board { public: Board(const char *s); Board(const Board &o) : planets(o.planets), fleets(o.fleets) {} Board &operator=(const Board &o) { planets = o.planets; fleets = o.fleets; return *this; } void makeTurn(); bool issueOrder(int player, int src, int dst, int ships); void nextTurn(); int distance(int src, int dst) const; RESULT rate() const; const vector &getPlanets() const { return planets; } const vector &getFleets() const { return fleets; } private: vector planets; vector fleets; }; #endif