game(np, me, nd, nz)
np | int | 遊戲總人數 |
me | int | 自己的 ID |
nd | int | 玩家的無人機數量 |
nz | int | 此遊戲的戰區數量 |
Iter<Player> players
Iter of Player
輸出玩家的 ID
for(const Player & player : game.players) {
cerr << "Player #" << player.id << ':' << endl;
}
Iter<Zone> zones
Iter of Zone
輸入各個 zone 的位置
for(Zone & zone : game.zones) {
cin >> zone; cin.ignore();
}
Player & Me() const
得到自己的 Player
object
none
Player &
Player & player(int) const
透過 ID 得到某個 Player
object
Player &
Zone & zone(int) const
透過 ID 得到某個 Zone
object
Zone &
Iter<Drone> drones(const Player &, const Zone &) const
查詢某位玩家在某個 zone 裡的所有無人機
Iter<Drone>
void UpdateZones()
更新每個 zone 的佔領者,注意你需要在遊戲回合中呼叫它,請參考我們的 main.cpp
none
none
void Output() const
輸出自己每臺無人機的目標位置,注意你需要在遊戲回合中呼叫它,請參考我們的 main.cpp
none
none
Player & Controller(const Zone &) const
查詢某個 zone 的佔領者是誰
Player &
int Control(const Zone &) const
查詢某個 zone 當下最少需要派遣幾架無人機才能佔領
int
Zone & Trace(const Drone &) const
根據某臺無人機的動向預測他要去哪個 zone
Zone &
根據該無人機前進的方向,找尋夾角最小的 zone,如果沒有 zone 與前進方向夾角小於 90 度,則會回傳最近的 zone
void SocialDistancing() const
期間限定功能,讓每臺無人機維持社交距離
none
none
void StayHome() const
期間限定功能,讓每臺無人機進行長時間的居家隔離,大約會進行到遊戲結束
none
none
template<typename T, typename U> static void Sort(Iter<T> &, const U &)
根據與給定目標的距離,排序給定的 Iter,給定目標可以是一個 zone 或是一台 drone
none
template<typename T> static void Sort(Iter<T> &, bool (*)(const T &, const T &))
根據給定的 compare function,排序給定的 Iter
bool
type returnsnone
Iter<Drone> drones;
Iter of Drone
輸入 0 號玩家各個 drone 的位置
Player p = game.player(0);
for(Drone & drone : p.drones) {
cin >> drone; cin.ignore();
}
bool isControl(const Zone &) const;
判斷 Player 是否控制指定的 zone
判斷 0 號玩家是否控制 0 號 zone
Player p = game.player(0);
Player z = game.zone(0);
bool isControl = p.isContro(z);
Drone & drone(int) const;
取得某個 id 的 Drone
取得 0 號玩家的 0 號無人機物件
Player p = game.player(0);
Drone d = p.drone(0);
const int id {-1};
取得 Player 的 id
取得玩家的 id
Player p = game.player(0);
int id = p.id;
template <typename T> class Iter;
A Random-Access-Iterator template for double pointer
Iter
是我們類別庫中特色的容器,我們用 Iter 來儲存多個 Drones, Zones, Players, … Iter 除了可以像陣列一般使用 for loop 遍歷,我們也提供排序 Iter 的方法,在許多函式中我們會用 Iter 作為參數作為傳遞多個物件的方法,他有以下幾個 Member types,不感興趣的可以跳過。
difference_type | size_t |
value_type | T |
reference | T & |
pointer | T * |
pointer | T * |
iterator_category | std::random_access_iteratoe_tag |
difference_type size() const
回傳 Iter 內的元素數量
none
difference_type,
假設 drones 是一個 Iter of Drone
drones[0] = (Drone){123, 456};
reference operator[](difference_type) const;
您可以使用中括號存取 Iter 中的資料
Iter begin() const
Iter end() const
您可以使用 begin() 和 end() 作為排序的參數
Zone 是繼承 Coord 的類別,其中有
x
是區域的 x 座標
y
是區域的 y 座標
template<typename U> bool In(const U &) const
判斷是否距離目標小於等於 100 單位
bool
判斷這個 zone 這個物件是否距離 (0, 1) 這個 Drone 小於等於 100 。
Zone z = {123, 345};
z.In((Drone){0, 1});
template<typename U> int operator-(const U &) const
運算子,到其他物件 (Zone, Drone) 的距離平方。
回傳與座標 (123, 345) 這個無人機的距離平方
Zone z = game.zone(0);
Drone d = {123, 345};
int distance = d - z;
istream & operator>>(istream &, const Game &);
運算子重載用於 cin ,輸入座標 x, y
ostream & operator<<(ostream &, const Game &);
運算子重載用於 cout, cerr ,輸出座標 x, y
x
是無人機的 x 座標
y
是無人機的 y 座標
template<typename U> bool In(const U &) const
判斷是否距離目標小於等於 100 單位
bool
判斷這個 drone 這個物件是否距離 (0, 1) 這個 Zone 小於等於 100 。
Drone d = {123, 345};
d.In((Zone){0, 1});
template<typename U> int operator-(const U &) const;
運算子,到其他物件 (Zone, Drone) 的距離平方。
回傳與 Drone d 的距離平方
Drone d = {123, 345};
int distance = d - (Zone)(11, 26);
istream & operator>>(istream &, const Game &);
運算子重載用於 cin ,輸入座標 x, y
ostream & operator<<(ostream &, const Game &);
運算子重載用於 cout, cerr ,輸出座標 x, y
紀錄一個座標點,被 Drone, Zone 繼承
還有一堆運算子重載,有興趣可以看 Source Code XD
x
是區域的 x 座標
y
是區域的 y 座標