-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckoutEngine.js
More file actions
89 lines (82 loc) · 3.03 KB
/
checkoutEngine.js
File metadata and controls
89 lines (82 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
=============================================================================
checkoutEngine.js
Version 1.0.6b 2026-06-10 22h00
=============================================================================
*/
//==============================================================================
function sortRoutes( routes ){
routes.sort(
( a, b )=>{
if( a.diff !== b.diff ){return a.diff - b.diff;}
return 0;
}
);
}
//==============================================================================
function getDN( score ){
let scoreInfo = DFC_STATE.scores[score];
if( !scoreInfo ){return 99;}
return scoreInfo.DARTSNEEDED;
}
//==============================================================================
function isBustScore( score ){return score < 0 || score === 1; }
//==============================================================================
function getNxtDrtClr( scoreBefore, segment ){
let scoreAfter = scoreBefore - segment.SegVal;
if( isBustScore( scoreAfter ) || ( scoreAfter === 0 && segment.SegMulti !== 2 ) ){return NDP_COLORS[3];}
let diff = getDN( scoreBefore ) - getDN( scoreAfter );
return NDP_COLORS[diff + 1] || NDP_COLORS[3];
}
//==============================================================================
function getProfileDF( profile ){
let diff = 0;
let parts = profile.split( "-" );
for( let part of parts ){diff = diff + DFfromProfile[part];}
return diff;
}
//==============================================================================
function makeRoute( segment, scoreBefore, scoreAfter ){
let scoreInfo = DFC_STATE.scores[scoreAfter];
let leaveProfile = scoreInfo.EZVISITPROFILE;
let segmentDF = segment.SegDF;
let diff = segmentDF + ( scoreInfo.DARTSNEEDED * LEAVE_DN_MULTIPLIER ) + getProfileDF( leaveProfile );
return {
diff: diff,
darts: [
{
seg: segment.SegId,
val: segment.SegVal,
multi: segment.SegMulti,
df: segmentDF
}
],
dnAfter: getDN( scoreAfter ),
dnBefore: getDN( scoreBefore ),
dnDiff: getDN( scoreBefore ) - getDN( scoreAfter ),
leaveDF: [ getDN( scoreAfter ), leaveProfile ],
scoreAfter: scoreAfter,
type: scoreAfter === 0 ? "finish" : "setup"
};
}
//==============================================================================
function getRoutes( scoreBefore, dih ){
console.log( "getRoutes: starting" );
let routes = [];
let routeKeys = {};
let dnBefore = getDN( scoreBefore );
if( isBustScore( scoreBefore ) || dih <= 0 ){return routes;}
for( let segment of DFC_STATE.segments ){
let scoreAfter = scoreBefore - segment.SegVal;
if( segment.SegVal <= 0 ){continue;}
if( isBustScore( scoreAfter ) || ( scoreAfter === 0 && segment.SegMulti !== 2 ) ){continue;}
if( getDN( scoreAfter ) !== dnBefore - 1 ){continue;}
let routeKey = segment.SegId + "-" + scoreAfter;
if( routeKeys[routeKey] ){continue;}
routeKeys[routeKey] = true;
routes.push( makeRoute( segment, scoreBefore, scoreAfter ) );
}
sortRoutes( routes );
return routes.slice( 0, MAX_FINISH_ROUTES );
}
//==============================================================================