Skip to content

Commit 948f577

Browse files
committed
feat: abilities
1 parent ce8ccff commit 948f577

File tree

11 files changed

+93
-36
lines changed

11 files changed

+93
-36
lines changed

cpp/main.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
std::ostringstream all_logs;
44

5+
//make global object for holding all ids of attackers whose abilities activated
6+
57
void init_constants() {
68
// All the attacker types
79
std::cin >> Constants::NO_OF_ATTACKER_TYPES;
810

911
std::unordered_map<size_t, Attributes> attacker_type_to_attributes;
1012
for (size_t i = 1; i <= Constants::NO_OF_ATTACKER_TYPES; i++) {
11-
unsigned hp, range, attack_power, speed, price, is_aerial , weight;
12-
std::cin >> hp >> range >> attack_power >> speed >> price >> is_aerial >> weight;
13+
unsigned hp, range, attack_power, speed, price, is_aerial , weight, num_ability_turns, ability_activation_cost;
14+
std::cin >> hp >> range >> attack_power >> speed >> price >> is_aerial >> weight >> num_ability_turns >> ability_activation_cost;
1315
attacker_type_to_attributes.insert(
14-
std::make_pair(i, Attributes(hp, range, attack_power, speed, price, is_aerial,weight)));
16+
std::make_pair(i, Attributes(hp, range, attack_power, speed, price, is_aerial,weight, num_ability_turns,ability_activation_cost)));
1517
}
1618
Constants::ATTACKER_TYPE_ATTRIBUTES = attacker_type_to_attributes;
1719

