No time for comments
authorgumartinm <gustavo@gumartinm.name>
Fri, 31 Aug 2012 15:15:42 +0000 (17:15 +0200)
committergumartinm <gustavo@gumartinm.name>
Fri, 31 Aug 2012 15:15:42 +0000 (17:15 +0200)
res/layout/activity_reversi.xml
src/de/android/reversi/CheckMovement.java
src/de/android/reversi/ReversiView.java

index 7316fc0..b93e2bd 100644 (file)
@@ -17,7 +17,7 @@
             android:layout_height="wrap_content"/>
         <TextView android:text=" 2" 
             android:id="@+id/txtPlayer1Score"
-            android:minWidth="30dp" 
+            android:minWidth="80dp"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content">    
         </TextView>
@@ -30,7 +30,7 @@
         <TextView 
             android:text=" 2" 
             android:id="@+id/txtPlayer2Score"
-            android:minWidth="30dp" 
+            android:minWidth="80dp"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content">
         </TextView>
index afc4bca..ab8b1c6 100644 (file)
@@ -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) {
index 4d4d607..2de189e 100644 (file)
@@ -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);
+                    }
                 }
             }
         }