|
7 | 7 | from tkinter import * |
8 | 8 | from Body import Body |
9 | 9 | from Seed import Seed |
10 | | - |
| 10 | +import pyrebase |
| 11 | +import json |
| 12 | +firebaseConfig = json.load(open('firebaseConfig.json')) |
| 13 | +firebase = pyrebase.initialize_app(firebaseConfig) |
| 14 | +db = firebase.database() |
11 | 15 | pygame.init() |
12 | 16 |
|
13 | 17 | root = Tk() |
@@ -69,7 +73,7 @@ def selectRadio(): |
69 | 73 |
|
70 | 74 | display_label = Label(root, text = 'Display Settings') |
71 | 75 | presets_label = Label(root, text = 'Presets') |
72 | | - |
| 76 | +seed_text_location = (550, 10) |
73 | 77 | randomNoMomentum_label = Label(root, text = 'Number of bodies', fg = disabledColor) |
74 | 78 | seed_label = Label(root, text = 'Seed', fg = disabledColor) |
75 | 79 |
|
@@ -133,7 +137,22 @@ def selectRadio(): |
133 | 137 | background_color = pygame.Color(30, 30, 30) |
134 | 138 |
|
135 | 139 | bodies = [] |
136 | | - |
| 140 | +maxEvalSeed, maxEval = "", 0 |
| 141 | +secondEvalSeed, secondEval = "", 0 |
| 142 | +thirdEvalSeed, thirdEval = "", 0 |
| 143 | +def evaluateState(bodies): |
| 144 | + maxBody = bodies[0] |
| 145 | + for body in bodies: |
| 146 | + if body.mass > maxBody.mass: |
| 147 | + maxBody = body |
| 148 | + value = 0 |
| 149 | + for body in bodies: |
| 150 | + if body != maxBody: |
| 151 | + dist = Body.findDisplayDistance(body.pos, maxBody.pos) |
| 152 | + if(dist > 450): |
| 153 | + continue |
| 154 | + value += (2025**(-1))*dist**2-0.444*dist+100 |
| 155 | + return value |
137 | 156 | # planet formation |
138 | 157 | def generateRandomBodies(numBodies, massRange): |
139 | 158 | return [Body((random.randint(0, screenWidth), random.randint(0, screenHeight)),\ |
@@ -208,7 +227,7 @@ def moveCamera(dx=0, dy=0): |
208 | 227 |
|
209 | 228 | pressed = pygame.key.get_pressed() |
210 | 229 |
|
211 | | - clock.tick(fps) |
| 230 | + # clock.tick(fps) |
212 | 231 |
|
213 | 232 | # drawing the background |
214 | 233 | screen.fill(background_color) |
@@ -353,10 +372,28 @@ def moveCamera(dx=0, dy=0): |
353 | 372 | # 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 |
354 | 373 | if not backUp: |
355 | 374 | pygame.draw.line(screen, launch_line_info[0], launch_line_info[1], launch_line_info[2], launch_line_width) |
356 | | - |
| 375 | + if frame_count >= 500 and len(bodies) > 0: |
| 376 | + evaluation = evaluateState(bodies) |
| 377 | + db.child('seeds').child(seed.seed).child('score').set(evaluation) |
| 378 | + db.child('seeds').child(seed.seed).child('seed').set(seed.raw) |
| 379 | + if(db.child('highscore').child('score').get().val()<evaluation): |
| 380 | + db.child('highscore').child('score').set(evaluation) |
| 381 | + db.child('highscore').child('seed').set(seed.raw) |
| 382 | + print(seed.raw) |
| 383 | + seed = Seed(Seed.generateRandom()) |
| 384 | + if(seed.raw in db.child('seeds').shallow().get().val()): |
| 385 | + seed = Seed(Seed.generateRandom()) |
| 386 | + bodies.clear() |
| 387 | + random.seed(seed.seed) |
| 388 | + bodies = generateRandomBodies(int(randomNoMomentum_numBodies), (8*10**22, 4*10**23)) |
| 389 | + frame_count = 0 |
357 | 390 | frame_label_text = "Frame: {}".format(frame_count) |
358 | 391 | frame_label = game_font.render(frame_label_text, 1, WHITE) |
359 | 392 | screen.blit(frame_label, frame_text_location) |
360 | 393 |
|
| 394 | + seed_label_text = "Seed: {}".format(seed.raw) |
| 395 | + seed_label = game_font.render(seed_label_text, 1, WHITE) |
| 396 | + screen.blit(seed_label, seed_text_location) |
| 397 | + |
361 | 398 | pygame.display.update() |
362 | 399 | pygame.display.flip() |
0 commit comments