From 58fb623fadc823962aa8e08f60cb3941b80730a3 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 22 Oct 2021 14:38:19 -0400 Subject: [PATCH 1/3] evaluation --- Gravity.py | 47 ++++++++++++++++++++++++++++++++++++++++----- firebaseConfig.json | 9 +++++++++ 2 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 firebaseConfig.json diff --git a/Gravity.py b/Gravity.py index a778440..410919c 100644 --- a/Gravity.py +++ b/Gravity.py @@ -7,7 +7,11 @@ from tkinter import * from Body import Body from Seed import Seed - +import pyrebase +import json +firebaseConfig = json.load(open('firebaseConfig.json')) +firebase = pyrebase.initialize_app(firebaseConfig) +db = firebase.database() pygame.init() root = Tk() @@ -69,7 +73,7 @@ def selectRadio(): display_label = Label(root, text = 'Display Settings') presets_label = Label(root, text = 'Presets') - +seed_text_location = (550, 10) randomNoMomentum_label = Label(root, text = 'Number of bodies', fg = disabledColor) seed_label = Label(root, text = 'Seed', fg = disabledColor) @@ -133,7 +137,22 @@ def selectRadio(): background_color = pygame.Color(30, 30, 30) bodies = [] - +maxEvalSeed, maxEval = "", 0 +secondEvalSeed, secondEval = "", 0 +thirdEvalSeed, thirdEval = "", 0 +def evaluateState(bodies): + maxBody = bodies[0] + for body in bodies: + if body.mass > maxBody.mass: + maxBody = body + value = 0 + for body in bodies: + if body != maxBody: + dist = Body.findDisplayDistance(body.pos, maxBody.pos) + if(dist > 450): + continue + value += (2025**(-1))*dist**2-0.444*dist+100 + return value # planet formation def generateRandomBodies(numBodies, massRange): return [Body((random.randint(0, screenWidth), random.randint(0, screenHeight)),\ @@ -208,7 +227,7 @@ def moveCamera(dx=0, dy=0): pressed = pygame.key.get_pressed() - clock.tick(fps) + # clock.tick(fps) # drawing the background screen.fill(background_color) @@ -353,10 +372,28 @@ def moveCamera(dx=0, dy=0): # multiplying Body.max_speed by 7.5 shows how fast a body would travel in 0.25 seconds as opposed to 0.033 seconds, as this is easier to see when dragging the line if not backUp: pygame.draw.line(screen, launch_line_info[0], launch_line_info[1], launch_line_info[2], launch_line_width) - + if frame_count >= 500 and len(bodies) > 0: + evaluation = evaluateState(bodies) + db.child('seeds').child(seed.seed).child('score').set(evaluation) + db.child('seeds').child(seed.seed).child('seed').set(seed.raw) + if(db.child('highscore').child('score').get().val() Date: Fri, 22 Oct 2021 15:51:13 -0400 Subject: [PATCH 2/3] fixes --- Gravity.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Gravity.py b/Gravity.py index 410919c..953d859 100644 --- a/Gravity.py +++ b/Gravity.py @@ -377,11 +377,15 @@ def moveCamera(dx=0, dy=0): db.child('seeds').child(seed.seed).child('score').set(evaluation) db.child('seeds').child(seed.seed).child('seed').set(seed.raw) if(db.child('highscore').child('score').get().val() Date: Sat, 23 Oct 2021 07:51:47 -0400 Subject: [PATCH 3/3] eval --- Body.py | 2 +- Gravity.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Body.py b/Body.py index d51f2e9..d1c9deb 100644 --- a/Body.py +++ b/Body.py @@ -150,7 +150,7 @@ def checkForBodyCollision(lst): # true if body1 is bigger and they are colliding absorb = dist <= body1.displayRad + body2.displayRad*Body.collisionDistanceFactor and body1.mass >= body2.mass # if body2 is bigger and they are colliding - if dist <= body2.displayRad + body1.displayRad*0.5 and body2.mass >= body1.mass: + if dist <= body2.displayRad + body1.displayRad*Body.collisionDistanceFactor and body2.mass >= body1.mass: absorb = True # swapping them so that body1 refers to the larger temp = body2 diff --git a/Gravity.py b/Gravity.py index 953d859..34272c1 100644 --- a/Gravity.py +++ b/Gravity.py @@ -382,11 +382,11 @@ def moveCamera(dx=0, dy=0): db.child('highscore').child('seed').set(seed.raw) print(seed.raw) seed = Seed(Seed.generateRandom()) - seeds = db.child('seeds').shallow().get().val() - print(len(seeds)) + # seeds = db.child('seeds').shallow().get().val() + # print(len(seeds)) print(int(evaluation)) - if(seed.raw in seeds): - seed = Seed(Seed.generateRandom()) + # if(seed.raw in seeds): + # seed = Seed(Seed.generateRandom()) bodies.clear() random.seed(seed.seed) bodies = generateRandomBodies(int(randomNoMomentum_numBodies), (8*10**22, 4*10**23))