add back comments

This commit is contained in:
David Westgate 2025-03-09 12:54:39 -07:00
parent 31e0a7a995
commit 1216e76381
3 changed files with 17 additions and 2 deletions

View File

@ -9,7 +9,8 @@
"userInterfaceStyle": "automatic", "userInterfaceStyle": "automatic",
"newArchEnabled": true, "newArchEnabled": true,
"ios": { "ios": {
"supportsTablet": true "supportsTablet": true,
"bundleIdentifier": "com.anonymous.pokerchipshelper"
}, },
"android": { "android": {
"adaptiveIcon": { "adaptiveIcon": {

View File

@ -61,7 +61,7 @@ const BuyInSelector: React.FC<BuyInSelectorProps> = ({
/> />
<Text style={styles.h2}> <Text style={styles.h2}>
{`${i18n.t("selected_buy_in")}: `} {`${i18n.t("selected_buy_in")} `}
{buyInAmount !== null {buyInAmount !== null
? `${selectedCurrency} ${buyInAmount}` ? `${selectedCurrency} ${buyInAmount}`
: i18n.t("none")} : i18n.t("none")}

View File

@ -12,6 +12,8 @@ interface ChipDistributionSummaryProps {
selectedCurrency: string; selectedCurrency: string;
} }
const reverseFib: number[] = [8, 5, 3, 2, 1];
const ChipDistributionSummary = ({ const ChipDistributionSummary = ({
playerCount, playerCount,
buyInAmount, buyInAmount,
@ -47,6 +49,8 @@ const ChipDistributionSummary = ({
return current; return current;
}; };
// Bound for the value of the highest chip
// This is somewhat arbitray, but 1/3 to 1/4 is reasonable depending on the number of colors.
const maxDenomination = useMemo(() => { const maxDenomination = useMemo(() => {
if (totalChipsCount.length > 3) { if (totalChipsCount.length > 3) {
return findFloorDenomination(buyInAmount / 3); return findFloorDenomination(buyInAmount / 3);
@ -60,6 +64,7 @@ const ChipDistributionSummary = ({
[buyInAmount, playerCount] [buyInAmount, playerCount]
); );
// The total value of all chips distributed to a single player. Ideally should be equal to buyInAmount
const totalValue = useMemo(() => { const totalValue = useMemo(() => {
let value = 0; let value = 0;
for (let i = 0; i < totalChipsCount.length; i++) { for (let i = 0; i < totalChipsCount.length; i++) {
@ -68,11 +73,14 @@ const ChipDistributionSummary = ({
return value; return value;
}, [distributions, denominations]); }, [distributions, denominations]);
// Maximum quantity of each chip color which may be distributed to a single player before running out
const maxPossibleDistribution = useMemo( const maxPossibleDistribution = useMemo(
() => totalChipsCount.map((v) => Math.floor(v / playerCount)), () => totalChipsCount.map((v) => Math.floor(v / playerCount)),
[totalChipsCount, playerCount] [totalChipsCount, playerCount]
); );
// Redenominate the chips in case of failure to properly distribute.
// Move the shuffle index to the next lowest denomination, and keep all else same
const redenominate = useCallback( const redenominate = useCallback(
( (
invalidDenomination: validDenomination[], invalidDenomination: validDenomination[],
@ -102,6 +110,7 @@ const ChipDistributionSummary = ({
[] []
); );
// Dynamically set denominations and distributions from changing inputs
useEffect(() => { useEffect(() => {
let testDenomination: validDenomination[] = []; let testDenomination: validDenomination[] = [];
const numColors = totalChipsCount.length; const numColors = totalChipsCount.length;
@ -110,6 +119,7 @@ const ChipDistributionSummary = ({
testDistribution.push(0); testDistribution.push(0);
} }
// Start with max denominations, then push on the next adjacent lower denomination
testDenomination.push(maxDenomination); testDenomination.push(maxDenomination);
let currentDenominationIndex: number = let currentDenominationIndex: number =
validDenominations.indexOf(maxDenomination); validDenominations.indexOf(maxDenomination);
@ -120,6 +130,9 @@ const ChipDistributionSummary = ({
} }
testDenomination.reverse(); testDenomination.reverse();
// Distribute the chips using the test denomination
// If distribution fails to equal the buy-in, redenominate and re-try
// Algorithm could be improved with more complexity and optimization
let remainingValue = buyInAmount; let remainingValue = buyInAmount;
let fail = true; let fail = true;
let failCount = 0; let failCount = 0;
@ -162,6 +175,7 @@ const ChipDistributionSummary = ({
<Text <Text
style={{ style={{
...styles.h2, ...styles.h2,
fontWeight: "bold",
color: colors[index], color: colors[index],
...(colors[index] === "white" && styles.shadow), ...(colors[index] === "white" && styles.shadow),
}} }}