From: gumartinm Date: Fri, 31 Aug 2012 13:14:33 +0000 (+0200) Subject: CheckMovement, removing Precondition 2. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=c293eb3fad521229f36db9e44b146757aa861276;p=AndroidReversiForFun%2F.git CheckMovement, removing Precondition 2. --- diff --git a/src/de/android/reversi/CheckMovement.java b/src/de/android/reversi/CheckMovement.java index b34ef64..afc4bca 100644 --- a/src/de/android/reversi/CheckMovement.java +++ b/src/de/android/reversi/CheckMovement.java @@ -36,17 +36,11 @@ public final class CheckMovement { final short row = movement.getRow(); final short column = movement.getColumn(); - //Precondition 1. + //Precondition: if (row <= 1) { return false; } - //Precondition 2. - if (gameBoard[column][row-1].getPlayer() == player || - empty(gameBoard, column, (short)(row-1))) { - return false; - } - final List flippedDiscs = outflank((short)0, (short)-1, gameBoard, player, (short)(row-1), column); if (flippedDiscs.isEmpty()) { @@ -62,17 +56,11 @@ public final class CheckMovement { final short row = movement.getRow(); final short column = movement.getColumn(); - //Precondition 1: + //Precondition: if (row >= ReversiView.NUMBER_OF_ROWS -2) { return false; } - //Precondition 2. - if (gameBoard[column][row+1].getPlayer() == player || - empty(gameBoard, column, (short)(row+1))) { - return false; - } - final List flippedDiscs = outflank((short)0, (short)1, gameBoard, player, (short)(row+1), column); if (flippedDiscs.isEmpty()) { @@ -88,17 +76,11 @@ public final class CheckMovement { final short row = movement.getRow(); final short column = movement.getColumn(); - //Precondition 1: + //Precondition: if (column >= ReversiView.NUMBER_OF_COLUMNS -2) { return false; } - //Precondition 2. - if (gameBoard[column+1][row].getPlayer() == player || - empty(gameBoard, (short)(column+1), row)) { - return false; - } - final List flippedDiscs = outflank((short)1, (short)0, gameBoard, player, row, (short)(column+1)); if (flippedDiscs.isEmpty()) { @@ -114,17 +96,11 @@ public final class CheckMovement { final short row = movement.getRow(); final short column = movement.getColumn(); - //Precondition 1: + //Precondition: if (column <= 1) { return false; } - //Precondition 2. - if (gameBoard[column-1][row].getPlayer() == player || - empty(gameBoard, (short)(column-1), row)) { - return false; - } - final List flippedDiscs = outflank((short)-1, (short)0, gameBoard, player, row, (short)(column-1)); if (flippedDiscs.isEmpty()) { @@ -140,17 +116,11 @@ public final class CheckMovement { final short row = movement.getRow(); final short column = movement.getColumn(); - //Precondition 1: + //Precondition: if (column <= 1 || row <= 1) { return false; } - //Precondition 2. - if (gameBoard[column-1][row-1].getPlayer() == player || - empty(gameBoard, (short)(column-1), (short)(row-1))) { - return false; - } - final List flippedDiscs = outflank((short)-1, (short)-1, gameBoard, player, (short)(row-1), (short)(column-1)); if (flippedDiscs.isEmpty()) { @@ -166,17 +136,11 @@ public final class CheckMovement { final short row = movement.getRow(); final short column = movement.getColumn(); - //Precondition 1: + //Precondition: if (column >= (ReversiView.NUMBER_OF_COLUMNS -2) || row >= (ReversiView.NUMBER_OF_ROWS -2)) { return false; } - //Precondition 2. - if (gameBoard[column+1][row+1].getPlayer() == player || - empty(gameBoard, (short)(column+1), (short)(row+1))) { - return false; - } - final List flippedDiscs = outflank((short)1, (short)1, gameBoard, player, (short)(row+1), (short)(column+1)); if (flippedDiscs.isEmpty()) { @@ -192,17 +156,11 @@ public final class CheckMovement { final short row = movement.getRow(); final short column = movement.getColumn(); - //Precondition 1: + //Precondition: if (column <= 1 || row >= (ReversiView.NUMBER_OF_ROWS -2)) { return false; } - //Precondition 2. - if (gameBoard[column-1][row+1].getPlayer() == player || - empty(gameBoard, (short)(column-1), (short)(row+1))) { - return false; - } - final List flippedDiscs = outflank((short)-1, (short)1, gameBoard, player, (short)(row+1), (short)(column-1)); if (flippedDiscs.isEmpty()) { @@ -218,17 +176,11 @@ public final class CheckMovement { final short row = movement.getRow(); final short column = movement.getColumn(); - //Precondition 1: + //Precondition: if (row <= 1 || column >= (ReversiView.NUMBER_OF_COLUMNS -2)) { return false; } - //Precondition 2. - if (gameBoard[column+1][row-1].getPlayer() == player || - empty(gameBoard, (short)(column+1), (short)(row-1))) { - return false; - } - final List flippedDiscs = outflank((short)1, (short)-1, gameBoard, player, (short)(row-1), (short)(column+1)); if (flippedDiscs.isEmpty()) { @@ -246,7 +198,7 @@ public final class CheckMovement { while (row > 0 && column > 0 && row < ReversiView.NUMBER_OF_ROWS && column < ReversiView.NUMBER_OF_COLUMNS && - gameBoard[column][row].getPlayer() != Player.NOPLAYER) { + !empty(gameBoard, column, row)) { if (gameBoard[column][row].getPlayer() == player) { match = true; diff --git a/src/de/android/reversi/FlippedDisc.java b/src/de/android/reversi/FlippedDisc.java new file mode 100644 index 0000000..5348066 --- /dev/null +++ b/src/de/android/reversi/FlippedDisc.java @@ -0,0 +1,19 @@ +package de.android.reversi; + +public class FlippedDisc { + private final short row; + private final short column; + + public FlippedDisc(final short row, final short column) { + this.row = row; + this.column = column; + } + + public short getRow() { + return row; + } + + public short getColumn() { + return column; + } +}