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
986cf224
Commit
986cf224
authored
9 years ago
by
Elnath
Browse files
Options
Downloads
Patches
Plain Diff
State is entirely printed to json
parent
2ecb0ccf
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/game/penguin.cpp
+38
-36
38 additions, 36 deletions
src/game/penguin.cpp
tools/gui.py
+4
-1
4 additions, 1 deletion
tools/gui.py
with
42 additions
and
37 deletions
src/game/penguin.cpp
+
38
−
36
View file @
986cf224
...
...
@@ -17,7 +17,7 @@ namespace game
obstacles
|=
((
uint64_t
)
1
)
<<
(
state
.
p2_blue
&
63
);
obstacles
|=
((
uint64_t
)
1
)
<<
(
state
.
p3_blue
&
63
);
obstacles
|=
((
uint64_t
)
1
)
<<
(
state
.
p4_blue
&
63
);
state
.
nb_moves_red
=
0
;
state
.
nb_moves_blue
=
0
;
state
.
nb_moves_red
+=
update_moves
(
&
state
.
p1_red
,
obstacles
);
...
...
@@ -28,7 +28,7 @@ namespace game
state
.
nb_moves_blue
+=
update_moves
(
&
state
.
p2_blue
,
obstacles
);
state
.
nb_moves_blue
+=
update_moves
(
&
state
.
p3_blue
,
obstacles
);
state
.
nb_moves_blue
+=
update_moves
(
&
state
.
p4_blue
,
obstacles
);
//Change player if the other one can play
if
(
state
.
current_player_red
&&
state
.
nb_moves_blue
>
0
)
state
.
current_player_red
=
false
;
...
...
@@ -45,10 +45,10 @@ namespace game
{
return
state
;
}
void
penguin
::
set_state
(
const
penguin_state
&
s
)
{
state
=
s
;
state
=
s
;
}
bool
penguin
::
end_of_game
()
const
...
...
@@ -61,7 +61,7 @@ namespace game
if
(
player
==
RED
)
return
state
.
score_red
>
state
.
score_blue
;
return
state
.
score_blue
>
state
.
score_red
;
}
bool
penguin
::
lost
(
std
::
uint8_t
player
)
const
{
if
(
player
==
RED
)
return
state
.
score_red
<
state
.
score_blue
;
...
...
@@ -76,7 +76,7 @@ namespace game
uint8_t
penguin
::
current_player
()
const
{
return
state
.
current_player_red
?
RED
:
BLUE
;
}
}
int
penguin
::
value
(
uint8_t
player
)
const
{
...
...
@@ -94,7 +94,7 @@ namespace game
//return 9 - state.total_moves;
return
0
;
}
/* The penguin that will move if we want to play the #move_number move in the list of possible moves.
* What this function does:
* Find the penguin that will move.
...
...
@@ -113,7 +113,7 @@ namespace game
return
p
;
}
move_number
-=
(
state
.
p1_red
>>
6
)
&
63
;
if
(((
state
.
p2_red
>>
6
)
&
63
)
>
move_number
)
{
uint32_t
*
p
=
&
state
.
p2_red
;
...
...
@@ -122,7 +122,7 @@ namespace game
return
p
;
}
move_number
-=
(
state
.
p2_red
>>
6
)
&
63
;
if
(((
state
.
p3_red
>>
6
)
&
63
)
>
move_number
)
{
uint32_t
*
p
=
&
state
.
p3_red
;
...
...
@@ -131,7 +131,7 @@ namespace game
return
p
;
}
move_number
-=
(
state
.
p3_red
>>
6
)
&
63
;
uint32_t
*
p
=
&
state
.
p4_red
;
(
*
p
)
=
(
*
p
)
&
0xFFFFF03F
;
//Reset move number for the penguin to 0
(
*
p
)
=
(
*
p
)
|
((
uint32_t
)
move_number
)
<<
6
;
...
...
@@ -147,7 +147,7 @@ namespace game
return
p
;
}
move_number
-=
(
state
.
p1_blue
>>
6
)
&
63
;
if
(((
state
.
p2_blue
>>
6
)
&
63
)
>
move_number
)
{
uint32_t
*
p
=
&
state
.
p2_blue
;
...
...
@@ -156,7 +156,7 @@ namespace game
return
p
;
}
move_number
-=
(
state
.
p2_blue
>>
6
)
&
63
;
if
(((
state
.
p3_blue
>>
6
)
&
63
)
>
move_number
)
{
uint32_t
*
p
=
&
state
.
p3_blue
;
...
...
@@ -165,14 +165,14 @@ namespace game
return
p
;
}
move_number
-=
(
state
.
p3_blue
>>
6
)
&
63
;
uint32_t
*
p
=
&
state
.
p4_blue
;
(
*
p
)
=
(
*
p
)
&
0xFFFFF03F
;
//Reset move number for the penguin to 0
(
*
p
)
=
(
*
p
)
|
((
uint32_t
)
move_number
)
<<
6
;
return
p
;
}
}
void
penguin
::
move_penguin
(
uint32_t
*
p
)
{
uint8_t
move_number
=
((
*
p
)
>>
6
)
&
63
;
//Move number for the current penguin
...
...
@@ -221,7 +221,7 @@ namespace game
//Move direction F
(
*
p
)
=
(
8
*
move_number
+
1
)
+
((
*
p
)
&
63
);
}
int
penguin
::
update_moves
(
uint32_t
*
p
,
uint64_t
obstacles
)
{
#define IsFree(i) (((obstacles >> (i)) & 1) == 0)
...
...
@@ -230,7 +230,7 @@ namespace game
int
i
=
pos
;
uint32_t
nbmoves
=
0
;
uint32_t
total_moves
=
0
;
//Direction A
while
(((
i
+
7
)
<
60
)
&&
(
i
%
15
!=
0
)
&&
IsFree
(
i
+
7
))
{
...
...
@@ -283,18 +283,18 @@ namespace game
nbmoves
++
;
total_moves
++
;
}
(
*
p
)
=
(
*
p
)
|
nbmoves
<<
27
;
(
*
p
)
=
(
*
p
)
|
total_moves
<<
6
;
return
total_moves
;
}
//Play the mth move in the possible moves list.
void
penguin
::
play
(
uint16_t
m
)
{
{
//Find which penguin will move
uint32_t
*
p
=
penguin_that_moves
(
m
);
uint8_t
position
=
(
*
p
)
&
63
;
//Find the value of the tile the penguin is on and update score
if
((
state
.
one_fish
>>
position
)
&
1
)
{
...
...
@@ -307,7 +307,7 @@ namespace game
}
else
if
((
state
.
two_fish
>>
position
)
&
1
)
{
if
(
current_player
()
==
RED
)
state
.
score_red
+=
2
;
else
...
...
@@ -324,12 +324,12 @@ namespace game
//We replace this tile with an empty one (0 in the bitboard)
state
.
three_fish
=
state
.
three_fish
&
~
(((
uint64_t
)
1
)
<<
position
);
}
//Move the current penguin
move_penguin
(
p
);
cout
<<
"Penguin p :"
<<
*
p
<<
endl
;
//Update moves on all penguins
uint64_t
obstacles
=
(
~
(
state
.
one_fish
|
state
.
two_fish
|
state
.
three_fish
));
obstacles
|=
((
uint64_t
)
1
)
<<
(
state
.
p1_red
&
63
);
...
...
@@ -340,9 +340,9 @@ namespace game
obstacles
|=
((
uint64_t
)
1
)
<<
(
state
.
p2_blue
&
63
);
obstacles
|=
((
uint64_t
)
1
)
<<
(
state
.
p3_blue
&
63
);
obstacles
|=
((
uint64_t
)
1
)
<<
(
state
.
p4_blue
&
63
);
cout
<<
obstacles
<<
endl
;
state
.
nb_moves_red
=
0
;
state
.
nb_moves_blue
=
0
;
state
.
nb_moves_red
+=
update_moves
(
&
state
.
p1_red
,
obstacles
);
...
...
@@ -353,21 +353,21 @@ namespace game
state
.
nb_moves_blue
+=
update_moves
(
&
state
.
p2_blue
,
obstacles
);
state
.
nb_moves_blue
+=
update_moves
(
&
state
.
p3_blue
,
obstacles
);
state
.
nb_moves_blue
+=
update_moves
(
&
state
.
p4_blue
,
obstacles
);
//Change player if the other one can play
if
(
state
.
current_player_red
&&
state
.
nb_moves_blue
>
0
)
state
.
current_player_red
=
false
;
else
if
(
state
.
current_player_red
==
false
&&
state
.
nb_moves_red
>
0
)
state
.
current_player_red
=
true
;
}
string
penguin
::
player_to_string
(
uint8_t
player
)
const
{
return
player
==
RED
?
"Red"
:
"Blue"
;
}
string
penguin
::
move_to_string
(
uint16_t
m
)
const
{
return
std
::
to_string
(
m
);
...
...
@@ -388,7 +388,7 @@ namespace game
json
[
"bitboards"
][
"onefish"
]
=
state
.
one_fish
;
json
[
"bitboards"
][
"twofish"
]
=
state
.
two_fish
;
json
[
"bitboards"
][
"threefish"
]
=
state
.
three_fish
;
json
[
"penguins"
][
"red"
][
0
]
=
state
.
p1_red
;
json
[
"penguins"
][
"red"
][
1
]
=
state
.
p2_red
;
json
[
"penguins"
][
"red"
][
2
]
=
state
.
p3_red
;
...
...
@@ -397,13 +397,15 @@ namespace game
json
[
"penguins"
][
"blue"
][
1
]
=
state
.
p2_blue
;
json
[
"penguins"
][
"blue"
][
2
]
=
state
.
p3_blue
;
json
[
"penguins"
][
"blue"
][
3
]
=
state
.
p4_blue
;
json
[
"score"
][
"red"
]
=
state
.
score_red
;
json
[
"score"
][
"blue"
]
=
state
.
score_blue
;
json
[
"possible_moves"
][
"red"
]
=
state
.
nb_moves_red
;
json
[
"possible_moves"
][
"blue"
]
=
state
.
nb_moves_blue
;
json
[
"current_player"
]
=
state
.
current_player_red
?
"Red"
:
"Blue"
;
return
json
;
}
...
...
@@ -423,7 +425,7 @@ namespace game
{
return
0
;
}
ostream
&
operator
<<
(
ostream
&
os
,
const
penguin
&
pen
)
{
os
<<
pen
.
to_string
();
...
...
This diff is collapsed.
Click to expand it.
tools/gui.py
+
4
−
1
View file @
986cf224
...
...
@@ -39,7 +39,10 @@ if __name__ == "__main__":
for
i
in
range
(
4
):
drawState
.
drawPenguin
(
state
[
"
penguins
"
][
"
blue
"
][
i
])
#PLAY NEXT MOVE
move
=
input
(
"
Enter next move:
"
)
if
state
[
"
current_player
"
]
==
"
Red
"
:
move
=
input
(
"
Enter Red move:
"
)
else
:
move
=
input
(
"
Enter Blue move:
"
)
program
.
stdin
.
write
(
move
+
"
\n
"
)
program
.
stdin
.
flush
()
except
KeyboardInterrupt
:
...
...
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