Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
supercomputer_lab
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Gaurav Kukreja
supercomputer_lab
Commits
8a4015aa
Commit
8a4015aa
authored
Jul 12, 2012
by
Gaurav Kukreja
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed unnecessary printf from pv-split-interactive
parent
683e2cd4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
162 additions
and
162 deletions
+162
-162
search-abid-pvsplit.cpp
mpi-assign5/pv-split-interative/search-abid-pvsplit.cpp
+162
-162
No files found.
mpi-assign5/pv-split-interative/search-abid-pvsplit.cpp
View file @
8a4015aa
...
...
@@ -26,67 +26,68 @@ extern int num_threads;
void
ABIDStrategy
::
searchBestMove
()
{
int
alpha
=
-
15000
,
beta
=
15000
;
int
nalpha
,
nbeta
,
currentValue
=
0
;
_pv
.
clear
(
_maxDepth
);
_currentBestMove
.
type
=
Move
::
none
;
_currentMaxDepth
=
1
;
/* iterative deepening loop */
do
{
int
alpha
=
-
15000
,
beta
=
15000
;
int
nalpha
,
nbeta
,
currentValue
=
0
;
_pv
.
clear
(
_maxDepth
);
_currentBestMove
.
type
=
Move
::
none
;
_currentMaxDepth
=
1
;
/* iterative deepening loop */
do
{
/* searches on same level with different alpha/beta windows */
while
(
1
)
{
nalpha
=
alpha
,
nbeta
=
beta
;
_inPV
=
(
_pv
[
0
].
type
!=
Move
::
none
);
if
(
_sc
&&
_sc
->
verbose
())
{
char
tmp
[
100
];
sprintf
(
tmp
,
"Alpha/Beta [%d;%d] with max depth %d"
,
alpha
,
beta
,
_currentMaxDepth
);
_sc
->
substart
(
tmp
);
}
currentValue
=
pv_split
(
alpha
,
beta
);
if
(
_sc
&&
_sc
->
verbose
())
printf
(
"Subsearch finished with currentValue = %d
\n
"
,
currentValue
);
/* stop searching if a win position is found */
if
(
currentValue
>
14900
||
currentValue
<
-
14900
)
_stopSearch
=
true
;
/* Don't break out if we haven't found a move */
if
(
_currentBestMove
.
type
==
Move
::
none
)
_stopSearch
=
false
;
if
(
_stopSearch
)
break
;
/* if result is outside of current alpha/beta window,
* the search has to be rerun with widened alpha/beta
*/
if
(
currentValue
<=
nalpha
)
{
alpha
=
-
15000
;
if
(
beta
<
15000
)
beta
=
currentValue
+
1
;
continue
;
}
if
(
currentValue
>=
nbeta
)
{
if
(
alpha
>
-
15000
)
alpha
=
currentValue
-
1
;
beta
=
15000
;
continue
;
}
break
;
}
/* searches on same level with different alpha/beta windows
*/
while
(
1
)
{
/* Window in both directions cause of deepening
*/
alpha
=
currentValue
-
200
,
beta
=
currentValue
+
200
;
nalpha
=
alpha
,
nbeta
=
beta
;
_inPV
=
(
_pv
[
0
].
type
!=
Move
::
none
);
if
(
_stopSearch
)
break
;
if
(
_sc
&&
_sc
->
verbose
())
{
char
tmp
[
100
];
sprintf
(
tmp
,
"Alpha/Beta [%d;%d] with max depth %d"
,
alpha
,
beta
,
_currentMaxDepth
);
_sc
->
substart
(
tmp
);
}
currentValue
=
pv_split
(
alpha
,
beta
);
printf
(
"Subsearch finished with currentValue = %d
\n
"
,
currentValue
);
/* stop searching if a win position is found */
if
(
currentValue
>
14900
||
currentValue
<
-
14900
)
_stopSearch
=
true
;
/* Don't break out if we haven't found a move */
if
(
_currentBestMove
.
type
==
Move
::
none
)
_stopSearch
=
false
;
if
(
_stopSearch
)
break
;
/* if result is outside of current alpha/beta window,
* the search has to be rerun with widened alpha/beta
*/
if
(
currentValue
<=
nalpha
)
{
alpha
=
-
15000
;
if
(
beta
<
15000
)
beta
=
currentValue
+
1
;
continue
;
}
if
(
currentValue
>=
nbeta
)
{
if
(
alpha
>
-
15000
)
alpha
=
currentValue
-
1
;
beta
=
15000
;
continue
;
}
break
;
_currentMaxDepth
++
;
}
/* Window in both directions cause of deepening */
alpha
=
currentValue
-
200
,
beta
=
currentValue
+
200
;
if
(
_stopSearch
)
break
;
while
(
_currentMaxDepth
<=
_maxDepth
);
_currentMaxDepth
++
;
}
while
(
_currentMaxDepth
<=
_maxDepth
);
_bestMove
=
_currentBestMove
;
_bestMove
=
_currentBestMove
;
}
int
ABIDStrategy
::
pv_split
(
int
alpha0
,
int
beta0
)
...
...
@@ -94,7 +95,7 @@ int ABIDStrategy::pv_split(int alpha0, int beta0)
bool
cutoff
;
int
depth
;
int
value
;
int
currentValue
=
-
15000
;
int
currentValue
=
-
15000
;
int
slave_id
;
int
num_slaves
;
int
pending_jobs
;
...
...
@@ -114,7 +115,7 @@ int ABIDStrategy::pv_split(int alpha0, int beta0)
alpha
[
0
]
=
alpha0
;
beta
[
0
]
=
beta0
;
_currentBestMove
.
type
=
Move
::
none
;
_currentBestMove
.
type
=
Move
::
none
;
// Play moves from the pv until you reach the lowest level
// If pv-moves are not possible use random moves
...
...
@@ -123,13 +124,13 @@ int ABIDStrategy::pv_split(int alpha0, int beta0)
while
(
depth
<
(
_currentMaxDepth
-
1
))
{
list
.
clear
();
_board
->
generateMoves
(
list
);
_board
->
generateMoves
(
list
);
m
=
_pv
[
depth
];
// check if pv-move is possible
if
((
m
.
type
!=
Move
::
none
)
&&
(
!
list
.
isElement
(
m
,
0
,
false
)))
m
.
type
=
Move
::
none
;
// get random move if pv-move is not possible
if
(
m
.
type
==
Move
::
none
)
list
.
getNext
(
m
,
Move
::
none
);
...
...
@@ -147,7 +148,7 @@ int ABIDStrategy::pv_split(int alpha0, int beta0)
// Devide the work at each level
depth
=
_currentMaxDepth
-
1
;
while
(
depth
>=
0
)
{
{
slave_id
=
0
;
list
.
clear
();
_board
->
generateMoves
(
list
);
...
...
@@ -161,13 +162,12 @@ int ABIDStrategy::pv_split(int alpha0, int beta0)
slave_input
.
depth
=
depth
+
1
;
slave_input
.
currentMaxDepth
=
_currentMaxDepth
;
printf
(
"Thread 0 testing %d moves at depth = %d
\n
"
,
list
.
getLength
(),
depth
);
while
(
list
.
getNext
(
m
,
Move
::
none
)
)
{
slave_input
.
move
=
m
;
MPI_Send
(
&
slave_input
,
sizeof
(
Slave_Input
),
MPI_BYTE
,
slave_id
+
1
,
10
,
MPI_COMM_WORLD
);
MPI_Irecv
(
&
slave_output
[
slave_id
],
sizeof
(
Slave_Output
),
MPI_BYTE
,
slave_id
+
1
,
10
,
MPI_COMM_WORLD
,
&
rcv_rq
[
slave_id
]);
10
,
MPI_COMM_WORLD
,
&
rcv_rq
[
slave_id
]);
slave_id
++
;
...
...
@@ -181,37 +181,37 @@ int ABIDStrategy::pv_split(int alpha0, int beta0)
while
(
pending_jobs
>
0
)
{
MPI_Waitany
(
num_slaves
,
rcv_rq
,
&
slave_id
,
MPI_STATUS_IGNORE
);
_sc
->
_leavesVisited
+=
slave_output
[
slave_id
].
num_leaves
;
_sc
->
_nodesVisited
+=
slave_output
[
slave_id
].
num_nodes
;
value
=
slave_output
[
slave_id
].
eval
;
if
(
value
>
currentValue
)
MPI_Waitany
(
num_slaves
,
rcv_rq
,
&
slave_id
,
MPI_STATUS_IGNORE
);
_sc
->
_leavesVisited
+=
slave_output
[
slave_id
].
num_leaves
;
_sc
->
_nodesVisited
+=
slave_output
[
slave_id
].
num_nodes
;
value
=
slave_output
[
slave_id
].
eval
;
if
(
value
>
currentValue
)
{
currentValue
=
value
;
_pv
=
slave_output
[
slave_id
].
pv
;
if
(
_sc
)
_sc
->
foundBestMove
(
depth
,
_pv
[
depth
],
currentValue
);
if
(
currentValue
>
alpha
[
depth
])
{
currentValue
=
value
;
_pv
=
slave_output
[
slave_id
].
pv
;
if
(
_sc
)
_sc
->
foundBestMove
(
depth
,
_pv
[
depth
],
currentValue
);
if
(
currentValue
>
alpha
[
depth
])
{
alpha
[
depth
]
=
currentValue
;
slave_input
.
beta
=
-
alpha
[
depth
];
}
/* alpha/beta cut off or win position ... */
if
(
currentValue
>
14900
||
currentValue
>=
beta
[
depth
])
cutoff
=
true
;
alpha
[
depth
]
=
currentValue
;
slave_input
.
beta
=
-
alpha
[
depth
];
}
/* alpha/beta cut off or win position ... */
if
(
currentValue
>
14900
||
currentValue
>=
beta
[
depth
])
cutoff
=
true
;
}
if
((
list
.
getNext
(
m
,
Move
::
none
))
&&
(
cutoff
==
false
))
{
slave_input
.
move
=
m
;
if
((
list
.
getNext
(
m
,
Move
::
none
))
&&
(
cutoff
==
false
))
{
slave_input
.
move
=
m
;
MPI_Send
(
&
slave_input
,
sizeof
(
Slave_Input
),
MPI_BYTE
,
slave_id
+
1
,
10
,
MPI_COMM_WORLD
);
MPI_Irecv
(
&
slave_output
[
slave_id
],
sizeof
(
Slave_Output
),
MPI_BYTE
,
slave_id
+
1
,
MPI_Send
(
&
slave_input
,
sizeof
(
Slave_Input
),
MPI_BYTE
,
slave_id
+
1
,
10
,
MPI_COMM_WORLD
);
MPI_Irecv
(
&
slave_output
[
slave_id
],
sizeof
(
Slave_Output
),
MPI_BYTE
,
slave_id
+
1
,
10
,
MPI_COMM_WORLD
,
&
rcv_rq
[
slave_id
]);
}
else
pending_jobs
--
;
}
else
pending_jobs
--
;
}
if
(
depth
>
0
)
...
...
@@ -223,11 +223,11 @@ int ABIDStrategy::pv_split(int alpha0, int beta0)
alpha
[
depth
-
1
]
=
currentValue
;
}
if
(
depth
==
0
)
_currentBestMove
=
_pv
[
0
];
_currentBestMove
=
_pv
[
0
];
if
(
_sc
)
_sc
->
finishedNode
(
depth
,
_pv
.
chain
(
depth
));
depth
--
;
}
}
free
(
slave_output
);
free
(
rcv_rq
);
...
...
@@ -247,88 +247,88 @@ int ABIDStrategy::pv_split(int alpha0, int beta0)
*/
int
ABIDStrategy
::
alphabeta
(
int
depth
,
int
alpha
,
int
beta
)
{
int
currentValue
=
-
14999
+
depth
,
value
;
Move
m
;
MoveList
list
;
bool
depthPhase
,
doDepthSearch
;
/* We make a depth search for the following move types... */
int
maxType
=
(
depth
<
_currentMaxDepth
-
1
)
?
Move
::
maxMoveType
:
(
depth
<
_currentMaxDepth
)
?
Move
::
maxPushType
:
Move
::
maxOutType
;
_board
->
generateMoves
(
list
);
if
(
_sc
&&
_sc
->
verbose
())
{
char
tmp
[
100
];
sprintf
(
tmp
,
"Alpha/Beta [%d;%d], %d moves (%d depth)"
,
alpha
,
beta
,
list
.
count
(
Move
::
none
),
list
.
count
(
maxType
));
_sc
->
startedNode
(
depth
,
tmp
);
}
// don't use moves from the principal variation
m
.
type
=
Move
::
none
;
// first, play all moves with depth search
depthPhase
=
true
;
while
(
1
)
{
// get next move
if
(
m
.
type
==
Move
::
none
)
{
if
(
depthPhase
)
depthPhase
=
list
.
getNext
(
m
,
maxType
);
if
(
!
depthPhase
)
if
(
!
list
.
getNext
(
m
,
Move
::
none
))
break
;
}
// we could start with a non-depth move from principal variation
doDepthSearch
=
depthPhase
&&
(
m
.
type
<=
maxType
);
int
currentValue
=
-
14999
+
depth
,
value
;
Move
m
;
MoveList
list
;
bool
depthPhase
,
doDepthSearch
;
_board
->
playMove
(
m
);
/* We make a depth search for the following move types... */
int
maxType
=
(
depth
<
_currentMaxDepth
-
1
)
?
Move
::
maxMoveType
:
(
depth
<
_currentMaxDepth
)
?
Move
::
maxPushType
:
Move
::
maxOutType
;
/* check for a win position first */
if
(
!
_board
->
isValid
())
{
_board
->
generateMoves
(
list
);
/* Shorter path to win position is better */
value
=
14999
-
depth
;
}
else
{
if
(
doDepthSearch
)
{
/* opponent searches for its maximum; but we want the
* minimum: so change sign (for alpha/beta window too!)
*/
value
=
-
alphabeta
(
depth
+
1
,
-
beta
,
-
alpha
);
}
else
{
value
=
evaluate
();
}
if
(
_sc
&&
_sc
->
verbose
())
{
char
tmp
[
100
];
sprintf
(
tmp
,
"Alpha/Beta [%d;%d], %d moves (%d depth)"
,
alpha
,
beta
,
list
.
count
(
Move
::
none
),
list
.
count
(
maxType
));
_sc
->
startedNode
(
depth
,
tmp
);
}
_board
->
takeBack
();
// don't use moves from the principal variation
m
.
type
=
Move
::
none
;
// first, play all moves with depth search
depthPhase
=
true
;
while
(
1
)
{
// get next move
if
(
m
.
type
==
Move
::
none
)
{
if
(
depthPhase
)
depthPhase
=
list
.
getNext
(
m
,
maxType
);
if
(
!
depthPhase
)
if
(
!
list
.
getNext
(
m
,
Move
::
none
))
break
;
}
// we could start with a non-depth move from principal variation
doDepthSearch
=
depthPhase
&&
(
m
.
type
<=
maxType
);
_board
->
playMove
(
m
);
/* best move so far? */
if
(
value
>
currentValue
)
{
currentValue
=
value
;
_pv
.
update
(
depth
,
m
);
/* check for a win position first */
if
(
!
_board
->
isValid
())
{
/* alpha/beta cut off or win position ... */
if
(
currentValue
>
14900
||
currentValue
>=
beta
)
{
if
(
_sc
)
_sc
->
finishedNode
(
depth
,
_pv
.
chain
(
depth
));
return
currentValue
;
}
/* Shorter path to win position is better */
value
=
14999
-
depth
;
}
else
{
if
(
doDepthSearch
)
{
/* opponent searches for its maximum; but we want the
* minimum: so change sign (for alpha/beta window too!)
*/
value
=
-
alphabeta
(
depth
+
1
,
-
beta
,
-
alpha
);
}
else
{
value
=
evaluate
();
}
}
/* maximize alpha */
if
(
currentValue
>
alpha
)
alpha
=
currentValue
;
_board
->
takeBack
();
/* best move so far? */
if
(
value
>
currentValue
)
{
currentValue
=
value
;
_pv
.
update
(
depth
,
m
);
/* alpha/beta cut off or win position ... */
if
(
currentValue
>
14900
||
currentValue
>=
beta
)
{
if
(
_sc
)
_sc
->
finishedNode
(
depth
,
_pv
.
chain
(
depth
));
return
currentValue
;
}
/* maximize alpha */
if
(
currentValue
>
alpha
)
alpha
=
currentValue
;
}
if
(
_stopSearch
)
break
;
// depthPhase=false;
m
.
type
=
Move
::
none
;
}
if
(
_stopSearch
)
break
;
// depthPhase=false;
m
.
type
=
Move
::
none
;
}
if
(
_sc
)
_sc
->
finishedNode
(
depth
,
_pv
.
chain
(
depth
));
if
(
_sc
)
_sc
->
finishedNode
(
depth
,
_pv
.
chain
(
depth
));
return
currentValue
;
return
currentValue
;
}
// register ourselve
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment