diff --git a/gui/src/controller/Controller.java b/gui/src/controller/Controller.java index 501b215a10e783f64131d14a1b8e8c6ea73465d2..6c4c6d78e4818dcc6843ce9fc419114b125607e8 100644 --- a/gui/src/controller/Controller.java +++ b/gui/src/controller/Controller.java @@ -70,9 +70,7 @@ public class Controller implements Initializable upT.start(); //We tell the game that we will start - gameInput.print("h"); - gameInput.println(); - gameInput.println("0"); + gameInput.println("h"); } diff --git a/gui/src/controller/UpdateThread.java b/gui/src/controller/UpdateThread.java index fb2d51782bfa7cc9a6e388675c3054dff04a5ad6..14f84cafc98a8758a61e3c3f938d1fcc0885c02b 100644 --- a/gui/src/controller/UpdateThread.java +++ b/gui/src/controller/UpdateThread.java @@ -26,7 +26,7 @@ public class UpdateThread extends Thread this.board = board; this.boardView = boardView; } - + public void run() { @@ -52,8 +52,8 @@ public class UpdateThread extends Thread } for (int i = 0; i < 4; i++) { - board[gameState.getPenguinPos(i, Player.Red)].setPenguinPresence(Tile.PenguinPresence.RED_PENGUIN); - board[gameState.getPenguinPos(i, Player.Blue)].setPenguinPresence(Tile.PenguinPresence.BLUE_PENGUIN); + board[gameState.getPenguinPos(Player.Red, i)].setPenguinPresence(Tile.PenguinPresence.RED_PENGUIN); + board[gameState.getPenguinPos(Player.Blue, i)].setPenguinPresence(Tile.PenguinPresence.BLUE_PENGUIN); } //UPDATE VIEW diff --git a/gui/src/model/GameState.java b/gui/src/model/GameState.java index df2dbec29a701eaf668187312610ca1820d718ed..ae3e8df4965c54465940838db10b80de4798fb75 100644 --- a/gui/src/model/GameState.java +++ b/gui/src/model/GameState.java @@ -62,10 +62,76 @@ public class GameState return 0; } - public int getPenguinPos(int i, Player player) + /** + * @param player The player for which we are searching the penguin position + * @param i The number of the penguin for this player + * @return The position (0-59) of the penguin on the board + */ + public int getPenguinPos(Player player, int i) + { return (penguins.get(player)[i] & 63); } + + /** + * @param player The penguin's owner + * @param i The number of the penguin for this player + * @return the total moves that this penguin can do + */ + public int getPenguinTotalMoves(Player player, int i) + { return ((penguins.get(player)[i] >>> 6) & 63); } + + public enum Direction { - //TODO - return 0; + A,B,C,D,E,F; + } + + /** + * Get maximum number of tiles that a penguin can do in one specific direction + */ + public int getNbMoves(Player player, int penguinNumber, Direction direction) + { + int shift = 0; + switch (direction) + { + case A: + shift = 12; + break; + case B: + shift = 15; + break; + case C: + shift = 18; + break; + case D: + shift = 21; + break; + case E: + shift = 24; + break; + case F: + shift = 27; + break; + } + return ((penguins.get(player)[penguinNumber] >>> shift) & 7); + } + + /** + * "I want to move penguin 1 in direction B for 5 steps" + * "This is you move number 10 out of all your possible moves" + * Note: moves start at 0. Steps start at 1 for this function + */ + public int getPlayerMoveNumber(Player player, int penguinNumber, Direction direction, int nbSteps) + { + int[] peng = penguins.get(player); + int total = 0; + for(int i = 0; i < penguinNumber; i++) //We add the moves of all preceding penguins + total += getPenguinTotalMoves(player, i); + for(Direction d : Direction.values()) + { + if(d.equals(direction)) + return total+nbSteps-1; + else + total += getNbMoves(player, penguinNumber, d); + } + return -1; } public boolean getCan_play_red()