Skip to content

Commit 2ad3615

Browse files
committed
Add dummy mechanism
1 parent b91f10c commit 2ad3615

23 files changed

+3662
-1715
lines changed

gameServer/dist/index.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use strict";
2+
3+
var _server = require("boardgame.io/server");
4+
5+
var _bridge = require("./lib/bridge.js");
6+
7+
var _cors = _interopRequireDefault(require("@koa/cors"));
8+
9+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10+
11+
//for now in memory
12+
const board = (0, _bridge.BridgeDealFactory)();
13+
const server = (0, _server.Server)({
14+
games: [board] // db: new FlatFile({
15+
// dir: '/storage',
16+
// logging: true
17+
// }),
18+
19+
});
20+
server.app.use((0, _cors.default)({
21+
origin: true
22+
}));
23+
server.run(process.env.PORT);

gameServer/dist/lib/IMP.js

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/* Copyright 2020 Daniel Bohm & Patrik Perger and the Bridge Hackathon Contributors
2+
*
3+
* Use of this source code is governed by an MIT-style
4+
* license that can be found in the LICENSE file or at
5+
* https://opensource.org/licenses/MIT
6+
*/
7+
// export default function IMPs(score1, score2) {
8+
// const diff = Math.abs(score1 - score2); //score 1 is the teams score on table 1, score 2 the same teams score on table 2.
9+
// var points;
10+
// if (diff < 20) {
11+
// return points = [0, 0]; //first number is IMP of the team whose score we entered, score 2 is the other teams IMP=
12+
// }
13+
// else if (diff >= 170 && diff <= 210) {
14+
// points= [5, 0];
15+
// }
16+
// else if (diff >= 220 && diff <= 260) {
17+
// points= [6, 0];
18+
// }
19+
// else if (diff >= 270 && diff <= 310) {
20+
// points= [7, 0];
21+
// }
22+
// else if (diff >= 320 && diff <= 360) {
23+
// points= [8, 0];
24+
// }
25+
// else if (diff >= 370 && diff <= 420) {
26+
// points= [9, 0];
27+
// }
28+
// else if (diff >= 430 && diff <= 490) {
29+
// points= [10, 0];
30+
// }
31+
// else if (diff >= 500 && diff <= 590) {
32+
// points= [11, 0];
33+
// }
34+
// else if (diff >= 600 && diff <= 740) {
35+
// points= [12, 0];
36+
// }
37+
// else if (diff >= 750 && diff <= 890) {
38+
// points= [13, 0];
39+
// }
40+
// else if (diff >= 900 && diff <= 1090) {
41+
// points= [14, 0];
42+
// }
43+
// else if (diff >= 1100 && diff <= 1290) {
44+
// points= [15, 0];
45+
// }
46+
// else if (diff >= 1300 && diff <= 1490) {
47+
// points= [16, 0];
48+
// }
49+
// else if (diff >= 1500 && diff <= 1740) {
50+
// points= [17, 0];
51+
// }
52+
// else if (diff >= 1750 && diff <= 1990) {
53+
// points= [18, 0];
54+
// }
55+
// else if (diff >= 2000 && diff <= 2240) {
56+
// points= [19, 0];
57+
// }
58+
// else if (diff >= 2250 && diff <= 2490) {
59+
// points= [20, 0];
60+
// }
61+
// else if (diff >= 2500 && diff <= 2990) {
62+
// points= [21, 0];
63+
// }
64+
// else if (diff >= 3000 && diff <= 3490) {
65+
// points= [22, 0];
66+
// }
67+
// else if (diff >= 3500 && diff <= 3990) {
68+
// points= [23, 0];
69+
// }
70+
// else{
71+
// points= [24, 0]
72+
// }
73+
// if(score2>score1){
74+
// points=points.reverse();
75+
// }
76+
// return points;
77+
// }
78+
"use strict";

gameServer/dist/lib/SpecialBids.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.SPECIAL_BIDS = void 0;
7+
const SPECIAL_BIDS = {
8+
DOUBLE: "DOUBLE",
9+
REDOUBLE: "REDOUBLE",
10+
PASS: "PASS"
11+
};
12+
exports.SPECIAL_BIDS = SPECIAL_BIDS;

