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>
<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>
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) {
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.
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);
}
else {
this.isEnableUserTouch = false;
- //Launch IA thread.
+ //Launch AI thread.
}
}
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);
+ }
}
}
}