@@ -23,7 +25,7 @@ void init_constants() {
2325
unsigned hp, range, attack_power, speed, price, is_aerial;
2426
std::cin >> hp >> range >> attack_power >> speed >> price >> is_aerial;
2527
defender_type_to_attributes.insert(
26-
std::make_pair(i, Attributes(hp, range, attack_power, speed, price, is_aerial,0)));
28+
std::make_pair(i, Attributes(hp, range, attack_power, speed, price, is_aerial,0,0,0)));
2729
}
2830
Constants::DEFENDER_TYPE_ATTRIBUTES = defender_type_to_attributes;
2931
}
@@ -47,6 +49,7 @@ void output(size_t turn_no, Game &game) {
4749
// Game details logged
4850
const auto &spawn_positions = game.get_spawn_positions();
4951
const auto &player_set_targets = game.get_player_set_targets();
52+
const auto &ability_activations = game.get_ability_activations();
5053

5154
std::cout << spawn_positions.size() << std::endl;
5255
for (const auto &entry : spawn_positions) {
@@ -58,6 +61,11 @@ void output(size_t turn_no, Game &game) {
5861
for (const auto &entry : player_set_targets) {
5962
std::cout << entry.first << " " << entry.second << std::endl;
6063
}
64+
65+
std::cout << ability_activations.size() << std::endl;
66+
for (const auto &attacker_id : ability_activations) {
67+
std::cout << attacker_id << std::endl;
68+
}
6169
}
6270

6371
void dump_logs(State &state, Game &game) {}
@@ -71,9 +79,9 @@ State next_state(size_t cur_turn_no) {
7179
std::cin >> no_of_active_attackers;
7280
std::vector<Attacker> attackers;
7381
for (size_t i = 0; i < no_of_active_attackers; i++) {
74-
size_t id, hp, x, y, type;
75-
std::cin >> id >> x >> y >> type >> hp;
76-
attackers.push_back(Attacker(id, hp, type, Position(x, y)));
82+
size_t id, hp, x, y, type, is_ability_active;
83+
std::cin >> id >> x >> y >> type >> hp >> is_ability_active;
84+
attackers.push_back(Attacker(id, hp, type, Position(x, y), is_ability_active));
7785
}
7886

7987
std::cin >> no_of_active_defenders;
@@ -97,17 +105,17 @@ PvPState pvp_next_state(size_t cur_turn_no) {
97105
std::cin >> no_of_active_attackers;
98106
std::vector<Attacker> attackers;
99107
for (size_t i = 0; i < no_of_active_attackers; i++) {
100-
size_t id, hp, x, y, type;
101-
std::cin >> id >> x >> y >> type >> hp;
102-
attackers.push_back(Attacker(id, hp, type, Position(x, y)));
108+
size_t id, hp, x, y, type, is_ability_active;
109+
std::cin >> id >> x >> y >> type >> hp >> is_ability_active;
110+
attackers.push_back(Attacker(id, hp, type, Position(x, y), is_ability_active));
103111
}
104112

105113
std::cin >> no_of_opponent_attackers;
106114
std::vector<Attacker> opponent_attackers;
107115
for (size_t i = 0; i < no_of_opponent_attackers; i++) {
108-
size_t id, hp, x, y, type;
109-
std::cin >> id >> x >> y >> type >> hp;
110-
opponent_attackers.push_back(Attacker(id, hp, type, Position(x, y)));
116+
size_t id, hp, x, y, type, is_ability_active;
117+
std::cin >> id >> x >> y >> type >> hp >> is_ability_active;
118+
opponent_attackers.push_back(Attacker(id, hp, type, Position(x, y), is_ability_active));
111119
}
112120

113121
return {move(attackers), move(opponent_attackers), Constants::PVP_FIXED_COINS, cur_turn_no + 1};

cpp/player_code.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#include <vector>
1111

1212
Attributes::Attributes(unsigned hp, unsigned range, unsigned attack_power,
13-
unsigned speed, unsigned price, unsigned is_aerial, unsigned weight)
13+
unsigned speed, unsigned price, unsigned is_aerial, unsigned weight, unsigned num_ability_turns, unsigned ability_activation_cost)
1414
: hp(hp), range(range), attack_power(attack_power), speed(speed),
15-
price(price), is_aerial(is_aerial), weight(weight) {}
15+
price(price), is_aerial(is_aerial), weight(weight), num_ability_turns(num_ability_turns), ability_activation_cost(ability_activation_cost) {}
1616

1717
Position::Position(int x, int y) : _x(x), _y(y) {}
1818

@@ -73,8 +73,8 @@ size_t Actor::get_hp() const { return _hp; }
7373
size_t Actor::get_type() const { return _type; }
7474
Position Actor::get_position() const { return _position; }
7575

76-
Attacker::Attacker(size_t id, size_t hp, size_t type, Position pos)
77-
: Actor(id, hp, type, pos) {}
76+
Attacker::Attacker(size_t id, size_t hp, size_t type, Position pos, size_t is_ability_active)
77+
: Actor(id, hp, type, pos), is_ability_active(is_ability_active) {}
7878

7979
Defender::Defender(size_t id, size_t hp, size_t type, Position pos)
8080
: Actor(id, hp, type, pos) {}
@@ -128,6 +128,10 @@ void Game::set_target(const Attacker &attacker, const Attacker &opponent) {
128128
this->_player_set_targets.insert({attacker.get_id(), opponent.get_id()});
129129
}
130130

131+
void Game::activate_ability(size_t attacker_id) {
132+
this->_ability_activations.push_back(attacker_id);
133+
}
134+
131135
std::ostringstream &Game::logr() { return this->_logr; }
132136

133137
const std::unordered_map<size_t, size_t> &Game::get_player_set_targets() const {
@@ -141,6 +145,10 @@ const std::set<Position> &Game::get_already_spawned_positions() const {
141145
return this->_already_spawned_positions;
142146
}
143147

148+
const std::vector<size_t> &Game::get_ability_activations() const {
149+
return this->_ability_activations;
150+
}
151+
144152
Map::Map(std::vector<std::vector<int>> map_as_grid)
145153
: _grid(move(map_as_grid)) {}
146154

cpp/player_code.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ struct Attributes {
1515
const unsigned price;
1616
const unsigned is_aerial;
1717
const unsigned weight;
18+
const unsigned num_ability_turns;
19+
const unsigned ability_activation_cost;
1820
Attributes(unsigned hp, unsigned range, unsigned attack_power, unsigned speed,
19-
unsigned price, unsigned is_aerial, unsigned weight);
21+
unsigned price, unsigned is_aerial, unsigned weight, unsigned num_ability_turns, unsigned ability_activation_cost);
2022
};
2123

2224
struct Constants {
@@ -71,7 +73,8 @@ class Actor {
7173

7274
class Attacker : public Actor {
7375
public:
74-
Attacker(size_t id, size_t hp, size_t type, Position pos);
76+
Attacker(size_t id, size_t hp, size_t type, Position pos, size_t is_ability_active);
77+
size_t is_ability_active;
7578
};
7679

7780
class Defender : public Actor {
@@ -119,16 +122,19 @@ class Game {
119122
void set_target(size_t attacker_id, size_t defender_id);
120123
void set_target(const Attacker &attacker, const Defender &defender);
121124
void set_target(const Attacker &attacker, const Attacker &opponent);
125+
void activate_ability(size_t attacker_id);
122126
std::ostringstream &logr();
123127

124128
const std::unordered_map<size_t, size_t> &get_player_set_targets() const;
125129
const std::vector<std::pair<size_t, Position>> &get_spawn_positions() const;
126130
const std::set<Position> &get_already_spawned_positions() const;
131+
const std::vector<size_t> &get_ability_activations() const;
127132
private:
128133
std::unordered_map<size_t, size_t> _player_set_targets;
129134
std::vector<std::pair<size_t, Position>> _spawn_postions;
130135
std::set<Position> _already_spawned_positions;
131-
136+
std::vector<size_t> _ability_activations;
137+
132138
std::ostringstream _logr;
133139
};
134140

cpp/run

2.44 MB
Binary file not shown.

java/Attacker.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
public class Attacker extends Actor {
2-
public Attacker(int id, int hp, int type, Position pos) {
2+
public final int is_ability_active;
3+
public Attacker(int id, int hp, int type, Position pos, int is_ability_active) {
34
super(id, hp, type, pos);
5+
this.is_ability_active = is_ability_active;
46
}
57
}

java/Attributes.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ public class Attributes {
66
public final int price;
77
public final int is_aerial;
88
public final int weight;
9+
public final int num_ability_turns;
10+
public final int ability_activation_cost;
911

10-
public Attributes(int hp, int range, int attackPower, int speed, int price, int is_aerial, int weight) {
12+
public Attributes(int hp, int range, int attackPower, int speed, int price, int is_aerial, int weight, int num_ability_turns, int ability_activation_cost) {
1113
this.hp = hp;
1214
this.range = range;
1315
this.attackPower = attackPower;
1416
this.speed = speed;
1517
this.price = price;
1618
this.is_aerial = is_aerial;
1719
this.weight = weight;
20+
this.num_ability_turns = num_ability_turns;
21+
this.ability_activation_cost = ability_activation_cost;
1822
}
1923
}

java/Game.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,25 @@ public class Game {
1010
private final List<SpawnDetail> _spawnPositions;
1111
private final Set<Position> _alreadySpawnedPositions;
1212
private final StringBuilder _logr;
13+
private final List<Integer> _ability_activations;
1314

1415
public Game() {
1516
_playerSetTargets = new HashMap<>();
1617
_spawnPositions = new ArrayList<>();
1718
_alreadySpawnedPositions = new HashSet<>();
1819
_logr = new StringBuilder();
20+
_ability_activations = new ArrayList<>();
1921
}
2022

2123
public void spawnAttacker(int id, Position pos) {
2224
_spawnPositions.add(new SpawnDetail(id, pos));
2325
_alreadySpawnedPositions.add(pos);
2426
}
2527

28+
public void activateAbility(int attacker_id) {
29+
_ability_activations.add(attacker_id);
30+
}
31+
2632
public List<SpawnDetail> getSpawnPositions() {
2733
return _spawnPositions;
2834
}
@@ -31,6 +37,10 @@ public Map<Integer, Integer> getPlayerSetTargets() {
3137
return _playerSetTargets;
3238
}
3339

40+
public List<Integer> getAbilityActivations() {
41+
return _ability_activations;
42+
}
43+
3444
public boolean alreadySpawnedAtPosition(Position pos) {
3545
return _alreadySpawnedPositions.contains(pos);
3646
}

java/Main.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ private static State nextState(int currentTurnNo) {
3232
List<Attacker> attackers = new ArrayList<>();
3333
for (int i = 0; i < noOfActiveAttackers; i++) {
3434
attackers.add(
35-
new Attacker(in.nextInt(), in.nextInt(), in.nextInt(), new Position(in.nextInt(), in.nextInt())));
35+
new Attacker(in.nextInt(), in.nextInt(), in.nextInt(), new Position(in.nextInt(), in.nextInt()), in.nextInt()));
3636
}
3737

3838
int noOfActiveDefenders = in.nextInt();
@@ -52,14 +52,14 @@ private static PvPState nextPvPState(int currentTurnNo) {
5252
List<Attacker> attackers = new ArrayList<>();
5353
for (int i = 0; i < noOfActiveAttackers; i++) {
5454
attackers.add(
55-
new Attacker(in.nextInt(), in.nextInt(), in.nextInt(), new Position(in.nextInt(), in.nextInt())));
55+
new Attacker(in.nextInt(), in.nextInt(), in.nextInt(), new Position(in.nextInt(), in.nextInt()), in.nextInt()));
5656
}
5757

5858
int noOfActiveOpponentAttackers = in.nextInt();
5959
List<Attacker> opponentAttackers = new ArrayList<>();
6060
for (int i = 0; i < noOfActiveOpponentAttackers; i++) {
6161
opponentAttackers.add(
62-
new Attacker(in.nextInt(), in.nextInt(), in.nextInt(), new Position(in.nextInt(), in.nextInt())));
62+
new Attacker(in.nextInt(), in.nextInt(), in.nextInt(), new Position(in.nextInt(), in.nextInt()),in.nextInt()));
6363
}
6464

6565
return new PvPState(attackers, opponentAttackers, Constants.PVP_FIXED_COINS, currentTurnNo + 1);
@@ -90,6 +90,7 @@ private static void output(int turnNo, Game game) {
9090
}
9191

9292
List<SpawnDetail> spawnPositions = game.getSpawnPositions();
93+
List<Integer> abilityActivations = game.getAbilityActivations();
9394

9495
System.out.println(spawnPositions.size());
9596
for (SpawnDetail entry : spawnPositions) {
@@ -101,6 +102,11 @@ private static void output(int turnNo, Game game) {
101102
for (Map.Entry<Integer, Integer> entry : playerSetTargets.entrySet()) {
102103
System.out.println(entry.getKey() + " " + entry.getValue());
103104
}
105+
106+
System.out.println(abilityActivations.size());
107+
for (Integer attacker_id : abilityActivations) {
108+
System.out.println(attacker_id);
109+
}
104110
}
105111

106112
public static void main(String[] args) {
@@ -123,14 +129,14 @@ public static void main(String[] args) {
123129
Constants.ATTACKER_TYPE_ATTRIBUTES = new HashMap<Integer, Attributes>();
124130
for (int i = 1; i <= Constants.NO_OF_ATTACKER_TYPES; i++) {
125131
Constants.ATTACKER_TYPE_ATTRIBUTES.put(i,
126-
new Attributes(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt()));
132+
new Attributes(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt()));
127133
}
128134

129135
Constants.NO_OF_DEFENDER_TYPES = in.nextInt();
130136
Constants.DEFENDER_TYPE_ATTRIBUTES = new HashMap<Integer, Attributes>();
131137
for (int i = 1; i <= Constants.NO_OF_DEFENDER_TYPES; i++) {
132138
Constants.DEFENDER_TYPE_ATTRIBUTES.put(i,
133-
new Attributes(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(),0));
139+
new Attributes(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(),0,0,0));
134140
}
135141

136142
switch (gameType) {

python/main.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,20 @@ def output(turn_no: int, game: Game):
2929
sys.stdout.write(f"{len(game.player_set_targets)}\n")
3030
for (attacker_id, defender_id) in game.player_set_targets.items():
3131
sys.stdout.write(f"{attacker_id} {defender_id}\n")
32-
32+
33+
sys.stdout.write(f"{len(game.ability_activations)}\n")
34+
for attacker_id in game.ability_activations:
35+
sys.stdout.write(f"{attacker_id}\n")
3336

3437

3538
def next_state(cur_turn_no: int) -> State:
3639
no_of_active_attackers = int(sys.stdin.readline())
3740
attackers = []
3841

3942
for _ in range(no_of_active_attackers):
40-
id, x, y, a_type, hp = map(int, sys.stdin.readline().split())
43+
id, x, y, a_type, hp, is_ability_active = map(int, sys.stdin.readline().split())
4144
attackers.append(
42-
Attacker(id, hp, Constants.ATTACKER_TYPE_ATTRIBUTES[a_type], Position(x, y))
45+
Attacker(id, hp, Constants.ATTACKER_TYPE_ATTRIBUTES[a_type], Position(x, y), is_ability_active)
4346
)
4447

4548
no_of_active_defenders = int(sys.stdin.readline())
@@ -60,18 +63,18 @@ def next_pvp_state(cur_turn_no: int) -> PvPState:
6063
attackers = []
6164

6265
for _ in range(no_of_active_attackers):
63-
id, x, y, a_type, hp = map(int, sys.stdin.readline().split())
66+
id, x, y, a_type, hp, is_ability_active = map(int, sys.stdin.readline().split())
6467
attackers.append(
65-
Attacker(id, hp, Constants.ATTACKER_TYPE_ATTRIBUTES[a_type], Position(x, y))
68+
Attacker(id, hp, Constants.ATTACKER_TYPE_ATTRIBUTES[a_type], Position(x, y), is_ability_active)
6669
)
6770

6871
no_of_opponent_attackers = int(sys.stdin.readline())
6972
opponent_attackers = []
7073

7174
for _ in range(no_of_opponent_attackers):
72-
id, x, y, d_type, hp = map(int, sys.stdin.readline().split())
75+
id, x, y, d_type, hp, is_ability_active = map(int, sys.stdin.readline().split())
7376
opponent_attackers.append(
74-
Attacker(id, hp, Constants.DEFENDER_TYPE_ATTRIBUTES[d_type], Position(x, y))
77+
Attacker(id, hp, Constants.DEFENDER_TYPE_ATTRIBUTES[d_type], Position(x, y), is_ability_active)
7578
)
7679

7780
return PvPState(attackers, opponent_attackers, Constants.PVP_FIXED_COINS, cur_turn_no + 1)

python/player_code.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class ActorType:
2929
class AttackerType(ActorType):
3030
speed: int
3131
weight: int
32+
num_ability_turns: int
33+
ability_activation_cost: int
3234

3335

3436
@dataclass(frozen=True)
@@ -42,6 +44,7 @@ class Attacker:
4244
hp: int
4345
type: AttackerType
4446
position: Position
47+
is_ability_active: int
4548

4649

4750
@dataclass(frozen=True)
@@ -72,6 +75,7 @@ def __init__(self):
7275
self.player_set_targets: dict[int, int] = {}
7376
self.spawn_positions: list[tuple[int, Position]] = []
7477
self.already_spawned_positions: set[Position] = set()
78+
self.ability_activations: list[int] = []
7579

7680
def spawn_attacker(self, id: int, position: Position):
7781
self.spawn_positions.append((id, position))
@@ -85,6 +89,10 @@ def set_target(self, attacker_id: int, defender_id: int):
8589
assert (type(defender_id)== int)
8690
self.player_set_targets[attacker_id] = defender_id
8791

92+
def activate_ability(self, attacker_id: int):
93+
assert (type(attacker_id)== int)
94+
self.ability_activations.append(attacker_id)
95+
8896
def log(self, line: str):
8997
self._log += line + "\n"
9098

@@ -117,9 +125,9 @@ def initialize(cls,game_type:GameType):
117125
cls.NO_OF_ATTACKER_TYPES = int(input())
118126
cls.ATTACKER_TYPE_ATTRIBUTES = {}
119127
for i in range(1, cls.NO_OF_ATTACKER_TYPES + 1):
120-
hp, a_range, attack_power, speed, price, is_aerial, weight = map(int, input().split())
128+
hp, a_range, attack_power, speed, price, is_aerial, weight, num_ability_turns, ability_activation_cost = map(int, input().split())
121129
cls.ATTACKER_TYPE_ATTRIBUTES[i] = AttackerType(
122-
hp, a_range, attack_power, price, is_aerial, speed, weight
130+
hp, a_range, attack_power, price, is_aerial, speed, weight, num_ability_turns, ability_activation_cost
123131
)
124132

125133
cls.NO_OF_DEFENDER_TYPES = int(input())

0 commit comments

Comments
 (0)