Skip to content

Commit

Permalink
Match coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
TwelveNights committed Oct 7, 2016
1 parent 661b034 commit 22eb957
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 145 deletions.
2 changes: 1 addition & 1 deletion imports/api/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const Constants = {
NORTH: "north",

MAHJONG_CLUB_LEAGUE: "Mahjong Club League",
MANGAN: 2000
MANGAN_BASIC_POINTS: 2000
};

Object.keys(Constants).forEach((k) => { Template.registerHelper(k, () => Constants[k] )});
32 changes: 16 additions & 16 deletions imports/api/NewGameUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ export var NewGameUtils = {

// This code could be streamlined, but let's leave it explicit
switch (gameType) {
case Constants.GAME_TYPE.HONG_KONG:
if (round <= 4)
return "東";
if (round > 4 && round <= 8)
return "南";
if (round > 8 && round <= 12)
return "西";
else //if (round > 12)
return "北";
case Constants.GAME_TYPE.JAPANESE:
if (round <= 4)
return "東";
if (round > 4 && round <= 8)
return "南";
else //if (round > 8)
return "西";
case Constants.GAME_TYPE.HONG_KONG:
if (round <= 4)
return "東";
if (round > 4 && round <= 8)
return "南";
if (round > 8 && round <= 12)
return "西";
else //if (round > 12)
return "北";
case Constants.GAME_TYPE.JAPANESE:
if (round <= 4)
return "東";
if (round > 4 && round <= 8)
return "南";
else //if (round > 8)
return "西";
};
},

Expand Down
178 changes: 89 additions & 89 deletions imports/api/PointCalculationUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,117 +2,117 @@ import { Constants } from './Constants';
import { NewGameUtils } from './NewGameUtils';

export var PointCalculationUtils = {
jpn: {
"dealin_delta": dealin_delta,
"selfdraw_delta": selfdraw_delta,
"fuckup_delta": fuckup_delta
}
jpn: {
"dealin_delta": dealin_delta,
"selfdraw_delta": selfdraw_delta,
"fuckup_delta": fuckup_delta
}
};

function dealin_delta(points, fu, winnerWind, loserWind, riichiSticks) {
let winds = {};
winds[Constants.EAST] = winds[Constants.SOUTH] = winds[Constants.WEST] = winds[Constants.NORTH] = 0;
let winds = {};
winds[Constants.EAST] = winds[Constants.SOUTH] = winds[Constants.WEST] = winds[Constants.NORTH] = 0;

let basicPoints;
let multiplier = (winnerWind != NewGameUtils.roundToDealerDirection(Number(Session.get("current_round")))) ? 4 : 6;
let manganPayout = multiplier * Constants.MANGAN;
let multiplier = (winnerWind != NewGameUtils.roundToDealerDirection(Number(Session.get("current_round")))) ? 4 : 6;
let manganPayout = multiplier * Constants.MANGAN_BASIC_POINTS;

if (points < 5) {
if (fu == 20 || (points == 1 && fu == 25)) {
return 0; // Issue Protection
} else {
basicPoints = Math.ceil((fu * Math.pow(2, 2 + points)) * multiplier /100) * 100;
basicPoints = basicPoints < manganPayout ? basicPoints : manganPayout;
}
} else {
switch (points) {
case 5: basicPoints = manganPayout; break;
case 6:
case 7: basicPoints = manganPayout * 1.5; break;
case 8:
case 9:
case 10: basicPoints = manganPayout * 2; break;
case 11:
case 12: basicPoints = manganPayout * 3; break;
case 13: basicPoints = manganPayout * 4; break;
case 26: basicPoints = manganPayout * 4 * 2; break;
case 39: basicPoints = manganPayout * 4 * 3; break;
case 52: basicPoints = manganPayout * 4 * 4; break;
case 65: basicPoints = manganPayout * 4 * 5; break;
}
}

winds[winnerWind] = basicPoints + 300 * Number(Session.get("current_bonus")) + riichiSticks * 1000;
winds[loserWind] = -basicPoints - 300 * Number(Session.get("current_bonus"));
if (fu == 20 || (points == 1 && fu == 25)) {
return 0; // Issue Protection
} else {
basicPoints = Math.ceil((fu * Math.pow(2, 2 + points)) * multiplier /100) * 100;
basicPoints = basicPoints < manganPayout ? basicPoints : manganPayout;
}
} else {
switch (points) {
case 5: basicPoints = manganPayout; break;
case 6:
case 7: basicPoints = manganPayout * 1.5; break;
case 8:
case 9:
case 10: basicPoints = manganPayout * 2; break;
case 11:
case 12: basicPoints = manganPayout * 3; break;
case 13: basicPoints = manganPayout * 4; break;
case 26: basicPoints = manganPayout * 4 * 2; break;
case 39: basicPoints = manganPayout * 4 * 3; break;
case 52: basicPoints = manganPayout * 4 * 4; break;
case 65: basicPoints = manganPayout * 4 * 5; break;
}
}

winds[winnerWind] = basicPoints + 300 * Number(Session.get("current_bonus")) + riichiSticks * 1000;
winds[loserWind] = -basicPoints - 300 * Number(Session.get("current_bonus"));

