Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pingouins
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Felton Samuel
pingouins
Commits
80462fe8
Commit
80462fe8
authored
8 years ago
by
Bariatti Francesco
Browse files
Options
Downloads
Patches
Plain Diff
Added function to GameState to query penguin positions and moves
parent
7557f763
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
gui/src/controller/Controller.java
+1
-3
1 addition, 3 deletions
gui/src/controller/Controller.java
gui/src/controller/UpdateThread.java
+3
-3
3 additions, 3 deletions
gui/src/controller/UpdateThread.java
gui/src/model/GameState.java
+69
-3
69 additions, 3 deletions
gui/src/model/GameState.java
with
73 additions
and
9 deletions
gui/src/controller/Controller.java
+
1
−
3
View file @
80462fe8
...
...
@@ -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"
);
}
...
...
This diff is collapsed.
Click to expand it.
gui/src/controller/UpdateThread.java
+
3
−
3
View file @
80462fe8
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
gui/src/model/GameState.java
+
69
−
3
View file @
80462fe8
...
...
@@ -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
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment