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
48105ae7
Commit
48105ae7
authored
8 years ago
by
Pizon Antoine
Browse files
Options
Downloads
Plain Diff
Merge
parents
be0fac28
69f5ff4c
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
AI/src/game/penguin.cpp
+12
-12
12 additions, 12 deletions
AI/src/game/penguin.cpp
AI/src/game/penguin.hpp
+4
-2
4 additions, 2 deletions
AI/src/game/penguin.hpp
AI/src/heuristics/zone_heuristic.hpp
+67
-0
67 additions, 0 deletions
AI/src/heuristics/zone_heuristic.hpp
with
83 additions
and
14 deletions
AI/src/game/penguin.cpp
+
12
−
12
View file @
48105ae7
...
...
@@ -530,28 +530,28 @@ namespace game
{
uint64_t
board
=
0
;
//Direction A
for
(
int
i
=
1
;
i
<=
PENGUIN_MOVES_A
(
pen
);
i
++
){
board
|=
((
uint64_t
)
1
<<
PENGUIN_POS
(
pen
)
+
i
*
7
);
for
(
u
int
i
=
1
;
i
<=
PENGUIN_MOVES_A
(
pen
);
i
++
){
board
|=
((
uint64_t
)
1
<<
(
PENGUIN_POS
(
pen
)
+
i
*
7
)
)
;
}
//Direction B
for
(
int
i
=
1
;
i
<=
PENGUIN_MOVES_B
(
pen
);
i
++
){
board
|=
((
uint64_t
)
1
<<
PENGUIN_POS
(
pen
)
+
i
*
(
-
1
));
for
(
u
int
i
=
1
;
i
<=
PENGUIN_MOVES_B
(
pen
);
i
++
){
board
|=
((
uint64_t
)
1
<<
(
PENGUIN_POS
(
pen
)
+
i
*
(
-
1
))
)
;
}
//Direction C
for
(
int
i
=
1
;
i
<=
PENGUIN_MOVES_C
(
pen
);
i
++
){
board
|=
((
uint64_t
)
1
<<
PENGUIN_POS
(
pen
)
+
i
*
(
-
8
));
for
(
u
int
i
=
1
;
i
<=
PENGUIN_MOVES_C
(
pen
);
i
++
){
board
|=
((
uint64_t
)
1
<<
(
PENGUIN_POS
(
pen
)
+
i
*
(
-
8
))
)
;
}
//Direction D
for
(
int
i
=
1
;
i
<=
PENGUIN_MOVES_D
(
pen
);
i
++
){
board
|=
((
uint64_t
)
1
<<
PENGUIN_POS
(
pen
)
+
i
*
(
-
7
));
for
(
u
int
i
=
1
;
i
<=
PENGUIN_MOVES_D
(
pen
);
i
++
){
board
|=
((
uint64_t
)
1
<<
(
PENGUIN_POS
(
pen
)
+
i
*
(
-
7
))
)
;
}
//Direction E
for
(
int
i
=
1
;
i
<=
PENGUIN_MOVES_E
(
pen
);
i
++
){
board
|=
((
uint64_t
)
1
<<
PENGUIN_POS
(
pen
)
+
i
*
1
);
for
(
u
int
i
=
1
;
i
<=
PENGUIN_MOVES_E
(
pen
);
i
++
){
board
|=
((
uint64_t
)
1
<<
(
PENGUIN_POS
(
pen
)
+
i
*
1
)
)
;
}
//Direction F
for
(
int
i
=
1
;
i
<=
PENGUIN_MOVES_A
(
pen
);
i
++
){
board
|=
((
uint64_t
)
1
<<
PENGUIN_POS
(
pen
)
+
i
*
8
);
for
(
u
int
i
=
1
;
i
<=
PENGUIN_MOVES_A
(
pen
);
i
++
){
board
|=
((
uint64_t
)
1
<<
(
PENGUIN_POS
(
pen
)
+
i
*
8
)
)
;
}
return
board
;
}
...
...
This diff is collapsed.
Click to expand it.
AI/src/game/penguin.hpp
+
4
−
2
View file @
48105ae7
...
...
@@ -80,15 +80,17 @@ namespace game
const
tile_content
get_tile
(
std
::
uint8_t
tile_index
)
const
;
static
penguin_state
random_start_state
();
std
::
uint64_t
penguin_board
(
bool
)
const
;
// true for position of blue penguin, else false
uint64_t
penguin_move_board
(
const
uint32_t
&
pen
)
const
;
//Bitboard of possible move of the penguin
uint8_t
turns_played
()
const
;
int
update_penguin_moves
(
uint32_t
*
p
,
uint64_t
obstacles
);
uint64_t
create_obstacles_bitboard
();
uint32_t
move_to_pos
(
uint16_t
m
);
private
:
penguin_state
state
;
void
move_penguin
(
uint32_t
*
p
,
uint16_t
rel_move
);
uint64_t
create_obstacles_bitboard
();
int
update_penguin_moves
(
uint32_t
*
p
,
uint64_t
obstacles
);
const
uint8_t
RED
=
0
;
const
uint8_t
BLUE
=
1
;
...
...
This diff is collapsed.
Click to expand it.
AI/src/heuristics/zone_heuristic.hpp
0 → 100644
+
67
−
0
View file @
48105ae7
#ifndef __PENGUIN_ZONE_HEURISTIC_FREEDOM_HPP__
#define __PENGUIN_ZONE_HEURISTIC_FREEDOM_HPP__
#include
"penguin.hpp"
#include
"heuristic.hpp"
#include
"penguin_heuristic.hpp"
#include
<algorithm>
namespace
mcts
{
class
zone_heuristic
:
public
penguin_heuristic
{
public:
float
get_value
(
const
game
::
penguin
&
game
,
uint8_t
move
)
const
{
game
::
penguin
g
=
*
(
game
::
copy
(
game
));
g
.
play
(
move
);
auto
s
=
g
.
get_state
();
uint32_t
*
penguins
=
s
.
current_player_red
?
s
.
peng_red
:
s
.
peng_blue
;
uint32_t
*
other_peng
=
s
.
current_player_red
?
s
.
peng_blue
:
s
.
peng_red
;
uint64_t
obstacles
=
g
.
create_obstacles_bitboard
();
uint64_t
moves_this
=
0
;
uint64_t
moves_other
=
0
;
for
(
int
i
=
0
;
i
<
4
;
++
i
)
{
//g.update_penguin_moves(&other_peng[i],obstacles);
//g.update_penguin_moves(&penguins[i],obstacles);
}
//std::cout << "CURRENT PLAYER RED : " << s.current_player_red << std::endl;
//std::cout << "NB MOVES RED : " << s.nb_moves_red << std::endl;
//std::cout << "NB MOVES BLUE : " << s.nb_moves_blue << std::endl;
for
(
int
i
=
0
;
i
<
4
;
++
i
)
{
moves_this
|=
g
.
penguin_move_board
(
penguins
[
i
]);
moves_other
|=
g
.
penguin_move_board
(
other_peng
[
i
]);
}
uint64_t
this_owned_moves
=
moves_this
&
~
(
moves_other
);
uint64_t
other_owned_moves
=
moves_other
&
~
(
moves_this
);
int
count_this
=
0
;
int
count_other
=
0
;
for
(
int
i
=
0
;
i
<
60
;
i
++
)
{
count_this
+=
(
this_owned_moves
>>
i
)
&
1
;
count_other
+=
(
other_owned_moves
>>
i
)
&
1
;
}
std
::
cout
<<
"COUNT_THIS : "
<<
count_this
<<
std
::
endl
;
std
::
cout
<<
"COUNT_OTHER : "
<<
count_other
<<
std
::
endl
;
std
::
cout
<<
clamp
((
float
)(
count_this
-
count_other
)
/
(
count_this
+
1
),
-
1.
f
,
1.
f
)
<<
std
::
endl
;
return
clamp
((
float
)(
count_this
-
count_other
)
/
(
count_this
+
1
),
-
1.
f
,
1.
f
);
}
int
get_count
(
const
game
::
penguin
&
game
,
uint8_t
move
)
const
{
return
100
;
}
private
:
float
clamp
(
float
v
,
float
l
,
float
h
)
const
{
return
std
::
max
(
std
::
min
(
h
,
v
),
l
);
}
};
};
#endif
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