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
69f5ff4c
Commit
69f5ff4c
authored
8 years ago
by
Felton Samuel
Browse files
Options
Downloads
Patches
Plain Diff
Implementation of the Zone heuristic
parent
15a4e790
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
+13
-13
13 additions, 13 deletions
AI/src/game/penguin.cpp
AI/src/game/penguin.hpp
+2
-2
2 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
82 additions
and
15 deletions
AI/src/game/penguin.cpp
+
13
−
13
View file @
69f5ff4c
...
...
@@ -526,32 +526,32 @@ namespace game
return
board
;
}
uint64_t
pengin
::
penguin_move_board
(
const
uint32_t
&
pen
)
const
uint64_t
peng
u
in
::
penguin_move_board
(
const
uint32_t
&
pen
)
const
{
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
+
2
−
2
View file @
69f5ff4c
...
...
@@ -82,12 +82,12 @@ namespace game
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
();
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 @
69f5ff4c
#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