Skip to content
This repository has been archived by the owner on Apr 25, 2020. It is now read-only.

Commit

Permalink
Finished AI
Browse files Browse the repository at this point in the history
  • Loading branch information
Raymo111 committed Jun 18, 2018
1 parent 1e67879 commit 12381c9
Showing 1 changed file with 21 additions and 25 deletions.
46 changes: 21 additions & 25 deletions src/AI.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ public AI(boolean inGui) throws IOException {
}

// User wants to offset edges
if (input.equalsIgnoreCase("y")) {
int x = Integer.parseInt(br.readLine()) - 1;
int y = Integer.parseInt(br.readLine()) - 1;
if (input.equalsIgnoreCase("n")) {
for (int i = 0; i < Battleship.enemyGrid.length; i++)
for (int j = 0; j < Battleship.enemyGrid[i].length; j++) {

// X between x and y layers
if (Battleship.enemyGrid[i][j].x >= x && Battleship.enemyGrid[i][j].x <= y
|| Battleship.enemyGrid[i][j].x <= 9 - y && Battleship.enemyGrid[i][j].x >= 9 - x) {
if (Battleship.enemyGrid[i][j].x == 0 || Battleship.enemyGrid[i][j].x == 9) {// x in outer 2
Battleship.enemyGrid[i][j].huntPDx += 40;
Battleship.enemyGrid[i][j].combinehuntPDXY();
}

// Y between x and y layers
if (Battleship.enemyGrid[i][j].y >= x && Battleship.enemyGrid[i][j].y <= y
|| Battleship.enemyGrid[i][j].y <= 9 - y && Battleship.enemyGrid[i][j].y >= 9 - x) {
if (Battleship.enemyGrid[i][j].y == 0 || Battleship.enemyGrid[i][j].y == 9) {// y in outer 2
Battleship.enemyGrid[i][j].huntPDy += 40;
Battleship.enemyGrid[i][j].combinehuntPDXY();
}
if (Battleship.enemyGrid[i][j].x == 1 || Battleship.enemyGrid[i][j].x == 8) {// x in outer 2
Battleship.enemyGrid[i][j].huntPDx += 40;
Battleship.enemyGrid[i][j].combinehuntPDXY();
}
if (Battleship.enemyGrid[i][j].y == 1 || Battleship.enemyGrid[i][j].y == 8) {// y in outer 2
Battleship.enemyGrid[i][j].huntPDy += 40;
Battleship.enemyGrid[i][j].combinehuntPDXY();
}
Expand Down Expand Up @@ -266,20 +266,16 @@ else if (lastShot.status == SquareTypes.SUNK) {
flag = true;
break;
}
if (flag) {// More hit squares than ships sunk
return target(mode, grid);
} else {// All hit ships were sunk
for (int i = 0; i < shipLengths.length; i++)
updateHuntPD(mode, grid, lastShot, shipLengths[i]);
mode = Mode.HUNT;
for (int i = 0; i < grid.length; i++)
for (int j = 0; j < grid[i].length; j++) {
grid[i][j].targetPDx = 0;
grid[i][j].targetPDy = 0;
grid[i][j].combinehuntPDXY();
}
return aim(null, grid, shipLengths);
}
for (int i = 0; i < shipLengths.length; i++)
updateHuntPD(mode, grid, lastShot, shipLengths[i]);
mode = Mode.HUNT;
for (int i = 0; i < grid.length; i++)
for (int j = 0; j < grid[i].length; j++) {
grid[i][j].targetPDx = 0;
grid[i][j].targetPDy = 0;
grid[i][j].combinehuntPDXY();
}
return aim(null, grid, shipLengths);
}

/*
Expand Down

0 comments on commit 12381c9

Please sign in to comment.