gameServer/dist/lib/Suits.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.SUIT_SYMBOLS = exports.EXTENDED_SUITS = exports.SUITS = void 0;
7+
const SUITS = {
8+
CLUBS: 0,
9+
DIAMONDS: 1,
10+
HEARTS: 2,
11+
SPADES: 3
12+
};
13+
exports.SUITS = SUITS;
14+
const EXTENDED_SUITS = Object.assign({
15+
NT: 4
16+
}, SUITS);
17+
exports.EXTENDED_SUITS = EXTENDED_SUITS;
18+
const SUIT_SYMBOLS = {
19+
0: "♣",
20+
1: "♦",
21+
2: "♥",
22+
3: "♠",
23+
4: "NT"
24+
};
25+
exports.SUIT_SYMBOLS = SUIT_SYMBOLS;

gameServer/dist/lib/VP.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// /* Copyright 2020 Daniel Bohm & Patrik Perger and the Bridge Hackathon Contributors
2+
// *
3+
// * Use of this source code is governed by an MIT-style
4+
// * license that can be found in the LICENSE file or at
5+
// * https://opensource.org/licenses/MIT
6+
// */
7+
// export default function vp(M, no_boards) { //M=margin, no_boards= number of boards
8+
// const B = 15 * (Math.pow(no_boards, 0.5));
9+
// const Tau = (Math.pow(5, 0.5) - 1) / 2;
10+
// VPW = 10 + 10 * ((1 - Math.pow(Tau, (3 * M / B))) / (1 - Math.pow(Tau, 3))); //source: https://www.bridgebase.com/forums/topic/55389-wbf-vp-scale-changes/page__p__667202#entry667202
11+
// if (VPW > 20) {
12+
// VPW = 20;
13+
// }
14+
// VPL = 20 - VPW;
15+
// return[VPW.toFixed(2),VPL.toFixed(2)] //VPW=VP of winner, VPL= VP of loser
16+
// }
17+
"use strict";

gameServer/dist/lib/Vulnerability.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.VULNERABILITY = void 0;
7+
const VULNERABILITY = {
8+
NS: "NS",
9+
EW: "EW",
10+
BOTH: "BOTH",
11+
NONE: "NONE"
12+
};
13+
exports.VULNERABILITY = VULNERABILITY;

