-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip:pvp * feat: pvp main, fds * feat: pvp * feat: pvp logger,attackers * feat:pvp * update: loggers * feat: unit tests for pvpgame and pvpattacker (#3) * wip: pvp tests * feat: unit tests for pvp * feat: abilities (#2) * feat: invuln ability * fix: main & tests * fix: include cassert * move ability into attacker class * modify attribute dict * update comparator * fix: comparator takes ability to account * add tests for attacker abilities * fix: minor fixes * fix: integrate with abilities --------- Co-authored-by: shubham-1806 <[email protected]> --------- Co-authored-by: Bhoopesh <[email protected]> Co-authored-by: Nithin Balan <[email protected]> Co-authored-by: Avyyukt Ajith <[email protected]>
- Loading branch information
1 parent
b1b6a09
commit f0edee8
Showing
34 changed files
with
1,767 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,3 @@ build/ | |
compile_commands.json | ||
.cache | ||
.vscode | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
add_subdirectory(pvpattacker) | ||
target_sources(cc_simulator PRIVATE attacker.cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target_sources(cc_simulator PRIVATE pvpattacker.cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include "attacker/pvpattacker/pvpattacker.hpp" | ||
#include "logger/pvplogger.hpp" | ||
#include "utils/attributes.hpp" | ||
|
||
#include <algorithm> | ||
|
||
PvPAttacker PvPAttacker::construct(AttackerType type, Position p, Owner owner) { | ||
Attributes attr = Attacker::attribute_dictionary[type]; | ||
return {type, p, | ||
attr.hp, attr.range, | ||
attr.speed, attr.attack_power, | ||
attr.price, attr.is_aerial, | ||
owner, PvPAttacker::State::SPAWNED}; | ||
} | ||
|
||
Owner PvPAttacker::get_owner() const { return this->_owner; } | ||
|
||
[[nodiscard]] std::optional<size_t> PvPAttacker::get_nearest_defender_index( | ||
const std::vector<PvPAttacker> &defenders) const { | ||
if (defenders.empty()) { | ||
return std::nullopt; | ||
} | ||
if (this->is_aerial_type()) { | ||
auto nearest_attacker = std::min_element( | ||
defenders.begin(), defenders.end(), | ||
[this](const PvPAttacker a, const PvPAttacker b) { | ||
if (a.is_aerial_type() && !b.is_aerial_type() && | ||
this->is_in_range(a)) { | ||
return true; | ||
} | ||
if (b.is_aerial_type() && !a.is_aerial_type() && | ||
this->is_in_range(b)) { | ||
return false; | ||
} | ||
return this->get_position().distance_to(a.get_position()) < | ||
this->get_position().distance_to(b.get_position()); | ||
}); | ||
return std::distance(defenders.begin(), nearest_attacker); | ||
} | ||
auto nearest_attacker = std::min_element( | ||
defenders.begin(), defenders.end(), | ||
[this](const PvPAttacker a, const PvPAttacker b) { | ||
if (a.is_aerial_type() && !b.is_aerial_type()) { | ||
return false; | ||
} | ||
if (b.is_aerial_type() && !a.is_aerial_type()) { | ||
return true; | ||
} | ||
return this->get_position().distance_to(a.get_position()) < | ||
this->get_position().distance_to(b.get_position()); | ||
}); | ||
if (!nearest_attacker->is_aerial_type()) { | ||
return std::distance(defenders.begin(), nearest_attacker); | ||
} | ||
|
||
return std::nullopt; | ||
} | ||
|
||
void PvPAttacker::log_death() const { | ||
PvPLogger::log_dead(this->get_id(), this->_owner); | ||
} | ||
|
||
void PvPAttacker::log_move(Position &p) const { | ||
PvPLogger::log_move(this->get_id(), p.get_x(), p.get_y(), this->_owner); | ||
} | ||
|
||
void PvPAttacker::log_shoot(Actor &opponent) const { | ||
PvPLogger::log_shoot(this->get_id(), opponent.get_id(), opponent.get_hp(), | ||
this->_owner); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma once | ||
|
||
#include "attacker/attacker.hpp" | ||
#include "utils/attributes.hpp" | ||
|
||
#include <optional> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
enum class Owner { PLAYER1, PLAYER2 }; | ||
|
||
class PvPAttacker : public Attacker { | ||
public: | ||
static inline std::unordered_map<AttackerType, unsigned> | ||
pvp_weight_dictionary; | ||
|
||
PvPAttacker(AttackerType type, Position position, unsigned hp, unsigned range, | ||
unsigned speed, unsigned attack_power, unsigned price, | ||
bool is_aerial, Owner owner, State state = State::SPAWNED) | ||
: Attacker{type, position, hp, range, speed, | ||
attack_power, price, is_aerial, state}, | ||
_owner(owner) {} | ||
|
||
[[nodiscard]] Owner get_owner() const; | ||
|
||
[[nodiscard]] static PvPAttacker construct(AttackerType type, Position p, | ||
Owner owner); | ||
|
||
// TODO: make this function properly follow the rules of polymorphism | ||
[[nodiscard]] std::optional<size_t> | ||
get_nearest_defender_index(const std::vector<PvPAttacker> &defenders) const; | ||
|
||
void log_death() const override final; | ||
|
||
void log_move(Position &p) const override final; | ||
|
||
void log_shoot(Actor &opponent) const override final; | ||
|
||
private: | ||
Owner _owner; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
target_sources(cc_simulator PRIVATE game.cpp) | ||
target_sources(cc_simulator PRIVATE pvpgame.cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.