Skip to content

Commit 4147f6d

Browse files
create attacks field for game status
1 parent 6baf779 commit 4147f6d

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

map.config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Map Details
2-
WORKER_ANT_INITIAL_HEALTH = 3
3-
SOLDIER_ANT_INITIAL_HEALTH = 5
2+
WORKER_ANT_INITIAL_HEALTH = 10
3+
SOLDIER_ANT_INITIAL_HEALTH = 10
44
COLONY_INITIAL_BREAD = 0
55
COLONY_INITIAL_GRASS = 0
66
GENERATE_WORKER_BREAD_AMOUNT = 10
@@ -21,6 +21,6 @@ WORKER_MAX_CARRYING_RESOURCE_AMOUNT = 10;
2121

2222
# SCORPION = Soldier, ANT = Worker :)
2323
INIT_SCORPIONS = 0
24-
INIT_ANTS = 4
24+
INIT_ANTS = 2
2525

2626
READ_MAP_FROM_FILE = true

src/main/java/ir/sharif/aichallenge/server/logic/dto/payloads/GameStatusDTO.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class GameStatusDTO {
1616
int current_resource_value;
1717
int current_resource_type;
1818
int health;
19+
AttackDTO[] attacks;
1920

2021
public GameStatusDTO(Game game, Integer antID) {
2122
Ant currentAnt = game.getAntByID(antID);
@@ -29,16 +30,16 @@ public GameStatusDTO(Game game, Integer antID) {
2930
.map(x -> new AroundCell(x, currentAnt)).toArray(AroundCell[]::new);
3031
this.chat_box = game.getColony(currentAnt.getColonyId()).getChatBox().getChatMessages().stream()
3132
.map(ChatBoxMessageDTO::new).toArray(ChatBoxMessageDTO[]::new);
33+
List<AttackDTO> nearByAttacks = getNearByAttacks(game, antID);
34+
this.attacks = nearByAttacks.toArray(new AttackDTO[nearByAttacks.size()]);
3235
}
3336
}
3437

3538
private List<AttackDTO> getNearByAttacks(Game game, Integer ant_id) {
3639
Ant ant = game.getAntByID(ant_id);
3740
List<AttackSummary> attackSummaries = game.getAttackHandler().getNearByAttacks(ant_id);
3841
return attackSummaries.stream()
39-
.map(x -> new AttackDTO(x.src_row, x.src_col,
40-
x.dst_col, x.dst_row,
41-
isAttackerEnemy(game, ant, x)))
42+
.map(x -> new AttackDTO(x.src_row, x.src_col, x.dst_col, x.dst_row, isAttackerEnemy(game, ant, x)))
4243
.collect(Collectors.toList());
4344
}
4445

0 commit comments

Comments
 (0)