stocks / battle.h
battle.h
Raw
// Project identifier: 9504853406CBAC39EE89AA3AD238AA12CA198043
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <getopt.h>
#include <sstream>
#include <unistd.h>
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <ctype.h>
#include <algorithm>
#include "input.h"

using namespace std;

struct Zombie{
    string name;
    int distance;
    int speed;
    uint32_t health;
    int rounds_active;
};

//comparators for PQ
class ZombieOrder{
    public:
    bool operator()(Zombie &lhs, Zombie &rhs) const {
    //if eta is the same
    if((lhs.distance / lhs.speed) == (rhs.distance / rhs.speed)){
        //use health
        if(lhs.health != rhs.health){
            return lhs.health > rhs.health;
        }
        //if health is same
        else{
            return lhs.name > rhs.name;
        }
    }
    else {
        return (lhs.distance / lhs.speed) > (rhs.distance / rhs.speed);
    }
  }
};

//comparators for PQ
class ActiveOrder{
    public:
    bool operator()(Zombie &lhs, Zombie &rhs) const {
    //if eta is the same
    if((lhs.rounds_active) == (rhs.rounds_active)){
            return lhs.name > rhs.name;
    }
    else {
        return lhs.rounds_active < rhs.rounds_active;
    }
  }
};

class ReverseActiveOrder{
    public:
    bool operator()(Zombie &lhs, Zombie &rhs) const {
    //if eta is the same
    if((lhs.rounds_active) == (rhs.rounds_active)){
            return lhs.name > rhs.name;
    }
    else {
        return lhs.rounds_active > rhs.rounds_active;
    }
  }
};

class Game{
    public:
    uint32_t quiver_cap;
    int current_round;
    int num_active;
    bool get_median;
    //containers
    priority_queue<Zombie, vector<Zombie>, ZombieOrder > zombie_queue;
    priority_queue<Zombie, vector<Zombie>, ActiveOrder > active_queue;
    priority_queue<Zombie, vector<Zombie>, ReverseActiveOrder > rev_active_queue;
    deque<Zombie> killed_zombies;
    deque<Zombie> zombies;
    Game(): quiver_cap(0), current_round(0), num_active(0), get_median(false){}
};

// UTILITIES
//clears pq
void clear_pq(priority_queue<Zombie, vector<Zombie>, ZombieOrder> &zombie_queue);
//initialize
void initialize(Game &game);
//return zombie index
size_t get_zombie(const Zombie &top, deque<Zombie> &zombies);
//increment rounds active
void inc_rounds_active(Game &game);

// FUNCTIONS 
// create zombies
void create_zombies(uint32_t &rand_zomb, uint32_t &named_zomb, deque<Zombie> &zombies, Line_args &line_args, string &junk);
// advance zombies
void advance_zombies(Game &game, Line_args &line_args, bool &game_over);
// load zombies to PQ
void load_zombies(Game &game);
// shoot zombies
void shoot_zombies(uint32_t &quiver, Game &game, Line_args &line_args, string &last_killed);

// MEDIAN
void print_median(Game &game);

// VERBOSE
// output Zombie Creation
void verbose_create(Zombie &zombie);
// output Zombie Destruction
void verbose_destroy(Zombie &zombie);
// print victory
void print_victory(int &current_round, string &last_killed);
// print defeat
void print_defeat(int &current_round, deque<Zombie> &zombies, size_t &killer_zombie);

// STATS
// print still active
void print_still_active(Game &game);
// resets killed zombie container
void reset_killed_zombies(Game &game, deque<Zombie> &reset);
// loads active queue with all zombies
void load_active_queue(Game &game);
// loads rev active queue with all zombies
void load_rev_active_queue(Game &game);
// print killed zombies
void print_killed_zombies(Game &game, Line_args &line_args);
// print stats
void print_stats(Game &game, Line_args &line_args);
// TESTING //
// TESTING //