Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
AminHP committed Oct 27, 2019
1 parent b149e0a commit 5d75775
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 106 deletions.
2 changes: 1 addition & 1 deletion CppClient/Game/gamecfg.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"": "creating a new decision thread each time a snapshot of game is received from server",
"create_new_thread": true,
"agent_name": "0",
"team_nickname": "BabyKnight",
"team_nickname": "Team1",
"token": "team_id1-xx"
}
}
5 changes: 1 addition & 4 deletions JavaClient/gamecfg.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"general": {
"command_files": [
"ks/commands"
],
"offline_mode": true
},

Expand All @@ -18,7 +15,7 @@
"": "creating a new decision thread each time a snapshot of game is received from server",
"create_new_thread": true,
"agent_name": "0",
"team_nickname": "BabyKnight",
"team_nickname": "Team1",
"token": "team_id1-xx"
}
}
138 changes: 69 additions & 69 deletions JavaClient/src/ai/AI.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,62 +22,62 @@ public void decide() {
System.out.println("decide");

if (this.mySide.equals("Police")) {
for (Police police : this.world.getPolices())
{
if (police.getStatus() == EAgentStatus.Dead)
continue;

boolean doingBombOperation = police.getDefusionRemainingTime() != -1;
if (doingBombOperation)
{
System.out.println("Agent[" + police.getId() + "]: " + "Continue Bomb Operation");
continue;
}

ECommandDirection bombsiteDirection = findBombsiteDirection(police.getPosition());
if (bombsiteDirection == null)
{
System.out.println("Agent[" + police.getId() + "]: " + "Random Move");
int randIndex = (int) (Math.random() * ECommandDirection.values().length);
ECommandDirection randDir = ECommandDirection.values()[randIndex];
move(police.getId(), randDir);
}
else
{
System.out.println("Agent[" + police.getId() + "]: " + "Start Bomb Operation");
defuse(police.getId(), bombsiteDirection);
}
}
}
else
{
for (Terrorist terrorist : this.world.getTerrorists())
{
if (terrorist.getStatus() == EAgentStatus.Dead)
continue;

boolean doingBombOperation = terrorist.getPlantingRemainingTime() != -1;
if (doingBombOperation)
{
System.out.println("Agent[" + terrorist.getId() + "]: " + "Continue Bomb Operation");
continue;
}

ECommandDirection bombsiteDirection = findBombsiteDirection(terrorist.getPosition());
if (bombsiteDirection == null)
{
System.out.println("Agent[" + terrorist.getId() + "]: " + "Random Move");
int randIndex = (int) (Math.random() * ECommandDirection.values().length);
ECommandDirection randDir = ECommandDirection.values()[randIndex];
move(terrorist.getId(), randDir);
}
else
{
System.out.println("Agent[" + terrorist.getId() + "]: " + "Start Bomb Operation");
plant(terrorist.getId(), bombsiteDirection);
}
}
}
for (Police police : this.world.getPolices())
{
if (police.getStatus() == EAgentStatus.Dead)
continue;

boolean doingBombOperation = police.getDefusionRemainingTime() != -1;
if (doingBombOperation)
{
System.out.println("Agent[" + police.getId() + "]: " + "Continue Bomb Operation");
continue;
}

ECommandDirection bombsiteDirection = findBombsiteDirection(police.getPosition());
if (bombsiteDirection == null)
{
System.out.println("Agent[" + police.getId() + "]: " + "Random Move");
int randIndex = (int) (Math.random() * ECommandDirection.values().length);
ECommandDirection randDir = ECommandDirection.values()[randIndex];
move(police.getId(), randDir);
}
else
{
System.out.println("Agent[" + police.getId() + "]: " + "Start Bomb Operation");
defuse(police.getId(), bombsiteDirection);
}
}
}
else
{
for (Terrorist terrorist : this.world.getTerrorists())
{
if (terrorist.getStatus() == EAgentStatus.Dead)
continue;

boolean doingBombOperation = terrorist.getPlantingRemainingTime() != -1;
if (doingBombOperation)
{
System.out.println("Agent[" + terrorist.getId() + "]: " + "Continue Bomb Operation");
continue;
}

ECommandDirection bombsiteDirection = findBombsiteDirection(terrorist.getPosition());
if (bombsiteDirection == null)
{
System.out.println("Agent[" + terrorist.getId() + "]: " + "Random Move");
int randIndex = (int) (Math.random() * ECommandDirection.values().length);
ECommandDirection randDir = ECommandDirection.values()[randIndex];
move(terrorist.getId(), randDir);
}
else
{
System.out.println("Agent[" + terrorist.getId() + "]: " + "Start Bomb Operation");
plant(terrorist.getId(), bombsiteDirection);
}
}
}
}


Expand All @@ -99,22 +99,22 @@ public void defuse(int agentId, ECommandDirection bombsiteDirection)

