Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
noobpwnftw committed Aug 23, 2023
1 parent 9f64cd1 commit 3d1ff46
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 28 deletions.
67 changes: 61 additions & 6 deletions web/cdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ function getMovesWithCheck( $redis, $row, $ply, $enumlimit, $resetlimit, $learn,
}
return $moves1;
}
function getAnalysisPath( $redis, $row, $ply, $enumlimit, $isbest, $learn, $depth, &$pv ) {
function getAnalysisPath( $redis, $row, $ply, $enumlimit, $isbest, $learn, $depth, &$pv, $stable ) {
list( $moves1, $finals ) = getAllScores( $redis, $row );
$BWfen = cbgetBWfen( $row );

Expand Down Expand Up @@ -833,8 +833,53 @@ function getAnalysisPath( $redis, $row, $ply, $enumlimit, $isbest, $learn, $dept
$moves2[ $key ] = $item;
}
}
shuffle_assoc( $moves2 );
arsort( $moves2 );
if( !$stable )
{
shuffle_assoc( $moves2 );
arsort( $moves2 );
}
else
{
$moves3 = array();
foreach( $moves2 as $key => $item ) {
$moves3[ $key ][0] = 0;
$moves3[ $key ][1] = 0;
if( isset( $finals[ $key ] ) )
continue;
$nextfen = cbmovemake( $row, $key );
list( $nextmoves, $variations ) = getMoves( $redis, $nextfen, false, false, $depth );
if( count( $nextmoves ) > 0 ) {
arsort( $nextmoves );
$nextscore = reset( $nextmoves );
$throttle = getthrottle( $nextscore );
$nextsum = 0;
$nextcount = 0;
$totalvalue = 0;
foreach( $nextmoves as $record => $score ) {
if( $score >= $throttle ) {
$nextcount++;
$nextsum = $nextsum + $score;
$totalvalue = $totalvalue + $nextsum;
}
else
break;
}
$moves3[ $key ][0] = count( $nextmoves );
$moves3[ $key ][1] = $nextcount;
}
}
uksort( $moves2, function ( $a, $b ) use ( $moves2, $moves3 ) {
if( $moves2[$a] != $moves2[$b] ) {
return $moves2[$b] - $moves2[$a];
} else if( $moves3[$a][1] != $moves3[$b][1] ) {
return $moves3[$a][1] - $moves3[$b][1];
} else if( $moves3[$a][0] != $moves3[$b][0] ) {
return $moves3[$b][0] - $moves3[$a][0];
} else {
return $a - $b;
}
} );
}
foreach( $moves2 as $key => $item ) {
$GLOBALS['counter']++;
if( $isbest ) {
Expand All @@ -847,7 +892,7 @@ function getAnalysisPath( $redis, $row, $ply, $enumlimit, $isbest, $learn, $dept
$nextfen = cbmovemake( $row, $key );
$GLOBALS['historytt'][$current_hash]['fen'] = $nextfen;
$GLOBALS['historytt'][$current_hash]['move'] = $key;
$nextmoves = getAnalysisPath( $redis, $nextfen, $ply + 1, $enumlimit, $isbest, false, $depth, $pv );
$nextmoves = getAnalysisPath( $redis, $nextfen, $ply + 1, $enumlimit, $isbest, false, $depth, $pv, $stable );
$isbest = false;
unset( $GLOBALS['historytt'][$current_hash] );
if( isset( $GLOBALS['loopcheck'] ) ) {
Expand Down Expand Up @@ -1767,8 +1812,12 @@ function is_true( $val ) {
uksort( $statmoves, function ( $a, $b ) use ( $statmoves, $variations ) {
if( $statmoves[$a] != $statmoves[$b] ) {
return $statmoves[$b] - $statmoves[$a];
} else {
} else if( $variations[$a][1] != $variations[$b][1] ) {
return $variations[$a][1] - $variations[$b][1];
} else if( $variations[$a][0] != $variations[$b][0] ) {
return $variations[$b][0] - $variations[$a][0];
} else {
return $a - $b;
}
} );
$maxscore = reset( $statmoves );
Expand Down Expand Up @@ -2016,11 +2065,17 @@ function is_true( $val ) {
}
else if( $action == 'querypv' ) {
$pv = array();
if( isset( $_REQUEST['stable'] ) ) {
$stable = is_true( $_REQUEST['stable'] );
}
else {
$stable = false;
}
$GLOBALS['counter'] = 0;
$GLOBALS['boardtt'] = new Judy( Judy::STRING_TO_INT );
$redis = new Redis();
$redis->pconnect('192.168.1.2', 8888, 1.0);
$statmoves = getAnalysisPath( $redis, $row, 0, 200, true, $learn, 0, $pv );
$statmoves = getAnalysisPath( $redis, $row, 0, 200, true, $learn, 0, $pv, $stable );
if( count( $statmoves ) > 0 ) {
if( $isJson )
echo '"status":"ok","score":' . $statmoves[$pv[0]] . ',"depth":' . count( $pv ) . ',"pv":["' . implode( '","', $pv ) . '"],"pvSAN":["' . implode( '","', cbmovesan( $row, $pv ) ) . '"]';
Expand Down
67 changes: 61 additions & 6 deletions web/chessdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ function getMovesWithCheck( $redis, $row, $banmoves, $ply, $enumlimit, $resetlim
}
return $moves1;
}
function getAnalysisPath( $redis, $row, $banmoves, $ply, $enumlimit, $isbest, $learn, $depth, &$pv ) {
function getAnalysisPath( $redis, $row, $banmoves, $ply, $enumlimit, $isbest, $learn, $depth, &$pv, $stable ) {
list( $moves1, $finals ) = getAllScores( $redis, $row );
$LRfen = ccbgetLRfen( $row );
$BWfen = ccbgetBWfen( $row );
Expand Down Expand Up @@ -1236,8 +1236,53 @@ function getAnalysisPath( $redis, $row, $banmoves, $ply, $enumlimit, $isbest, $l
$moves2[ $key ] = $item;
}
}
shuffle_assoc( $moves2 );
arsort( $moves2 );
if( !$stable )
{
shuffle_assoc( $moves2 );
arsort( $moves2 );
}
else
{
$moves3 = array();
foreach( $moves2 as $key => $item ) {
$moves3[ $key ][0] = 0;
$moves3[ $key ][1] = 0;
if( isset( $finals[ $key ] ) )
continue;
$nextfen = ccbmovemake( $row, $key );
list( $nextmoves, $variations ) = getMoves( $redis, $nextfen, array(), false, false, false, $depth );
if( count( $nextmoves ) > 0 ) {
arsort( $nextmoves );
$nextscore = reset( $nextmoves );
$throttle = getthrottle( $nextscore );
$nextsum = 0;
$nextcount = 0;
$totalvalue = 0;
foreach( $nextmoves as $record => $score ) {
if( $score >= $throttle ) {
$nextcount++;
$nextsum = $nextsum + $score;
$totalvalue = $totalvalue + $nextsum;
}
else
break;
}
$moves3[ $key ][0] = count( $nextmoves );
$moves3[ $key ][1] = $nextcount;
}
}
uksort( $moves2, function ( $a, $b ) use ( $moves2, $moves3 ) {
if( $moves2[$a] != $moves2[$b] ) {
return $moves2[$b] - $moves2[$a];
} else if( $moves3[$a][1] != $moves3[$b][1] ) {
return $moves3[$a][1] - $moves3[$b][1];
} else if( $moves3[$a][0] != $moves3[$b][0] ) {
return $moves3[$b][0] - $moves3[$a][0];
} else {
return $a - $b;
}
} );
}
foreach( $moves2 as $key => $item ) {
$GLOBALS['counter']++;
if( $isbest ) {
Expand All @@ -1250,7 +1295,7 @@ function getAnalysisPath( $redis, $row, $banmoves, $ply, $enumlimit, $isbest, $l
$nextfen = ccbmovemake( $row, $key );
$GLOBALS['historytt'][$current_hash]['fen'] = $nextfen;
$GLOBALS['historytt'][$current_hash]['move'] = $key;
$nextmoves = getAnalysisPath( $redis, $nextfen, array(), $ply + 1, $enumlimit, $isbest, false, $depth, $pv );
$nextmoves = getAnalysisPath( $redis, $nextfen, array(), $ply + 1, $enumlimit, $isbest, false, $depth, $pv, $stable );
$isbest = false;
unset( $GLOBALS['historytt'][$current_hash] );
if( isset( $GLOBALS['loopcheck'] ) ) {
Expand Down Expand Up @@ -2123,8 +2168,12 @@ function is_true( $val ) {
uksort( $statmoves, function ( $a, $b ) use ( $statmoves, $variations ) {
if( $statmoves[$a] != $statmoves[$b] ) {
return $statmoves[$b] - $statmoves[$a];
} else {
} else if( $variations[$a][1] != $variations[$b][1] ) {
return $variations[$a][1] - $variations[$b][1];
} else if( $variations[$a][0] != $variations[$b][0] ) {
return $variations[$b][0] - $variations[$a][0];
} else {
return $a - $b;
}
} );
$maxscore = reset( $statmoves );
Expand Down Expand Up @@ -2275,11 +2324,17 @@ function is_true( $val ) {
}
else if( $action == 'querypv' ) {
$pv = array();
if( isset( $_REQUEST['stable'] ) ) {
$stable = is_true( $_REQUEST['stable'] );
}
else {
$stable = false;
}
$GLOBALS['counter'] = 0;
$GLOBALS['boardtt'] = new Judy( Judy::STRING_TO_INT );
$redis = new Redis();
$redis->pconnect('192.168.1.2', 8889, 1.0);
$statmoves = getAnalysisPath( $redis, $row, $banmoves, 0, 200, true, $learn, 0, $pv );
$statmoves = getAnalysisPath( $redis, $row, $banmoves, 0, 200, true, $learn, 0, $pv, $stable );
if( count( $statmoves ) > 0 ) {
echo 'score:' . $statmoves[$pv[0]] . ',depth:' . count( $pv ) . ',pv:' . implode( '|', $pv );
}
Expand Down
8 changes: 4 additions & 4 deletions web/query/file/xiangqi.js
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ function ChangeFen(id) {
return;
}

function FillPV(id) {
function FillPV(id, stable) {
if (busy)
return;
busy = 1;
Expand All @@ -1152,7 +1152,7 @@ function FillPV(id) {

var xmlhttpPV = getXmlHttp();

xmlhttpPV.open('GET', apiurl + '?action=querypv&board=' + b[2], true);
xmlhttpPV.open('GET', apiurl + '?action=querypv&board=' + b[2] + "&stable=" + stable, true);
xmlhttpPV.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttpPV.onreadystatechange = function() {
if (xmlhttpPV.readyState == 4) {
Expand Down Expand Up @@ -1185,7 +1185,7 @@ function FillPV(id) {
function mclick(e, id) {
e.preventDefault();
if (e.shiftKey) {
FillPV(id);
FillPV(id, true);
}
else {
ChangeFen(id);
Expand All @@ -1195,7 +1195,7 @@ function mclick(e, id) {

function mcontext(e, id) {
e.preventDefault();
FillPV(id);
FillPV(id, e.shiftKey);
return false;
}

Expand Down
8 changes: 4 additions & 4 deletions web/query_en/file/xiangqi.js
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ function ChangeFen(id) {
return;
}

function FillPV(id) {
function FillPV(id, stable) {
if (busy)
return;
busy = 1;
Expand All @@ -1152,7 +1152,7 @@ function FillPV(id) {

var xmlhttpPV = getXmlHttp();

xmlhttpPV.open('GET', apiurl + '?action=querypv&board=' + b[2], true);
xmlhttpPV.open('GET', apiurl + '?action=querypv&board=' + b[2] + "&stable=" + stable, true);
xmlhttpPV.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttpPV.onreadystatechange = function() {
if (xmlhttpPV.readyState == 4) {
Expand Down Expand Up @@ -1185,7 +1185,7 @@ function FillPV(id) {
function mclick(e, id) {
e.preventDefault();
if (e.shiftKey) {
FillPV(id);
FillPV(id, true);
}
else {
ChangeFen(id);
Expand All @@ -1195,7 +1195,7 @@ function mclick(e, id) {

function mcontext(e, id) {
e.preventDefault();
FillPV(id);
FillPV(id, e.shiftKey);
return false;
}

Expand Down
8 changes: 4 additions & 4 deletions web/queryc/file/cdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ function Initialize2() {
return;
}

function FillPV(id) {
function FillPV(id, stable) {
if (busy)
return;
busy = 1;
Expand All @@ -1045,7 +1045,7 @@ function FillPV(id) {

var xmlhttpPV = getXmlHttp();

xmlhttpPV.open('GET', apiurl + '?action=querypv&board=' + b[2], true);
xmlhttpPV.open('GET', apiurl + '?action=querypv&board=' + b[2] + "&stable=" + stable, true);
xmlhttpPV.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttpPV.onreadystatechange = function() {
if (xmlhttpPV.readyState == 4) {
Expand Down Expand Up @@ -1079,7 +1079,7 @@ function FillPV(id) {
function mclick(e, id) {
e.preventDefault();
if (e.shiftKey) {
FillPV(id);
FillPV(id, true);
}
else {
ChangeFen(id);
Expand All @@ -1089,7 +1089,7 @@ function mclick(e, id) {

function mcontext(e, id) {
e.preventDefault();
FillPV(id);
FillPV(id, e.shiftKey);
return false;
}

Expand Down
8 changes: 4 additions & 4 deletions web/queryc_en/file/cdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ function Initialize2() {
return;
}

function FillPV(id) {
function FillPV(id, stable) {
if (busy)
return;
busy = 1;
Expand All @@ -1045,7 +1045,7 @@ function FillPV(id) {

var xmlhttpPV = getXmlHttp();

xmlhttpPV.open('GET', apiurl + '?action=querypv&board=' + b[2], true);
xmlhttpPV.open('GET', apiurl + '?action=querypv&board=' + b[2] + "&stable=" + stable, true);
xmlhttpPV.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttpPV.onreadystatechange = function() {
if (xmlhttpPV.readyState == 4) {
Expand Down Expand Up @@ -1079,7 +1079,7 @@ function FillPV(id) {
function mclick(e, id) {
e.preventDefault();
if (e.shiftKey) {
FillPV(id);
FillPV(id, true);
}
else {
ChangeFen(id);
Expand All @@ -1089,7 +1089,7 @@ function mclick(e, id) {

function mcontext(e, id) {
e.preventDefault();
FillPV(id);
FillPV(id, e.shiftKey);
return false;
}

Expand Down

0 comments on commit 3d1ff46

Please sign in to comment.