From 59bc6a360abdc88f7a1659e6dca153fc59f1126f Mon Sep 17 00:00:00 2001 From: gumartinm Date: Fri, 31 Aug 2012 17:15:42 +0200 Subject: [PATCH] No time for comments --- res/layout/activity_reversi.xml | 4 ++-- src/de/android/reversi/CheckMovement.java | 23 +++++++++++++++-------- src/de/android/reversi/ReversiView.java | 19 +++++++++++-------- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/res/layout/activity_reversi.xml b/res/layout/activity_reversi.xml index 7316fc0..b93e2bd 100644 --- a/res/layout/activity_reversi.xml +++ b/res/layout/activity_reversi.xml @@ -17,7 +17,7 @@ android:layout_height="wrap_content"/> @@ -30,7 +30,7 @@ diff --git a/src/de/android/reversi/CheckMovement.java b/src/de/android/reversi/CheckMovement.java index afc4bca..ab8b1c6 100644 --- a/src/de/android/reversi/CheckMovement.java +++ b/src/de/android/reversi/CheckMovement.java @@ -6,22 +6,29 @@ import java.util.List; public final class CheckMovement { public static boolean horizontal(final Square gameBoard[][], final Movement movement, final Player player) { - return outflankRight(gameBoard, movement, player) || - outflankLeft(gameBoard, movement, player); + final boolean outflankRight = outflankRight(gameBoard, movement, player); + final boolean outflankLeft = outflankLeft(gameBoard, movement, player); + + return outflankRight || outflankLeft; } public static boolean vertical(final Square gameBoard[][], final Movement movement, final Player player) { - return outflankUp(gameBoard, movement, player) || - outflankDown(gameBoard, movement, player); + final boolean outflankUp = outflankUp(gameBoard, movement, player); + final boolean outflankDown = outflankDown(gameBoard, movement, player); + + return outflankUp || outflankDown; } public static boolean diagonal(final Square gameBoard[][], final Movement movement, final Player player) { - return outflankDiagonalLeftUp(gameBoard, movement, player) || - outflankDiagonalRightDown(gameBoard, movement, player) || - outflankDiagonalRightUp(gameBoard, movement, player) || - outflankDiagonalLeftDown(gameBoard, movement, player); + final boolean outflankDiagonalLeftUp = outflankDiagonalLeftUp(gameBoard, movement, player); + final boolean outflankDiagonalRightDown = outflankDiagonalRightDown(gameBoard, movement, player); + final boolean outflankDiagonalRightUp = outflankDiagonalRightUp(gameBoard, movement, player); + final boolean outflankDiagonalLeftDown = outflankDiagonalLeftDown(gameBoard, movement, player); + + return outflankDiagonalLeftUp || outflankDiagonalRightDown || outflankDiagonalRightUp || + outflankDiagonalLeftDown; } public static boolean empty(final Square gameBoard[][], final short column, final short row) { diff --git a/src/de/android/reversi/ReversiView.java b/src/de/android/reversi/ReversiView.java index 4d4d607..2de189e 100644 --- a/src/de/android/reversi/ReversiView.java +++ b/src/de/android/reversi/ReversiView.java @@ -23,7 +23,7 @@ public class ReversiView extends SurfaceView { private static final short LEFT_MARGIN = 0; private final Square gameBoard[][] = new Square[NUMBER_OF_ROWS][NUMBER_OF_COLUMNS]; - private final Player IA = Player.NOPLAYER; + private final Player AI = Player.NOPLAYER; private final Context context; //¿Funciona bien volatile con enum? Ver mi codigo de Singletons y enums. @@ -314,7 +314,7 @@ public class ReversiView extends SurfaceView { private void mainLoop() { this.currentPlayer = opponent(this.currentPlayer); - if (this.currentPlayer != this.IA) { + if (this.currentPlayer != this.AI) { //AllowedMovements for Player listAllowedMovements = allowedMovements(currentPlayer, gameBoard); @@ -333,7 +333,7 @@ public class ReversiView extends SurfaceView { } else { this.isEnableUserTouch = false; - //Launch IA thread. + //Launch AI thread. } } @@ -343,11 +343,14 @@ public class ReversiView extends SurfaceView { for (short column = 0; column < NUMBER_OF_COLUMNS; column++) { for (short row = 0; row < NUMBER_OF_ROWS; row++) { final Movement movement = new Movement(row, column); - if (CheckMovement.empty(gameBoard, column, row) && - (CheckMovement.diagonal(gameBoard, movement, player) || - CheckMovement.horizontal(gameBoard, movement, player) || - CheckMovement.vertical(gameBoard, movement, player))) { - list.add(movement); + if (CheckMovement.empty(gameBoard, column, row)) { + final boolean diagonal = CheckMovement.diagonal(gameBoard, movement, player); + final boolean horizontal = CheckMovement.horizontal(gameBoard, movement, player); + final boolean vertical = CheckMovement.vertical(gameBoard, movement, player); + + if(diagonal || horizontal || vertical) { + list.add(movement); + } } } } -- 2.1.4