gameServer/dist/lib/bidding.js

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.getAllowedBids = exports.getLastNoSpecialBid = exports.getLastNotPassBid = void 0;
7+
8+
var _Suits = require("./Suits.js");
9+
10+
var _SpecialBids = require("./SpecialBids.js");
11+
12+
require("lodash.product");
13+
14+
var _lodash2 = _interopRequireDefault(require("lodash"));
15+
16+
var _positions = require("./positions.js");
17+
18+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19+
20+
//TODO refactor this naive implementation
21+
const allBids = _lodash2.default.chain(_lodash2.default.product(_lodash2.default.range(1, 8), _lodash2.default.values(_Suits.EXTENDED_SUITS))).map(e => {
22+
const iface = {
23+
isHigerThan: function (bid = {
24+
level: 0,
25+
suit: 0
26+
}) {
27+
return bid.level < this.level || bid.level === this.level && bid.suit < this.suit;
28+
}
29+
};
30+
return Object.assign(Object.create(iface), {
31+
level: e[0],
32+
suit: e[1]
33+
});
34+
}).concat(_lodash2.default.map(_lodash2.default.values(_SpecialBids.SPECIAL_BIDS), bid => {
35+
return {
36+
bid
37+
};
38+
})).value();
39+
40+
const isSpecial = bid => {
41+
return _lodash2.default.values(_SpecialBids.SPECIAL_BIDS).indexOf(bid.bid) > -1;
42+
};
43+
44+
const getLastNotPassBid = bidding => {
45+
return _lodash2.default.findLast(bidding, bid => {
46+
return bid.bid !== _SpecialBids.SPECIAL_BIDS.PASS;
47+
});
48+
};
49+
50+
exports.getLastNotPassBid = getLastNotPassBid;
51+
52+
const getLastNoSpecialBid = bidding => {
53+
return _lodash2.default.findLast(bidding, bid => {
54+
return !isSpecial(bid);
55+
});
56+
};
57+
58+
exports.getLastNoSpecialBid = getLastNoSpecialBid;
59+
60+
const isAllowed = ({
61+
bid,
62+
bidding,
63+
position
64+
}) => {
65+
const lastNotPassBid = getLastNotPassBid(bidding);
66+
const lastNoSpecialBid = getLastNoSpecialBid(bidding);
67+
68+
if (lastNotPassBid) {
69+
//Redouble allowed is previous bid was opponent
70+
if (bid.bid === _SpecialBids.SPECIAL_BIDS.REDOUBLE) {
71+
return lastNotPassBid.bid === _SpecialBids.SPECIAL_BIDS.DOUBLE && !(0, _positions.arePartners)(lastNotPassBid.position, position);
72+
} //Double only if last bid is not special and made by opponent
73+
74+
75+
if (bid.bid === _SpecialBids.SPECIAL_BIDS.DOUBLE) {
76+
return !isSpecial(lastNotPassBid) && !(0, _positions.arePartners)(lastNotPassBid.position, position);
77+
}
78+
79+
if (!isSpecial(bid)) {
80+
return bid.isHigerThan(lastNoSpecialBid);
81+
}
82+
} else {
83+
if (isSpecial(bid)) {
84+
return bid.bid === _SpecialBids.SPECIAL_BIDS.PASS;
85+
}
86+
}
87+
88+
return true;
89+
};
90+
91+
const getAllowedBids = ({
92+
bidding,
93+
position
94+
}) => {
95+
const lastBid = getLastNotPassBid(bidding);
96+
return _lodash2.default.chain(allBids).filter(bid => {
97+
return isAllowed({
98+
bid,
99+
bidding,
100+
position
101+
});
102+
}).groupBy(element => {
103+
return element.level || "special";
104+
}).value();
105+
};
106+
107+
exports.getAllowedBids = getAllowedBids;

gameServer/dist/lib/bridge.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.BridgeDealFactory = void 0;
7+
8+
var _deal = require("./deal.js");
9+
10+
var _moves = require("./moves");
11+
12+
var _lodash = require("lodash");
13+
14+
var _SpecialBids = require("./SpecialBids.js");
15+
16+
var _phases = require("./phases.js");
17+
18+
var _Vulnerability = require("./Vulnerability.js");
19+
20+
var _positions = require("./positions.js");
21+
22+
const getRandomVulnerabilty = () => {
23+
return _lodash._.values(_Vulnerability.VULNERABILITY)[Math.floor(Math.random() * 4)];
24+
};
25+
26+
const getRandomDealer = () => {
27+
return _lodash._.values(_positions.POSITIONS)[Math.floor(Math.random() * 4)];
28+
};
29+
30+
const BridgeDealFactory = () => {
31+
return {
32+
name: "bridgeDeal",
33+
turn: {
34+
moveLimit: 1
35+
},
36+
setup: () => ({
37+
hands: (0, _deal.deal)(),
38+
dealer: getRandomDealer(),
39+
vulnerability: getRandomVulnerabilty(),
40+
bidding: [],
41+
tricks: [{
42+
cards: []
43+
}],
44+
contract: {}
45+
}),
46+
phases: _phases.phases
47+
};
48+
};
49+
50+
exports.BridgeDealFactory = BridgeDealFactory;

gameServer/dist/lib/deal.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"use strict";
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.deal = void 0;
7+
8+
require("lodash.product");
9+
10+
var _lodash2 = _interopRequireDefault(require("lodash"));
11+
12+
var _deck = require("./deck.js");
13+
14+
var _positions = require("./positions.js");
15+
16+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17+
18+
const deal = () => {
19+
return _lodash2.default.zipObject(_lodash2.default.keys(_positions.POSITIONS), _lodash2.default.chain((0, _deck.deck)()).shuffle().chunk(13).map(hand => {
20+
return _lodash2.default.sortBy(hand, ({
21+
suit,
22+
value
23+
}) => {
24+
return -1 * (1000 * suit + value);
25+
});
26+
}).value());
27+
};
28+
29+
exports.deal = deal;

0 commit comments

Comments
 (0)