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 a778440..34272c1 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,32 @@ 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()