You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
157 lines
5.7 KiB
157 lines
5.7 KiB
const Presidence = Object.freeze({
|
|
General: "general",
|
|
Row: "row",
|
|
Highest: "highest",
|
|
Lowest: "lowest"
|
|
})
|
|
|
|
const AppliesTo = Object.freeze({
|
|
All: "all",
|
|
None: "none",
|
|
Capped: "capped",
|
|
Uncapped: "uncapped"
|
|
})
|
|
|
|
const Oversight = Object.freeze({
|
|
Win: "win",
|
|
Tie: "tie",
|
|
Watch: "watch",
|
|
Ignore: "ignore"
|
|
})
|
|
|
|
const Capsource = Object.freeze({
|
|
Row: "row",
|
|
General: "general"
|
|
})
|
|
|
|
function newResult(shouldApplyCap, reasonNum, trueCap, capSource, myBidNum) {
|
|
let result = {};
|
|
result.shouldApplyCap = shouldApplyCap;
|
|
result.reason = reasonNum;
|
|
result.trueCap = trueCap;
|
|
result.capSource = capSource;
|
|
result.myBid = myBidNum;
|
|
return results;
|
|
}
|
|
|
|
function getBidCapReason(generalCapIsEnabled, generalCap, capPresidence, applyPresidenceTo, oversightAction, rowCapIsEnabled, rowCap, tieBid, myBid) {
|
|
let tieBidNum = number(tieBid);
|
|
let winBidNum = number(tieBid) + 25;
|
|
let generalCapNum = number(generalCap);
|
|
let rowCapNum = number(rowCap);
|
|
let myBidNum = number(myBid);
|
|
|
|
//Build our response object
|
|
let results = newResult(false, 0, null, null, myBidNum);
|
|
|
|
//WIP - LOTS of rules here - these are just the beginning.
|
|
if(generalCapIsEnabled) {
|
|
if(capPresidence == Presidence.General) {
|
|
if(applyPresidenceTo == AppliesTo.All) {
|
|
|
|
switch(oversightAction) {
|
|
case Oversight.Win:
|
|
if(winBidNum > generalCapNum) {
|
|
results = newResult(true, 1, generalCapNum, Capsource.General, generalCapNum);
|
|
return results;
|
|
}
|
|
//winBidNum <= generalCapNum
|
|
results = newResult(false, 2, generalCapNum, Capsource.General, myBidNum);
|
|
break;
|
|
|
|
case Oversight.Tie:
|
|
if(tieBidNum > generalCapNum) {
|
|
results = newResult(true, 3, generalCapNum, Capsource.General, generalCapNum);
|
|
return results;
|
|
}
|
|
//tieBidNum <= generalCapNum
|
|
results = newResult(false, 4, generalCapNum, Capsource.General, myBidNum);
|
|
break;
|
|
|
|
case Oversight.Watch:
|
|
results = newResult(false, 5, generalCapNum, Capsource.General, myBidNum);
|
|
break;
|
|
|
|
case Oversight.Ignore:
|
|
results = newResult(false, 6, generalCapNum, Capsource.General, myBidNum);
|
|
break;
|
|
|
|
default:
|
|
//We should never get here because all oversight actions have been covered.
|
|
}
|
|
return results;
|
|
}
|
|
else if(applyPresidenceTo == AppliesTo.None){
|
|
|
|
}
|
|
else if(applyPresidenceTo == AppliesTo.Capped){
|
|
|
|
}
|
|
else if(applyPresidenceTo == AppliesTo.Uncapped){
|
|
|
|
}
|
|
return results;
|
|
}
|
|
else if(capPresidence == Presidence.Row) {
|
|
return results;
|
|
}
|
|
else if(capPresidence == Presidence.Highest){
|
|
return results;
|
|
}
|
|
else if(capPresidence == Presidence.Lowest){
|
|
return results;
|
|
}
|
|
}
|
|
|
|
//If we made it here, generalCapIsEnabled is FALSE so no conflicts should exist
|
|
//This means rowCaps are the winners if they are enabled.
|
|
if(rowCapIsEnabled) {
|
|
switch(oversightAction) {
|
|
case Oversight.Win:
|
|
if(winBidNum > rowCapNum) {
|
|
results = newResult(true, 101, rowCapNum, Capsource.Row, rowCapNum);
|
|
return results;
|
|
}
|
|
//winBidNum <= rowCapNum
|
|
results = newResult(false, 102, rowCapNum, Capsource.Row, myBidNum);
|
|
break;
|
|
|
|
case Oversight.Tie:
|
|
if(tieBidNum > rowCapNum) {
|
|
results = newResult(true, 103, rowCapNum, Capsource.Row, rowCapNum);
|
|
return results;
|
|
}
|
|
//tieBidNum <= generalCapNum
|
|
results = newResult(false, 104, rowCapNum, Capsource.Row, myBidNum);
|
|
break;
|
|
|
|
case Oversight.Watch:
|
|
results = newResult(false, 105, null, Capsource.Row, myBidNum);
|
|
break;
|
|
|
|
case Oversight.Ignore:
|
|
results = newResult(false, 106, null, Capsource.Row, myBidNum);
|
|
break;
|
|
default:
|
|
//We should never get here because all oversight actions have been covered.
|
|
}
|
|
return results;
|
|
}
|
|
//Caps are not enabled for this row.
|
|
|
|
return results;
|
|
}
|
|
|
|
|
|
const expected1 = {};
|
|
const ShouldApplyCap = true;
|
|
const GeneralCapIsEnabled = true;
|
|
const RowCapIsEnabled = true;
|
|
|
|
|
|
// generalCapIsEnabled , generalCap , capPresidence , applyPresidenceTo , oversightAction , rowCapIsEnabled , rowCap , tieBid , myBid
|
|
const results1 = getBidCapReason( GeneralCapIsEnabled , 300 , Presidence.General , AppliesTo.All , Oversight.Win , !RowCapIsEnabled , null , 500 , 300 );
|
|
const results2 = getBidCapReason( GeneralCapIsEnabled , 300 , Presidence.General , AppliesTo.All , Oversight.Win , RowCapIsEnabled , 450 , 500 , 300 );
|
|
const results3 = getBidCapReason( GeneralCapIsEnabled , 300 , Presidence.General , AppliesTo.All , Oversight.Tie , !RowCapIsEnabled , null , 500 , 300 );
|
|
|
|
console.log(results1.shouldApplyCap = true && results1.reason == 1 && results1.trueCap == 200 && results1.capSource == Capsource.General && mybid == 300);
|
|
|