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
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
Bariatti Francesco
pingouins
Commits
cf6a9635
Commit
cf6a9635
authored
9 years ago
by
Le Mikael
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of
https://gitlab.insa-rennes.fr/francesco-bariatti/pingouins
parents
dedcfde9
2274d2f1
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/morpion.cpp
+29
-17
29 additions, 17 deletions
src/game/morpion.cpp
src/game/morpion.hpp
+29
-19
29 additions, 19 deletions
src/game/morpion.hpp
with
58 additions
and
36 deletions
src/game/morpion.cpp
+
29
−
17
View file @
cf6a9635
...
...
@@ -49,20 +49,20 @@ namespace game
bool
morpion
::
won
(
std
::
uint8_t
player
)
const
{
//TODO: Implement
return
false
;
if
(
player
==
CROSS
)
return
state
.
first_player_win
;
return
state
.
second_player_win
;
}
bool
morpion
::
lost
(
std
::
uint8_t
player
)
const
{
//TODO: Implement
return
false
;
if
(
player
==
CIRCLE
)
return
state
.
first_player_win
;
return
state
.
second_player_win
;
}
bool
morpion
::
draw
(
std
::
uint8_t
player
)
const
{
//TODO: Implement
return
false
;
if
(
state
.
first_player_win
||
state
.
second_player_win
)
return
false
;
return
state
.
total_moves
==
9
;
}
uint8_t
morpion
::
current_player
()
const
...
...
@@ -72,7 +72,12 @@ namespace game
int
morpion
::
value
(
uint8_t
player
)
const
{
//TODO: Implement
if
(
player
==
CROSS
)
{
return
state
.
first_player_win
?
1
:
(
state
.
second_player_win
?
-
1
:
0
)
}
else
if
(
player
==
CIRCLE
)
{
return
state
.
second_player_win
?
1
:
(
state
.
first_player_win
?
-
1
:
0
)
}
return
0
;
}
...
...
@@ -83,8 +88,7 @@ namespace game
bool
morpion
::
get
(
uint64_t
bitboard
,
uint8_t
col
,
uint8_t
row
)
const
{
//TODO: Implement
return
false
;
return
bitboard
&
(
1LL
<<
(
3
*
row
))
<<
col
;
}
//#define set(bitboard, col, row) (bitboard |= (1LL << (((col) << 3) + (row))))
...
...
@@ -119,17 +123,25 @@ namespace game
if
(
current_player
()
==
CROSS
)
}
/**
* player_to_string
* Retourne X si le joueur joue les croix, O s'il joue les ronds,
* et un espace sinon.
*/
string
morpion
::
player_to_string
(
uint8_t
player
)
const
{
//TODO: Implement
return
"TODO"
;
return
player
==
CROSS
?
"X"
:
(
player
==
CIRCLE
?
"O"
:
" "
);
}
string
morpion
::
move_to_string
(
uint16_t
m
)
const
{
//TODO: Implement
return
"TODO"
;
uint8_t
row
=
m
/
3
;
uint8_t
col
=
m
%
3
;
return
"( "
std
::
to_string
(
row
)
", "
std
::
to_string
(
col
)
" )"
;
}
set
<
int
>
morpion
::
to_input_vector
()
const
...
...
@@ -143,8 +155,8 @@ namespace game
string
morpion
::
to_string
()
const
{
//TODO: Implement
return
"TODO"
;
for
(
int
i
=
0
//TODO PAR ROMAIN
}
void
morpion
::
playout
(
mt19937
&
engine
,
int
max_depth
)
...
...
This diff is collapsed.
Click to expand it.
src/game/morpion.hpp
+
29
−
19
View file @
cf6a9635
...
...
@@ -11,11 +11,11 @@ namespace game
{
struct
morpion_state
{
uint16_t
cross_bitboard
=
0
;
uint16_t
circle_bitboard
=
0
;
uint8_t
total_moves
=
0
;
bool
first_player_win
=
false
;
bool
second_player_win
=
false
;
uint16_t
cross_bitboard
=
0
;
//bitboard with the played moves of the cross
uint16_t
circle_bitboard
=
0
;
//bitboard with the played moves of the circle
uint8_t
total_moves
=
0
;
//Total played moves (<= 9)
bool
first_player_win
=
false
;
//First player is always the cross
bool
second_player_win
=
false
;
//Second player is always the circle
};
class
morpion
:
public
game
<
morpion_state
>
...
...
@@ -24,36 +24,46 @@ namespace game
morpion
();
morpion
(
const
morpion
&
mor
)
=
default
;
morpion
&
operator
=
(
const
morpion
&
mor
)
=
default
;
bool
end_of_game
()
const
;
bool
end_of_game
()
const
;
//Is the game ended? (draw or won)
int
value
(
std
::
uint8_t
player
)
const
;
//Returns if the player win, loose or nothing
bool
won
(
std
::
uint8_t
player
)
const
;
bool
lost
(
std
::
uint8_t
player
)
const
;
bool
draw
(
std
::
uint8_t
player
)
const
;
uint8_t
current_player
()
const
;
std
::
uint16_t
number_of_moves
()
const
;
void
play
(
std
::
uint16_t
m
);
uint8_t
current_player
()
const
;
//The player that has to play next (at the beginning, the first player)
std
::
uint16_t
number_of_moves
()
const
;
//Moves played until now
void
play
(
std
::
uint16_t
m
);
//Play a move (updates the state)
void
undo
(
std
::
uint16_t
m
)
{}
std
::
string
player_to_string
(
std
::
uint8_t
player
)
const
;
std
::
string
move_to_string
(
std
::
uint16_t
m
)
const
;
std
::
string
to_string
()
const
;
std
::
string
player_to_string
(
std
::
uint8_t
player
)
const
;
//String representation of a player
std
::
string
move_to_string
(
std
::
uint16_t
m
)
const
;
//String representation of a move (for example, A1)
std
::
string
to_string
()
const
;
//String representation of the entire game
void
playout
(
std
::
mt19937
&
engine
,
int
max_depth
=
-
1
);
std
::
set
<
int
>
to_input_vector
()
const
;
void
from_input_vector
(
const
std
::
set
<
int
>&
input
);
morpion_state
get_state
();
void
set_state
(
const
morpion_state
&
state
);
morpion_state
get_state
();
//Return the state
void
set_state
(
const
morpion_state
&
state
);
//Replace the current state with the one passed as a parameter
std
::
shared_ptr
<
game
<
morpion_state
>>
do_copy
()
const
;
std
::
uint64_t
hash
(
std
::
uint16_t
m
)
const
;
std
::
uint64_t
hash
()
const
;
private
:
inline
void
update_win
();
inline
bool
has_won
(
uint16_t
bitboard
);
inline
bool
get
(
uint16_t
bitboard
,
uint8_t
i
,
uint8_t
j
)
const
;
inline
void
update_win
();
//Check if someone won and update the state
inline
bool
has_won
(
uint16_t
bitboard
);
//Check if the player whose bitboard was passed as a param has won
inline
bool
get
(
uint16_t
bitboard
,
uint8_t
i
,
uint8_t
j
)
const
;
//Get a case of the board
const
uint8_t
CROSS
=
1
;
const
uint8_t
CIRCLE
=
0
;
const
uint8_t
CROSS
=
0
;
const
uint8_t
CIRCLE
=
1
;
morpion_state
state
;
//WIN CONSTANTS
const
uint16_t
ROW0_MASK
=
504
;
const
uint16_t
ROW1_MASK
=
455
;
const
uint16_t
ROW2_MASK
=
63
;
const
uint16_t
COL0_MASK
=
438
;
const
uint16_t
COL1_MASK
=
365
;
const
uint16_t
COL2_MASK
=
219
;
const
uint16_t
DIA0_MASK
=
238
;
const
uint16_t
DIA1_MASK
=
427
;
static
std
::
vector
<
std
::
vector
<
uint64_t
>>
cross_hash_values
;
static
std
::
vector
<
std
::
vector
<
uint64_t
>>
circle_hash_values
;
...
...
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