Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions dist/index.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/module.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/module.js.map

Large diffs are not rendered by default.

58 changes: 29 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,24 @@
"name": "anybody-problem",
"version": "1.0.0",
"license": "CC-BY-NC-4.0",
"targets": {
"module": {
"optimize": true,
"source": "src/index.js",
"isLibrary": true
},
"iframe": {
"source": "src/index.html",
"optimize": true
}
},
"source": "src/index.js",
"type": "module",
"main": "dist/module.js",
"module": "dist/module.js",
"iframe": "dist/index.html",
"source": "src/index.js",
"scripts": {
"prepare": "husky",
"build": "rm -rf .parcel-cache && rm -rf dist && yarn parcel build",
"dev": "rm -rf .parcel-cache && rm -rf dist && yarn parcel watch src/index.js",
"serve": "rm -rf .parcel-cache && yarn parcel src/index.html --open",
"chain": "hardhat node",
"circom": "./scripts/basic_circom.sh",
"circom:game-test": "yarn circom game_2_20 && yarn circom game_3_20 && yarn circom game_4_20 && yarn circom game_5_20 && yarn circom game_6_20",
"circom:game-prod": "yarn circom game_2_250 && yarn circom game_3_250 && yarn circom game_4_250 && yarn circom game_5_125 && yarn circom game_6_125",
"deploy": "hardhat run scripts/deploy.cjs",
"test:circom": "ls test/*.js | grep -v -e 'bodies' -e 'problems' -e 'solver' -e 'problemMetadata' -e 'bodyMetadata' | xargs npx hardhat test",
"test:solidity": "hardhat test test/problems.test.js test/problemMetadata.test.js test/bodyMetadata.test.js test/bodies.test.js test/solver.test.js",
"dev": "rm -rf .parcel-cache && rm -rf dist && yarn parcel watch src/index.js",
"precommit": "echo 'husky is working : )' && lint-staged && yarn build && git add dist",
"prepare": "husky",
"serve": "rm -rf .parcel-cache && yarn parcel src/index.html --open",
"test": "hardhat test",
"precommit": "echo 'husky is working : )' && lint-staged && yarn build && git add dist"
"test:circom": "ls test/*.js | grep -v -e 'bodies' -e 'problems' -e 'solver' -e 'problemMetadata' -e 'bodyMetadata' | xargs npx hardhat test",
"test:solidity": "hardhat test test/problems.test.js test/problemMetadata.test.js test/bodyMetadata.test.js test/bodies.test.js test/solver.test.js"
},
"lint-staged": {
"*.{js,jsx}": [
Expand All @@ -42,6 +31,12 @@
],
"**/*": "prettier --write --ignore-unknown"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead",
"not ie 11"
],
"eslintConfig": {
"env": {
"amd": true,
Expand Down Expand Up @@ -75,6 +70,9 @@
],
"root": true
},
"resolutions": {
"web-worker": "1.2.0"
},
"dependencies": {
"ethers": "^5.7.0",
"tone": "^15.0.4"
Expand Down Expand Up @@ -113,16 +111,18 @@
"solidity-coverage": "^0.8.6",
"xmldom": "^0.6.0"
},
"resolutions": {
"web-worker": "1.2.0"
},
"type": "module",
"browserslist": [
"> 1%",
"last 2 versions",
"not dead",
"not ie 11"
],
"iframe": "dist/index.html",
"readme": "ERROR: No README data found!",
"targets": {
"module": {
"optimize": true,
"source": "src/index.js",
"isLibrary": true
},
"iframe": {
"source": "src/index.html",
"optimize": true
}
},
"_id": "[email protected]"
}
10 changes: 10 additions & 0 deletions src/anybody.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export class Anybody extends EventEmitter {
todaysRecords: {},
levelSpeeds: [],
bodyData: null,
gameMode: 'score',
// debug: false,
// Add default properties and their initial values here
startingBodies: 1,
Expand Down Expand Up @@ -231,6 +232,7 @@ export class Anybody extends EventEmitter {

// run once at initilization
init() {
this.hits = []
this.skipAhead = false
this.winScreenBaddies = undefined
this.seed = utils.solidityKeccak256(['uint256'], [this.day])
Expand Down Expand Up @@ -524,6 +526,9 @@ export class Anybody extends EventEmitter {
}

step(bodies = this.bodies, missiles = this.missiles) {
if (this.gameOver && missiles.length !== 0) {
missiles = []
}
// this.steps ||= 0
// console.log({ steps: this.steps })
// this.steps++
Expand All @@ -536,6 +541,9 @@ export class Anybody extends EventEmitter {
console.log('LASTMISSILECANTBEUNDONE = FALSE')
this.lastMissileCantBeUndone = false
}
if (this.gameOver) {
this.missiles = []
}
bodies = this.forceAccumulator(bodies)
var results = this.detectCollision(bodies, this.missiles)
bodies = results.bodies
Expand Down Expand Up @@ -646,9 +654,11 @@ export class Anybody extends EventEmitter {
]

const { address, day, level, bodyInits, bodyFinal, framesTook } = this
const points = this.calculatePoints()

const results = JSON.parse(
JSON.stringify({
points,
day,
level,
inflightMissile,
Expand Down
117 changes: 113 additions & 4 deletions src/calculations.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { utils } from 'ethers'

export const Calculations = {
forceAccumulator(bodies = this.bodies) {
bodies = this.convertBodiesToBigInts(bodies)
Expand Down Expand Up @@ -363,6 +365,10 @@ export const Calculations = {
) {
missile.radius = 0n
}
// const maxVectorScaled = this.convertFloatToScaledBigInt(this.vectorLimit)
// const maxWidth = BigInt(this.windowWidth) * this.scalingFactor
// const maxHeight = BigInt(this.windowHeight) * this.scalingFactor
const maxVectorScaled = this.convertFloatToScaledBigInt(this.vectorLimit)

for (let j = 0; j < bodies.length; j++) {
const body = bodies[j]
Expand All @@ -389,16 +395,119 @@ export const Calculations = {
missile.radius = 0n
const x = this.convertScaledBigIntToFloat(body.position.x)
const y = this.convertScaledBigIntToFloat(body.position.y)
this.explosions.push(
...this.convertBigIntsToBodies([JSON.parse(JSON.stringify(body))])
)
const convertedBody = this.convertBigIntsToBodies([
JSON.parse(JSON.stringify(body))
])[0]
convertedBody.frame = this.frames
this.explosions.push(convertedBody)
this.hits.push(convertedBody)
if (!this.util) {
this.makeExplosionStart(x, y)
this.shakeScreen()
this.sound?.playExplosion(x, y)
}
if (convertedBody.bodyIndex == 0) {
// bodies[j].radius = 0n
} else if (this.introStage < this.totalIntroStages) {
bodies[1].radius = 0
}

bodies[j].radius = 0n
const randXseed = utils.solidityKeccak256(
['uint256'],
[body.position.x]
)
const randomX = BigInt(
this.randomRange(
0,
BigInt(this.windowWidth) * this.scalingFactor,
randXseed
)
)
const randYseed = utils.solidityKeccak256(
['uint256'],
[body.position.y]
)
const randomY = BigInt(
this.randomRange(
0,
BigInt(this.windowHeight) * this.scalingFactor,
randYseed
)
)

const randVXseed = utils.solidityKeccak256(
['uint256'],
[body.velocity.x]
)
const randomVX =
BigInt(
this.randomRange(
maxVectorScaled / 2n,
(maxVectorScaled * 3n) / 2n,
randVXseed
)
) - maxVectorScaled

const randVYseed = utils.solidityKeccak256(
['uint256'],
[body.velocity.y]
)
const randomVY =
BigInt(
this.randomRange(
maxVectorScaled / 2n,
(maxVectorScaled * 3n) / 2n,
randVYseed
)
) - maxVectorScaled
console.log({ randomX, randomY, randomVX, randomVY })
// TODO: newBody.velocity.y = this.convertScaledBigIntToFloat(body.velocity.y)
body.position.x = randomX
body.position.y = randomY
body.velocity.x = randomVX
body.velocity.y = randomVY

// line of division is x = -y
// if (body.position.x > maxHeight - body.position.y) {
// body.position.x = 0n
// body.position.y = 0n
// // body.velocity.x = maxVectorScaled / 2n
// // body.velocity.y = maxVectorScaled / 2n
// } else {
// body.position.x = maxWidth
// body.position.y = maxHeight
// // body.velocity.x = -maxVectorScaled / 2n
// // body.velocity.y = -maxVectorScaled / 2n
// }

// if (body.position.x > maxWidth / 2n) {
// // right side of screen
// if (body.position.y > maxHeight / 2n) {
// // bottom right
// body.position.x = 0n
// body.position.y = 0n
// } else {
// if (body.position.x < this.body.position.y) {
// }
// // top right
// body.position.x = maxWidth
// body.position.y = maxHeight
// }
// } else {
// // left side of screen
// if (body.position.y > maxHeight / 2n) {
// // bottom left
// body.position.x = body.position.y = maxWidth
// } else {
// // top left
// body.position.x = 0n
// body.position.y = 0n
// }
// }
// body.position.x = maxWidth
// body.position.y = 0n
// body.velocity.x = -maxVectorScaled
// body.velocity.y = maxVectorScaled
}

missiles[0] = missile
Expand Down
Loading