Session.set("free_riichi_sticks", 0);
return winds;
};

function selfdraw_delta(points, fu, winnerWind, riichiSticks) {
let winds = {};
winds[Constants.EAST] = winds[Constants.SOUTH] = winds[Constants.WEST] = winds[Constants.NORTH] = 0;
let winds = {};
winds[Constants.EAST] = winds[Constants.SOUTH] = winds[Constants.WEST] = winds[Constants.NORTH] = 0;

let basicPoints;
let basicPoints;
let dealerWind = NewGameUtils.roundToDealerDirection(Number(Session.get("current_round")));

if (points < 5) {
if (points == 1 && (fu == 20 || fu == 25)) {
return 0; // Issue Protection
} else {
basicPoints = fu * Math.pow(2, 2 + points);
basicPoints = basicPoints < Constants.MANGAN ? basicPoints : Constants.MANGAN;
}
} else {
switch (points) {
case 5: basicPoints = Constants.MANGAN; break;
case 6:
case 7: basicPoints = Constants.MANGAN * 1.5; break;
case 8:
case 9:
case 10: basicPoints = Constants.MANGAN * 2; break;
case 11:
case 12: basicPoints = Constants.MANGAN * 3; break;
case 13: basicPoints = Constants.MANGAN * 4; break;
case 26: basicPoints = Constants.MANGAN * 4 * 2; break;
case 39: basicPoints = Constants.MANGAN * 4 * 3; break;
case 52: basicPoints = Constants.MANGAN * 4 * 4; break;
case 65: basicPoints = Constants.MANGAN * 4 * 5; break;
};
}

let nonDealerPays = Math.ceil(basicPoints/100) * 100;
let dealerPays = Math.ceil(basicPoints/100 * 2) * 100;

let bonuses = Number(Session.get("current_bonus"));

for (let w in winds) {
if (winnerWind != dealerWind) {
if (w == dealerWind) {
winds[w] = -dealerPays - 100 * bonuses;
} else if (w == winnerWind) {
winds[w] = dealerPays + 2 * nonDealerPays + 300 * bonuses + riichiSticks * 1000;
} else {
winds[w] = -nonDealerPays - 100 * bonuses;
}
} else {
if (w == winnerWind) {
winds[w] = 3 * nonDealerPays + riichiSticks * 1000;
} else {
winds[w] = -nonDealerPays;
}
}
}
if (points < 5) {
if (points == 1 && (fu == 20 || fu == 25)) {
return 0; // Issue Protection
} else {
basicPoints = fu * Math.pow(2, 2 + points);
basicPoints = basicPoints < Constants.MANGAN_BASIC_POINTS ? basicPoints : Constants.MANGAN_BASIC_POINTS;
}
} else {
switch (points) {
case 5: basicPoints = Constants.MANGAN_BASIC_POINTS; break;
case 6:
case 7: basicPoints = Constants.MANGAN_BASIC_POINTS * 1.5; break;
case 8:
case 9:
case 10: basicPoints = Constants.MANGAN_BASIC_POINTS * 2; break;
case 11:
case 12: basicPoints = Constants.MANGAN_BASIC_POINTS * 3; break;
case 13: basicPoints = Constants.MANGAN_BASIC_POINTS * 4; break;
case 26: basicPoints = Constants.MANGAN_BASIC_POINTS * 4 * 2; break;
case 39: basicPoints = Constants.MANGAN_BASIC_POINTS * 4 * 3; break;
case 52: basicPoints = Constants.MANGAN_BASIC_POINTS * 4 * 4; break;
case 65: basicPoints = Constants.MANGAN_BASIC_POINTS * 4 * 5; break;
};
}

let nonDealerPays = Math.ceil(basicPoints/100) * 100;
let dealerPays = Math.ceil(basicPoints/100 * 2) * 100;

let bonuses = Number(Session.get("current_bonus"));

for (let w in winds) {
if (winnerWind != dealerWind) {
if (w == dealerWind) {
winds[w] = -dealerPays - 100 * bonuses;
} else if (w == winnerWind) {
winds[w] = dealerPays + 2 * nonDealerPays + 300 * bonuses + riichiSticks * 1000;
} else {
winds[w] = -nonDealerPays - 100 * bonuses;
}
} else {
if (w == winnerWind) {
winds[w] = 3 * nonDealerPays + riichiSticks * 1000;
} else {
winds[w] = -nonDealerPays;
}
}
}

Session.set("free_riichi_sticks", 0);
return winds;
};

function fuckup_delta(loser) {
let winds = {};
winds[Constants.EAST] = winds[Constants.SOUTH] = winds[Constants.WEST] = winds[Constants.NORTH] = 4000;
let winds = {};
winds[Constants.EAST] = winds[Constants.SOUTH] = winds[Constants.WEST] = winds[Constants.NORTH] = 4000;

winds[loser] = -12000;
winds[loser] = -12000;

return winds;
return winds;
};
Loading

0 comments on commit 22eb957

Please sign in to comment.