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
835fced2
Commit
835fced2
authored
9 years ago
by
Bariatti Francesco
Browse files
Options
Downloads
Patches
Plain Diff
Fixed some errors with update moves
But is it over?
parent
19badb90
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Makefile
+2
-2
2 additions, 2 deletions
Makefile
src/game/morpion.cpp
+15
-5
15 additions, 5 deletions
src/game/morpion.cpp
src/game/morpion.hpp
+2
-1
2 additions, 1 deletion
src/game/morpion.hpp
src/game/test_morpion.cpp
+13
-1
13 additions, 1 deletion
src/game/test_morpion.cpp
with
32 additions
and
9 deletions
Makefile
+
2
−
2
View file @
835fced2
CC
=
g++
-4.9
CC
=
g++
BIN
=
bin
BIN
=
bin
INCLUDE
=
-I
src/game
-I
src/util
-I
src/monte_carlo
-I
src/mcts
-I
src/minmax
INCLUDE
=
-I
src/game
-I
src/util
-I
src/monte_carlo
-I
src/mcts
-I
src/minmax
CFLAGS
=
-g
-O3
-ffast-math
-fopenmp
-c
-Wall
-std
=
c++11
$(
INCLUDE
)
CFLAGS
=
-g
-O3
-ffast-math
-fopenmp
-c
-Wall
-std
=
c++11
$(
INCLUDE
)
LDFLAGS
=
-fopenmp
-std
=
c++11
#-lprofiler -Wl,-no_pie
LDFLAGS
=
-fopenmp
-std
=
c++11
#-lprofiler -Wl,-no_pie
SOURCES
=
omp_util.cpp fast_log.cpp display_node.cpp morpion.cpp test_morpion.cpp monte_carlo.cpp test_monte_carlo.cpp test_fast_log.cpp
\
SOURCES
=
omp_util.cpp fast_log.cpp display_node.cpp morpion.cpp test_morpion.cpp
connect4.cpp test_connect4.cpp
monte_carlo.cpp test_monte_carlo.cpp test_fast_log.cpp
\
statistics.cpp node.cpp allocator.cpp test_allocator.cpp openings.cpp mcts_two_players.cpp test_mcts_two_players.cpp test_minmax.cpp
\
statistics.cpp node.cpp allocator.cpp test_allocator.cpp openings.cpp mcts_two_players.cpp test_mcts_two_players.cpp test_minmax.cpp
\
bits.cpp test_bits.cpp main.cpp
bits.cpp test_bits.cpp main.cpp
OBJECTS
=
$(
addprefix
$(
BIN
)
/,
$(
SOURCES:.cpp
=
.o
))
OBJECTS
=
$(
addprefix
$(
BIN
)
/,
$(
SOURCES:.cpp
=
.o
))
...
...
This diff is collapsed.
Click to expand it.
src/game/morpion.cpp
+
15
−
5
View file @
835fced2
...
@@ -81,7 +81,13 @@ namespace game
...
@@ -81,7 +81,13 @@ namespace game
return
0
;
return
0
;
}
}
/* Number of moves that you can play */
uint16_t
morpion
::
number_of_moves
()
const
uint16_t
morpion
::
number_of_moves
()
const
{
return
9
-
state
.
total_moves
;
}
uint16_t
morpion
::
number_moves_played
()
const
{
{
return
state
.
total_moves
;
return
state
.
total_moves
;
}
}
...
@@ -116,16 +122,20 @@ namespace game
...
@@ -116,16 +122,20 @@ namespace game
void
morpion
::
update_moves
()
void
morpion
::
update_moves
()
{
{
uint16_t
free_bitboard
=
~
(
state
.
cross_bitboard
|
state
.
circle_bitboard
);
uint16_t
free_bitboard
=
~
(
state
.
cross_bitboard
|
state
.
circle_bitboard
);
free_bitboard
&=
ALL_ONES
;
//When we complements, all unused bits in uint_16 are complemented to. ALL_ONES is a mask in which we have ones in the position used by the bitboard
cout
<<
"Free bitboard: "
<<
free_bitboard
<<
endl
;
state
.
possible_moves
=
0
;
state
.
possible_moves
=
0
;
for
(
int
i
=
0
;
i
<=
8
;
i
++
)
uint16_t
mask
=
256
;
//256 = 100 000 000
for
(
int
i
=
8
;
i
>=
0
;
i
--
)
{
{
if
(
free_bitboard
&
1
)
if
(
free_bitboard
&
mask
)
{
{
state
.
possible_moves
+
=
i
;
state
.
possible_moves
=
state
.
possible_moves
<<
4
;
state
.
possible_moves
=
state
.
possible_moves
<<
4
;
state
.
possible_moves
|
=
i
;
}
}
free_bitboard
=
free_bitboard
>>
1
;
mask
=
mask
>>
1
;
}
}
cout
<<
"Possible moves: "
<<
state
.
possible_moves
<<
endl
;
}
}
void
morpion
::
play
(
uint16_t
m
)
void
morpion
::
play
(
uint16_t
m
)
...
...
This diff is collapsed.
Click to expand it.
src/game/morpion.hpp
+
2
−
1
View file @
835fced2
...
@@ -31,7 +31,8 @@ namespace game
...
@@ -31,7 +31,8 @@ namespace game
bool
lost
(
std
::
uint8_t
player
)
const
;
bool
lost
(
std
::
uint8_t
player
)
const
;
bool
draw
(
std
::
uint8_t
player
)
const
;
bool
draw
(
std
::
uint8_t
player
)
const
;
uint8_t
current_player
()
const
;
//The player that has to play next (at the beginning, the first player)
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
std
::
uint16_t
number_of_moves
()
const
;
//Number of moves that you can play
std
::
uint16_t
number_moves_played
()
const
;
//Number of moves played until now
void
play
(
std
::
uint16_t
m
);
//Play a move (updates the state)
void
play
(
std
::
uint16_t
m
);
//Play a move (updates the state)
void
undo
(
std
::
uint16_t
m
)
{}
void
undo
(
std
::
uint16_t
m
)
{}
std
::
string
player_to_string
(
std
::
uint8_t
player
)
const
;
//String representation of a player
std
::
string
player_to_string
(
std
::
uint8_t
player
)
const
;
//String representation of a player
...
...
This diff is collapsed.
Click to expand it.
src/game/test_morpion.cpp
+
13
−
1
View file @
835fced2
...
@@ -20,9 +20,10 @@ namespace game
...
@@ -20,9 +20,10 @@ namespace game
while
(
!
mor
.
end_of_game
())
while
(
!
mor
.
end_of_game
())
{
{
cout
<<
mor
<<
endl
;
cout
<<
mor
<<
endl
;
cout
<<
"It's"
<<
mor
.
player_to_string
(
mor
.
current_player
())
<<
"turn."
<<
endl
;
cout
<<
"It's
"
<<
mor
.
player_to_string
(
mor
.
current_player
())
<<
"
turn."
<<
endl
;
map
<
string
,
int
>
m
;
map
<
string
,
int
>
m
;
uint64_t
possible_moves
=
mor
.
get_state
().
possible_moves
;
uint64_t
possible_moves
=
mor
.
get_state
().
possible_moves
;
cout
<<
"Number of possible moves: "
<<
mor
.
number_of_moves
()
<<
endl
;
for
(
int
i
=
0
;
i
<
mor
.
number_of_moves
();
i
++
)
for
(
int
i
=
0
;
i
<
mor
.
number_of_moves
();
i
++
)
{
{
uint16_t
move
=
possible_moves
&
((
uint64_t
)
15
);
//15 = 1111 (a move is on 4 bits)
uint16_t
move
=
possible_moves
&
((
uint64_t
)
15
);
//15 = 1111 (a move is on 4 bits)
...
@@ -30,7 +31,18 @@ namespace game
...
@@ -30,7 +31,18 @@ namespace game
m
[
mor
.
move_to_string
(
move
)]
=
i
;
//In the map: the move as seen by the player and its index in possible moves
m
[
mor
.
move_to_string
(
move
)]
=
i
;
//In the map: the move as seen by the player and its index in possible moves
possible_moves
=
possible_moves
>>
4
;
possible_moves
=
possible_moves
>>
4
;
}
}
string
move
;
cin
>>
move
;
mor
.
play
(
m
[
move
]);
}
}
cout
<<
mor
<<
endl
;
if
(
mor
.
won
(
0
))
cout
<<
mor
.
player_to_string
(
0
)
<<
"has won"
<<
endl
;
else
if
(
mor
.
won
(
1
))
cout
<<
mor
.
player_to_string
(
1
)
<<
"has won"
<<
endl
;
else
cout
<<
"Draw! too bad :("
<<
endl
;
}
}
}
}
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