private ECommandDirection findBombsiteDirection(Position position)
{
if ((this.world.getBoard().get(position.getY() - 1).get(position.getX()).getValue() >= ECell.SmallBombSite.getValue()) &&
(this.world.getBoard().get(position.getY() - 1).get(position.getX()).getValue() <= ECell.VastBombSite.getValue()))
return ECommandDirection.Up;
if ((this.world.getBoard().get(position.getY() - 1).get(position.getX()).getValue() >= ECell.SmallBombSite.getValue()) &&
(this.world.getBoard().get(position.getY() - 1).get(position.getX()).getValue() <= ECell.VastBombSite.getValue()))
return ECommandDirection.Up;

if ((this.world.getBoard().get(position.getY()).get(position.getX() + 1).getValue() >= ECell.SmallBombSite.getValue()) &&
(this.world.getBoard().get(position.getY()).get(position.getX() + 1).getValue() <= ECell.VastBombSite.getValue()))
return ECommandDirection.Right;
if ((this.world.getBoard().get(position.getY()).get(position.getX() + 1).getValue() >= ECell.SmallBombSite.getValue()) &&
(this.world.getBoard().get(position.getY()).get(position.getX() + 1).getValue() <= ECell.VastBombSite.getValue()))
return ECommandDirection.Right;

if ((this.world.getBoard().get(position.getY() + 1).get(position.getX()).getValue() >= ECell.SmallBombSite.getValue()) &&
(this.world.getBoard().get(position.getY() + 1).get(position.getX()).getValue() <= ECell.VastBombSite.getValue()))
return ECommandDirection.Down;
if ((this.world.getBoard().get(position.getY() + 1).get(position.getX()).getValue() >= ECell.SmallBombSite.getValue()) &&
(this.world.getBoard().get(position.getY() + 1).get(position.getX()).getValue() <= ECell.VastBombSite.getValue()))
return ECommandDirection.Down;

if ((this.world.getBoard().get(position.getY()).get(position.getX() - 1).getValue() >= ECell.SmallBombSite.getValue()) &&
(this.world.getBoard().get(position.getY()).get(position.getX() - 1).getValue() <= ECell.VastBombSite.getValue()))
return ECommandDirection.Left;
if ((this.world.getBoard().get(position.getY()).get(position.getX() - 1).getValue() >= ECell.SmallBombSite.getValue()) &&
(this.world.getBoard().get(position.getY()).get(position.getX() - 1).getValue() <= ECell.VastBombSite.getValue()))
return ECommandDirection.Left;

return null;
return null;
}
}
10 changes: 5 additions & 5 deletions PythonClient/gamecfg.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"general": {
"command_files": [
"ks/commands"
],
"offline_mode": true
"command_files": [
"ks/commands"
],
"offline_mode": true
},

"net": {
Expand All @@ -18,7 +18,7 @@
"": "creating a new decision thread each time a snapshot of game is received from server",
"create_new_thread": true,
"agent_name": "0",
"team_nickname": "BabyKnight",
"team_nickname": "Team1",
"token": "team_id1-xx"
}
}
12 changes: 6 additions & 6 deletions PythonClient/gamecfg2.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"general": {
"command_files": [
"ks/commands"
],
"offline_mode": true
"command_files": [
"ks/commands"
],
"offline_mode": true
},

"net": {
Expand All @@ -18,7 +18,7 @@
"": "creating a new decision thread each time a snapshot of game is received from server",
"create_new_thread": true,
"agent_name": "0",
"team_nickname": "BabyKnight2",
"token": "team_id1-xx"
"team_nickname": "Team2",
"token": "team_id2-xx"
}
}
10 changes: 5 additions & 5 deletions PythonRandomClient/gamecfg.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"general": {
"command_files": [
"ks/commands"
],
"offline_mode": true
"command_files": [
"ks/commands"
],
"offline_mode": true
},

"net": {
Expand All @@ -19,6 +19,6 @@
"create_new_thread": true,
"agent_name": "0",
"team_nickname": "RandomTeam",
"token": "team_id1-xx"
"token": "random_team-xx"
}
}
36 changes: 20 additions & 16 deletions PythonServer/generate_ks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,34 @@
from koala_serializer import generate


commands_reletive_path = 'ks/commands.ks'
models_reletive_path = 'ks/models.ks'
ks_rel_dir = "app/ks"
commands_ksfile = "commands.ks"
models_ksfile = "models.ks"

destinations = [
'../PythonClient',
'../PythonRandomClient',
'../CppClient/Game',
'../JavaClient/src'
"../PythonClient/ks",
"../PythonRandomClient/ks",
"../CppClient/Game/ks",
"../JavaClient/src/ks",
"../CSharpClient/Game/KS"
]

for dest in destinations:
for rel_path in [commands_reletive_path, models_reletive_path]:
path = os.path.join(dest, rel_path)
for ksfile in [commands_ksfile, models_ksfile]:
path = os.path.join(dest, ksfile)
if not os.path.exists(os.path.dirname(path)):
os.mkdir(os.path.dirname(path))
copyfile(os.path.join('app', rel_path), path)
copyfile(os.path.join(ks_rel_dir, ksfile), path)

all_args = [
('python', 'app/ks', 'snake_case'),
('python', '../PythonClient/ks', 'snake_case'),
('python', '../PythonRandomClient/ks', 'snake_case'),
('cpp', '../CppClient/Game/ks', 'camelCase'),
('java', '../JavaClient/src', 'camelCase')
('python', ks_rel_dir, 'snake_case'),
('python', "../PythonClient/ks", 'snake_case'),
('python', "../PythonRandomClient/ks", 'snake_case'),
('cpp', "../CppClient/Game/ks", 'camelCase'),
('java', "../JavaClient/src", 'camelCase'),
('cs', '../CSharpClient/Game/KS', 'PascalCase')
]

for args in all_args:
generate(os.path.join('app', commands_reletive_path), *args)
generate(os.path.join('app', models_reletive_path), *args)
generate(os.path.join(ks_rel_dir, commands_ksfile), *args)
generate(os.path.join(ks_rel_dir, models_ksfile), *args)

0 comments on commit 5d75775

Please sign in to comment.