Skip to content
Snippets Groups Projects
Commit 80462fe8 authored by Bariatti Francesco's avatar Bariatti Francesco
Browse files

Added function to GameState to query penguin positions and moves

parent 7557f763
No related branches found
No related tags found
No related merge requests found
......@@ -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");
}
......
......@@ -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
......
......@@ -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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment