From 6b9aadc2658febb64f0051c7452f59b7d70f814c Mon Sep 17 00:00:00 2001 From: Nishchay Bhatt Date: Sun, 26 May 2024 18:25:10 +0530 Subject: [PATCH 1/2] fixes: issue #9 --- backend/src/constants/index.ts | 14 ++++ backend/src/constants/padding.ts | 9 +++ backend/src/index.ts | 74 ++++++++++++++----- backend/src/outcomes.ts | 21 +++++- backend/src/types/types.d.ts | 5 ++ backend/src/utils/game.ts | 18 +++++ backend/tsconfig.json | 117 +++---------------------------- 7 files changed, 134 insertions(+), 124 deletions(-) create mode 100644 backend/src/constants/index.ts create mode 100644 backend/src/constants/padding.ts create mode 100644 backend/src/types/types.d.ts create mode 100644 backend/src/utils/game.ts diff --git a/backend/src/constants/index.ts b/backend/src/constants/index.ts new file mode 100644 index 0000000..a14c0ed --- /dev/null +++ b/backend/src/constants/index.ts @@ -0,0 +1,14 @@ +import { pad } from "./padding.ts"; + + +export const WIDTH = 800; +export const HEIGHT = 800; +export const ballRadius = 7; +export const obstacleRadius = 4; + +export const gravity = pad(0.6); +export const horizontalFriction = 0.4; +export const verticalFriction = 0.8; + +export const sinkWidth = 36; +export const NUM_SINKS = 17; \ No newline at end of file diff --git a/backend/src/constants/padding.ts b/backend/src/constants/padding.ts new file mode 100644 index 0000000..9fb151a --- /dev/null +++ b/backend/src/constants/padding.ts @@ -0,0 +1,9 @@ +export const DECIMAL_MULTIPLIER = 10000; + +export function pad(n: number) { + return n * DECIMAL_MULTIPLIER; +} + +export function unpad(n: number) { + return Math.floor(n / DECIMAL_MULTIPLIER); +} diff --git a/backend/src/index.ts b/backend/src/index.ts index a1206d8..9b60780 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -2,15 +2,18 @@ import express from "express"; import { outcomes } from "./outcomes"; import cors from "cors"; +import { getObstacles } from "./utils/game"; +import { pad, unpad } from "./constants/padding"; +import { WIDTH, ballRadius, horizontalFriction, verticalFriction } from "./constants"; const app = express(); app.use(cors()) const TOTAL_DROPS = 16; -const MULTIPLIERS: {[ key: number ]: number} = { - 0: 16, - 1: 9, +const MULTIPLIERS: { [key: number]: number } = { + 0: 5, + 1: 3, 2: 2, 3: 1.4, 4: 1.4, @@ -24,30 +27,67 @@ const MULTIPLIERS: {[ key: number ]: number} = { 12: 1.4, 13: 1.4, 14: 2, - 15: 9, - 16: 16 + 15: 3, + 16: 5 } +app.post("/stake", (req, res) => { +}) app.post("/game", (req, res) => { let outcome = 0; - const pattern = [] - for (let i = 0; i < TOTAL_DROPS; i++) { - if (Math.random() > 0.5) { - pattern.push("R") - outcome++; - } else { - pattern.push("L") - } - } + const pattern: Array<'L' | 'R'> = [] + const obstacles = getObstacles() + + let possiblieOutcomes = outcomes[outcome]; + const startX = possiblieOutcomes[Math.floor(Math.random() * possiblieOutcomes.length)] || pad(WIDTH / 2 + 13) + const startY = pad(50) + let x = startX + let y = startY + let vx = 0 + let vy = 0 + // Collision with obstacles + obstacles.forEach(obstacle => { + const dist = Math.hypot(x - obstacle.x, y - obstacle.y); + if (dist < pad(ballRadius + obstacle.radius)) { + // Calculate collision angle + const angle = Math.atan2(y - obstacle.y, x - obstacle.x); + // Reflect velocity + const speed = Math.sqrt(vx * vx + vy * vy); + vx = (Math.cos(angle) * speed * horizontalFriction); + vy = Math.sin(angle) * speed * verticalFriction; + // Adjust position to prevent sticking + const overlap = ballRadius + obstacle.radius - unpad(dist); + x += pad(Math.cos(angle) * overlap); + y += pad(Math.sin(angle) * overlap); + if (pad(Math.cos(angle) * overlap) > 0) { + pattern.push('R'); + outcome++ + } else { + pattern.push('L') + outcome--; + } + } + }); + console.log("Outcomes : ", outcome) const multiplier = MULTIPLIERS[outcome]; - const possiblieOutcomes = outcomes[outcome]; + + res.send({ - point: possiblieOutcomes[Math.floor(Math.random() * possiblieOutcomes.length || 0)], + point: startX, multiplier, pattern }); }); -app.listen(3000) \ No newline at end of file +app.listen(3000) + +// for (let i = 0; i < TOTAL_DROPS; i++) { +// if (Math.random() > 0.5) { +// pattern.push("R") +// outcome++; +// } else { +// pattern.push("L") +// } +// } \ No newline at end of file diff --git a/backend/src/outcomes.ts b/backend/src/outcomes.ts index f60a237..b2464f9 100644 --- a/backend/src/outcomes.ts +++ b/backend/src/outcomes.ts @@ -1 +1,20 @@ -export const outcomes: {[key: string]: number[]} = { "0": [], "1": [ 3964963.452981615, 3910113.3998412564 ], "2": [ 3980805.7004139693, 3945617.6504109767, 4027628.395823398, 3902115.8620758583, 3938709.5467746584 ], "3": [ 3975554.824601942, 3965805.769610554, 3909279.443666201, 3940971.550465178, 3909606.717374134, 3915484.1741136736, 3977018.430328505, 3979167.5933461944, 3995981.0273005674, 3974177.78840204 ], "4": [ 3943174.7607756723, 3992961.0886867167, 3914511.2798374896, 3950487.300703086, 3973378.3900412438, 4012888.985549594, 4040961.8767680754, 4066503.3857407006, 3944573.7194061875, 3979876.769324002, 4042712.772834604, 4032991.0303322095, 4046340.7919081766, 3912597.9665436875, 4068852.495940549, 4064879.257329362, 3996796.04239161, 4045062.2783860737, 3964680.919169739 ], "5": [ 3953045.1447091424, 3947374.62976226, 3924082.6101653073, 3919085.269354398, 3902650.4008744615, 3934968.1593932374, 4044126.7590222214, 3928499.8807134246, 3913801.9247018984, 3909595.4432100505, 4082827.827013994, 3979739.108665962, 4077651.317785833, 4008030.8883127486, 3950951.6007580766, 3992039.9053288833, 4021810.0928285993, 4052650.560434505, 3994806.267259329, 3959327.3735489477, 3940455.7641962855, 3998822.2807239015, 3998803.9335444313, 4068193.3913483596, 3938798.911585438 ], "6": [ 4065643.7049927213, 3936841.961313155, 3948472.8991447487, 4004510.5975928125, 3933695.6888747592, 4011296.1958215656, 4093232.84383817, 3945658.6170622837, 4063199.5117669366, 4037864.799653558, 3931477.3517858014, 4091381.513010509, 4000895.053297006, 4042867.6535872207, 4090947.938511616, 3989468.333758437, 3943335.764879169, 3947278.536321405, 4022304.817103859, 3902177.8466275427, 3925270.959381573, 3955253.4540312397, 3986641.0060988157, 3927696.2396482667, 4064571.150949869, 3991167.946685552, 3973041.308793569, 3987377.180906899, 3917262.667253392, 4002606.795366179, 4033596.992526079, 3901372.366183016, 4015207.583244224, 3955421.290959922, 3952223.0425123484, 3941774.4498685915, 3977289.3718391117, 4024943.3014183883, 4024885.5052148327, 4016596.7449097126, 3910164.1864616796, 4023400.498352244, 3981421.8628830933, 3913377.3496230906, 4045958.9425667236, 4071139.892029292, 4019862.922309672, 4027992.2300945413, 4030455.1701347437, 4060673.10227606, 3996564.062673036, 4009801.4052053, 4007734.404953163, 4046612.754675019, 3944956.9979153597, 3977382.889196781, 3906636.5132748624, 4080470.0674178666, 3996210.4877184015, 3956216.294023866, 3940040.183231992 ], "7": [ 3926739.9104774813, 4091374.44234272, 4061919.9903071183, 3976066.7555194413, 3948801.1936986246, 4043233.7830772344, 4010011.7658794387, 3936431.4108806592, 3942776.8649452417, 3909995.011479453, 4012272.43979473, 3989907.069429411, 3996182.4336681785, 4078644.79693604, 4081624.0834239917, 4025044.731614778, 4033602.5381773794, 3913189.826642105, 3910500.674962151, 4055296.6588616692, 4005574.8641647273, 4079800.3518520766, 4092763.5236495608, 3952185.4910905147, 3945510.495018459, 3920891.8818843197, 3997101.789672143, 3991974.822516503, 3949265.4371072412, 3933412.4749754136, 3933181.8312838264, 4063875.6616431624, 3998206.7252218956, 3959006.1987530286, 3924067.917601976, 3902914.4459602935, 3905347.098696195, 4000831.565288375, 3944915.3251241, 3930343.481158048, 4025858.616981573, 4026496.026592473, 3948116.019901921, 4067143.737297127, 3995156.000931595, 3905006.3301882823, 4035783.4852589793, 3956461.6106608217, 4032886.6912715673, 3913146.10237042, 3930772.085213345, 3984887.619042549, 4053031.0321973227, 3913395.137097174, 3993579.678508536, 3932427.236196532, 3984279.0886106077 ], "8": [ 4099062.75134143, 4085894.4181278455, 3991123.0115790954, 3973053.5827605873, 3968190.564301313, 3925604.5066868863, 3933898.7590061547, 4089919.7991958153, 4076997.5225973814, 3957630.60529322, 3948999.35996541, 3963938.9455971997, 4044805.7991237757, 3905133.2109927135, 4074463.6876271376, 3939301.0655442886, 4040571.320635691, 4020510.19979044, 3959835.4618981928, 4037241.67248416, 4043105.87901907, 3912654.2409310103, 3929773.262095125, 3950802.527033251, 4068582.4605300324, 3946792.6177569656, 4078475.9982660934, 3972024.763383927, 3947150.677862883, 3963410.9779685168, 3999134.851845996, 3909374.1117644133, 3942761.896008833, 4071253.4107468165, 4050534.50171971, 3988521.4618817912, 3929940.089627246, 4029305.1056314665, 4087943.221841722, 3910909.3079385986, 4046944.0552393594, 4006944.159180551, 4014707.657017377, 3925473.574267122, 4012158.905329344, 4042197.149473071, 3998434.6078570196, 4047267.2747256896, 3964753.3725316986, 3955821.0222197613, 3973475.662585886, 3917189.0280630635, 4027132.7848505056, 3905368.7668914935, 3936654.62186107, 4092566.3229272505, 4026541.0685970024, 4038770.6420815475, 4067262.4257867294, 4050430.5327158393, 3980149.8069138955, 4052184.5678737606, 3942299.598280835, 4079754.687607573, 4021112.5651541506, 3961023.3381184433, 3937025.1424917267, 3964607.486702018, 4001319.0133674755, 3941648.5232227165, 4030587.9685114417, 4044067.1579758436, 4058158.522928313 ], "9": [ 3911530.315770063, 4024711.492410591, 3967652.4297853387, 4098886.3793751886, 4026117.0283389515, 4045045.4095477182, 4034571.220507859, 4088809.303306565, 3900806.968890352, 3913166.9251142726, 4059594.3600833854, 3945137.694311404, 3902668.8160601873, 4054646.2889849013, 4053898.6542759663, 3959251.11275926, 3963475.882565954, 3967968.9310842347, 4075078.929914972, 4035117.4533019722, 4047608.2592268144, 3913024.5010530455, 4081362.0390194473, 4098538.7144543654, 4049336.7774994993, 4056844.5727342237, 3917845.6810319433, 4098332.1779752634, 3979547.7686487637, 4026747.155594485, 3944692.803167993, 3960649.105237204, 4081040.2295870385, 4005698.9658651184, 4074183.694152899, 3976184.3586868607, 4007157.5084493076, 3918927.3398626954, 3918166.0285542854, 3953868.3374998523, 3963648.6249533077, 4065036.1837552087, 3964230.698479104, 3992799.530672317, 3931113.922813188, 4082916.6661583954, 3919236.111874976, 4012743.1541231154, 3900406.2441578982, 4031396.764516756, 4088712.2834741194, 3921570.4946371615, 4077416.64169384, 3962807.6000533635 ], "10": [ 4069582.648305392, 3966300.3577461895, 4047184.7847023425, 3962656.256238744, 3934682.0223851865, 4089620.291559703, 3996605.065672608, 3921656.567101851, 3950930.30704122, 4052733.606190915, 4046762.051641918, 3912718.72211605, 3942094.6698735086, 4017504.735499972, 4016206.1612997893, 4060896.040328729, 4077224.686824909, 3988932.185505723, 4016550.502499315, 3959104.134236025, 3903531.023685199, 3939907.5585800377, 3969464.753065079, 4036549.7059165714, 3938844.715578784, 3985594.4268763512, 4011615.276676018, 3949739.058361909, 4064041.8926257566, 4004767.498301687, 3996411.8026064364, 4035064.3182208547, 3988008.7378418343, 4015638.96642283, 3967068.722994021, 4082965.2856357233, 3951302.134707721, 3948101.1830631103, 3978745.8509503608, 4068638.265329366, 4018433.726155858, 4032765.523475676 ], "11": [ 4055462.593704495, 4027576.362231998, 4011290.7395424685, 4034848.6574270525, 4064298.598636101, 3997022.919190929, 4053625.932623065, 4064234.3514714935, 4075348.9710445153, 4060118.5348266517, 4065992.932112665, 4063162.143518177, 4060798.1858924176, 3956764.654354398, 3912916.1668887464, 4018282.0763658765, 4065575.3280486814, 3967348.3916016137, 4034992.477051428, 4069123.2018048204, 3939281.4172981237, 4022103.802712647, 4083993.320300048, 4034478.871034405, 4068844.513451607, 4097187.535489012, 3981130.4047553614, 4068312.6406908804, 4050921.0879167155, 4048297.277514315, 3953878.475004285, 3998627.3710734197 ], "12": [ 4007152.5182738686, 4014664.8542149696, 4095619.5802802853, 4018084.7270321106, 4072050.3744347296, 4026256.723716898, 4095827.9573665825, 4023631.9896559394, 4046751.9125588783, 3973758.674124694, 4081927.075527175, 3922485.387310559, 4001549.2805312183, 4050417.849670596, 3987607.4531957353, 4060206.9664999805, 4080316.8473846694, 4030455.1532406537, 4087714.965906726, 4028165.0792610054, 4032588.5261474997, 3980546.468460318, 4090408.033691761, 3990019.103297975, 4088755.998466496, 4092162.22327816, 4029036.6583707742, 4055066.505591603, 4081998.821392285, 4079550.553314541 ], "13": [ 3905319.849889843, 4054719.0660902266, 4055596.4319745116, 3992648.989962779, 3924972.5941170114, 4095167.7814041013, 3912740.1944122575, 4024882.9438952096, 4023171.3988155797, 4059892.954049364, 4068510.96886605, 4093838.431690223, 4070524.1327491063 ], "14": [ 4092261.8249403643, 3956304.3865069468, 4069053.2302732924, 4038890.8473817194 ], "15": [ 4013891.110502415, 3977489.9532032954, 4044335.989753631, 4066199.8081775964 ], "16": [ 3979706.1687804307, 4024156.037977316 ], "17": [] } \ No newline at end of file +export const outcomes: { [key: string]: number[] } = { + "0": [], + "1": [3964963.452981615, 3910113.3998412564], + "2": [3980805.7004139693, 3945617.6504109767, 4027628.395823398, 3902115.8620758583, 3938709.5467746584], + "3": [3975554.824601942, 3965805.769610554, 3909279.443666201, 3940971.550465178, 3909606.717374134, 3915484.1741136736, 3977018.430328505, 3979167.5933461944, 3995981.0273005674, 3974177.78840204], + "4": [3943174.7607756723, 3992961.0886867167, 3914511.2798374896, 3950487.300703086, 3973378.3900412438, 4012888.985549594, 4040961.8767680754, 4066503.3857407006, 3944573.7194061875, 3979876.769324002, 4042712.772834604, 4032991.0303322095, 4046340.7919081766, 3912597.9665436875, 4068852.495940549, 4064879.257329362, 3996796.04239161, 4045062.2783860737, 3964680.919169739], + "5": [3953045.1447091424, 3947374.62976226, 3924082.6101653073, 3919085.269354398, 3902650.4008744615, 3934968.1593932374, 4044126.7590222214, 3928499.8807134246, 3913801.9247018984, 3909595.4432100505, 4082827.827013994, 3979739.108665962, 4077651.317785833, 4008030.8883127486, 3950951.6007580766, 3992039.9053288833, 4021810.0928285993, 4052650.560434505, 3994806.267259329, 3959327.3735489477, 3940455.7641962855, 3998822.2807239015, 3998803.9335444313, 4068193.3913483596, 3938798.911585438], + "6": [4065643.7049927213, 3936841.961313155, 3948472.8991447487, 4004510.5975928125, 3933695.6888747592, 4011296.1958215656, 4093232.84383817, 3945658.6170622837, 4063199.5117669366, 4037864.799653558, 3931477.3517858014, 4091381.513010509, 4000895.053297006, 4042867.6535872207, 4090947.938511616, 3989468.333758437, 3943335.764879169, 3947278.536321405, 4022304.817103859, 3902177.8466275427, 3925270.959381573, 3955253.4540312397, 3986641.0060988157, 3927696.2396482667, 4064571.150949869, 3991167.946685552, 3973041.308793569, 3987377.180906899, 3917262.667253392, 4002606.795366179, 4033596.992526079, 3901372.366183016, 4015207.583244224, 3955421.290959922, 3952223.0425123484, 3941774.4498685915, 3977289.3718391117, 4024943.3014183883, 4024885.5052148327, 4016596.7449097126, 3910164.1864616796, 4023400.498352244, 3981421.8628830933, 3913377.3496230906, 4045958.9425667236, 4071139.892029292, 4019862.922309672, 4027992.2300945413, 4030455.1701347437, 4060673.10227606, 3996564.062673036, 4009801.4052053, 4007734.404953163, 4046612.754675019, 3944956.9979153597, 3977382.889196781, 3906636.5132748624, 4080470.0674178666, 3996210.4877184015, 3956216.294023866, 3940040.183231992], + "7": [3926739.9104774813, 4091374.44234272, 4061919.9903071183, 3976066.7555194413, 3948801.1936986246, 4043233.7830772344, 4010011.7658794387, 3936431.4108806592, 3942776.8649452417, 3909995.011479453, 4012272.43979473, 3989907.069429411, 3996182.4336681785, 4078644.79693604, 4081624.0834239917, 4025044.731614778, 4033602.5381773794, 3913189.826642105, 3910500.674962151, 4055296.6588616692, 4005574.8641647273, 4079800.3518520766, 4092763.5236495608, 3952185.4910905147, 3945510.495018459, 3920891.8818843197, 3997101.789672143, 3991974.822516503, 3949265.4371072412, 3933412.4749754136, 3933181.8312838264, 4063875.6616431624, 3998206.7252218956, 3959006.1987530286, 3924067.917601976, 3902914.4459602935, 3905347.098696195, 4000831.565288375, 3944915.3251241, 3930343.481158048, 4025858.616981573, 4026496.026592473, 3948116.019901921, 4067143.737297127, 3995156.000931595, 3905006.3301882823, 4035783.4852589793, 3956461.6106608217, 4032886.6912715673, 3913146.10237042, 3930772.085213345, 3984887.619042549, 4053031.0321973227, 3913395.137097174, 3993579.678508536, 3932427.236196532, 3984279.0886106077], + "8": [4099062.75134143, 4085894.4181278455, 3991123.0115790954, 3973053.5827605873, 3968190.564301313, 3925604.5066868863, 3933898.7590061547, 4089919.7991958153, 4076997.5225973814, 3957630.60529322, 3948999.35996541, 3963938.9455971997, 4044805.7991237757, 3905133.2109927135, 4074463.6876271376, 3939301.0655442886, 4040571.320635691, 4020510.19979044, 3959835.4618981928, 4037241.67248416, 4043105.87901907, 3912654.2409310103, 3929773.262095125, 3950802.527033251, 4068582.4605300324, 3946792.6177569656, 4078475.9982660934, 3972024.763383927, 3947150.677862883, 3963410.9779685168, 3999134.851845996, 3909374.1117644133, 3942761.896008833, 4071253.4107468165, 4050534.50171971, 3988521.4618817912, 3929940.089627246, 4029305.1056314665, 4087943.221841722, 3910909.3079385986, 4046944.0552393594, 4006944.159180551, 4014707.657017377, 3925473.574267122, 4012158.905329344, 4042197.149473071, 3998434.6078570196, 4047267.2747256896, 3964753.3725316986, 3955821.0222197613, 3973475.662585886, 3917189.0280630635, 4027132.7848505056, 3905368.7668914935, 3936654.62186107, 4092566.3229272505, 4026541.0685970024, 4038770.6420815475, 4067262.4257867294, 4050430.5327158393, 3980149.8069138955, 4052184.5678737606, 3942299.598280835, 4079754.687607573, 4021112.5651541506, 3961023.3381184433, 3937025.1424917267, 3964607.486702018, 4001319.0133674755, 3941648.5232227165, 4030587.9685114417, 4044067.1579758436, 4058158.522928313], + "9": [3911530.315770063, 4024711.492410591, 3967652.4297853387, 4098886.3793751886, 4026117.0283389515, 4045045.4095477182, 4034571.220507859, 4088809.303306565, 3900806.968890352, 3913166.9251142726, 4059594.3600833854, 3945137.694311404, 3902668.8160601873, 4054646.2889849013, 4053898.6542759663, 3959251.11275926, 3963475.882565954, 3967968.9310842347, 4075078.929914972, 4035117.4533019722, 4047608.2592268144, 3913024.5010530455, 4081362.0390194473, 4098538.7144543654, 4049336.7774994993, 4056844.5727342237, 3917845.6810319433, 4098332.1779752634, 3979547.7686487637, 4026747.155594485, 3944692.803167993, 3960649.105237204, 4081040.2295870385, 4005698.9658651184, 4074183.694152899, 3976184.3586868607, 4007157.5084493076, 3918927.3398626954, 3918166.0285542854, 3953868.3374998523, 3963648.6249533077, 4065036.1837552087, 3964230.698479104, 3992799.530672317, 3931113.922813188, 4082916.6661583954, 3919236.111874976, 4012743.1541231154, 3900406.2441578982, 4031396.764516756, 4088712.2834741194, 3921570.4946371615, 4077416.64169384, 3962807.6000533635], + "10": [4069582.648305392, 3966300.3577461895, 4047184.7847023425, 3962656.256238744, 3934682.0223851865, 4089620.291559703, 3996605.065672608, 3921656.567101851, 3950930.30704122, 4052733.606190915, 4046762.051641918, 3912718.72211605, 3942094.6698735086, 4017504.735499972, 4016206.1612997893, 4060896.040328729, 4077224.686824909, 3988932.185505723, 4016550.502499315, 3959104.134236025, 3903531.023685199, 3939907.5585800377, 3969464.753065079, 4036549.7059165714, 3938844.715578784, 3985594.4268763512, 4011615.276676018, 3949739.058361909, 4064041.8926257566, 4004767.498301687, 3996411.8026064364, 4035064.3182208547, 3988008.7378418343, 4015638.96642283, 3967068.722994021, 4082965.2856357233, 3951302.134707721, 3948101.1830631103, 3978745.8509503608, 4068638.265329366, 4018433.726155858, 4032765.523475676], + "11": [4055462.593704495, 4027576.362231998, 4011290.7395424685, 4034848.6574270525, 4064298.598636101, 3997022.919190929, 4053625.932623065, 4064234.3514714935, 4075348.9710445153, 4060118.5348266517, 4065992.932112665, 4063162.143518177, 4060798.1858924176, 3956764.654354398, 3912916.1668887464, 4018282.0763658765, 4065575.3280486814, 3967348.3916016137, 4034992.477051428, 4069123.2018048204, 3939281.4172981237, 4022103.802712647, 4083993.320300048, 4034478.871034405, 4068844.513451607, 4097187.535489012, 3981130.4047553614, 4068312.6406908804, 4050921.0879167155, 4048297.277514315, 3953878.475004285, 3998627.3710734197], + "12": [4007152.5182738686, 4014664.8542149696, 4095619.5802802853, 4018084.7270321106, 4072050.3744347296, 4026256.723716898, 4095827.9573665825, 4023631.9896559394, 4046751.9125588783, 3973758.674124694, 4081927.075527175, 3922485.387310559, 4001549.2805312183, 4050417.849670596, 3987607.4531957353, 4060206.9664999805, 4080316.8473846694, 4030455.1532406537, 4087714.965906726, 4028165.0792610054, 4032588.5261474997, 3980546.468460318, 4090408.033691761, 3990019.103297975, 4088755.998466496, 4092162.22327816, 4029036.6583707742, 4055066.505591603, 4081998.821392285, 4079550.553314541], + "13": [3905319.849889843, 4054719.0660902266, 4055596.4319745116, 3992648.989962779, 3924972.5941170114, 4095167.7814041013, 3912740.1944122575, 4024882.9438952096, 4023171.3988155797, 4059892.954049364, 4068510.96886605, 4093838.431690223, 4070524.1327491063], + "14": [4092261.8249403643, 3956304.3865069468, 4069053.2302732924, 4038890.8473817194], + "15": [4013891.110502415, 3977489.9532032954, 4044335.989753631, 4066199.8081775964], + "16": [3979706.1687804307, 4024156.037977316], + "17": [] +} \ No newline at end of file diff --git a/backend/src/types/types.d.ts b/backend/src/types/types.d.ts new file mode 100644 index 0000000..fa29b42 --- /dev/null +++ b/backend/src/types/types.d.ts @@ -0,0 +1,5 @@ +export interface Obstacle { + x: number; + y: number; + radius: number; +} \ No newline at end of file diff --git a/backend/src/utils/game.ts b/backend/src/utils/game.ts new file mode 100644 index 0000000..d704aef --- /dev/null +++ b/backend/src/utils/game.ts @@ -0,0 +1,18 @@ +import { WIDTH, obstacleRadius } from "../constants"; +import { pad } from "../constants/padding"; +import { Obstacle } from "../types/types"; + +export const getObstacles = (): Obstacle[] => { + const obstacles: Obstacle[] = []; + const rows = 18; + for (let row = 2; row < rows; row++) { + const numObstacles = row + 1; + const y = 0 + row * 35; + const spacing = 36; + for (let col = 0; col < numObstacles; col++) { + const x = WIDTH / 2 - spacing * (row / 2 - col); + obstacles.push({ x: pad(x), y: pad(y), radius: obstacleRadius }); + } + } + return obstacles; +} \ No newline at end of file diff --git a/backend/tsconfig.json b/backend/tsconfig.json index a645c5b..f4caf5c 100644 --- a/backend/tsconfig.json +++ b/backend/tsconfig.json @@ -1,109 +1,14 @@ { "compilerOptions": { - /* Visit https://aka.ms/tsconfig to read more about this file */ - - /* Projects */ - // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ - // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ - // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ - // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ - // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ - // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ - - /* Language and Environment */ - "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ - // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ - // "jsx": "preserve", /* Specify what JSX code is generated. */ - // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ - // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ - // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ - // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ - // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ - // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ - // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ - // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ - // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ - - /* Modules */ - "module": "commonjs", /* Specify what module code is generated. */ - "rootDir": "./src", /* Specify the root folder within your source files. */ - // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ - // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ - // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ - // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ - // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ - // "types": [], /* Specify type package names to be included without being referenced in a source file. */ - // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ - // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ - // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ - // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ - // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ - // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ - // "resolveJsonModule": true, /* Enable importing .json files. */ - // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ - // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ - - /* JavaScript Support */ - // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ - // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ - // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ - - /* Emit */ - // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ - // "declarationMap": true, /* Create sourcemaps for d.ts files. */ - // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ - // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ - // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ - // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ - "outDir": "./dist", /* Specify an output folder for all emitted files. */ - // "removeComments": true, /* Disable emitting comments. */ - // "noEmit": true, /* Disable emitting files from a compilation. */ - // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ - // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ - // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ - // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ - // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ - // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ - // "newLine": "crlf", /* Set the newline character for emitting files. */ - // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ - // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ - // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ - // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ - // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ - // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ - - /* Interop Constraints */ - // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ - // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ - "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ - // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ - "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ - - /* Type Checking */ - "strict": true, /* Enable all strict type-checking options. */ - // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ - // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ - // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ - // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ - // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ - // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ - // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ - // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ - // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ - // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ - // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ - // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ - // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ - // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ - // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ - // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ - // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ - // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ - - /* Completeness */ - // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "target": "es2016", + "module": "commonjs", + "rootDir": "./src", + "outDir": "./dist", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true, + "noEmit": true, + "allowImportingTsExtensions": true, } -} +} \ No newline at end of file From 0fb8c47818936371b31ac10d7adbd82c4ad33803 Mon Sep 17 00:00:00 2001 From: Nishchay Bhatt Date: Sun, 26 May 2024 19:02:58 +0530 Subject: [PATCH 2/2] fixes: issue #9 --- backend/src/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/src/index.ts b/backend/src/index.ts index 9b60780..703f595 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -12,8 +12,8 @@ app.use(cors()) const TOTAL_DROPS = 16; const MULTIPLIERS: { [key: number]: number } = { - 0: 5, - 1: 3, + 0: 16, + 1: 9, 2: 2, 3: 1.4, 4: 1.4, @@ -27,8 +27,8 @@ const MULTIPLIERS: { [key: number]: number } = { 12: 1.4, 13: 1.4, 14: 2, - 15: 3, - 16: 5 + 15: 9, + 16: 16 } app.post("/stake", (req, res) => {