diff options
-rw-r--r-- | game_mechanics.txt | 1 | ||||
-rw-r--r-- | gui.py | 47 | ||||
-rw-r--r-- | mechanics.py | 3 | ||||
-rw-r--r-- | reversing_game_mechanics/zoomlevel/README | 2 | ||||
-rw-r--r-- | reversing_game_mechanics/zoomlevel/fit.log | 46 | ||||
-rw-r--r-- | reversing_game_mechanics/zoomlevel/win.size.gnuplot | 5 |
6 files changed, 51 insertions, 53 deletions
diff --git a/game_mechanics.txt b/game_mechanics.txt index 1bb5987..9c64805 100644 --- a/game_mechanics.txt +++ b/game_mechanics.txt @@ -5,3 +5,4 @@ can eat ejected mass if mass >= 18 i.e. size >= 43 cell can eat us, if their size/mass(??) is at least 1.25* our size/mass +zoom level is 369.399 * sum(own_cells.size) ** 0.431776 @@ -6,6 +6,7 @@ from pygame.locals import * import sys import math import time +import mechanics from agarnet.agarnet.vec import Vec running = True @@ -136,12 +137,31 @@ def draw_text(pos, text, color, font_size=16, global_coords=True, draw_centered= def update(): pygame.display.update() -def calc_zoom(): - zoom1 = screensize[0] / 2051. - zoom2 = screensize[1] / 1216. - return max(zoom1,zoom2) +def update_zoom(): + global zoom + global calculated_visible_width, calculated_visible_height + + ratio = 1.7 # reverse engineered value. + + size = sum(map(lambda cell : cell.size, c.player.own_cells)) + + # reverse engineered formula + diag_server = mechanics.viewport_diag(size) if size > 0 else 10000 + + # calculate screen diag, if we would have a screen with our width, but correct ratio + diag1 = math.sqrt(screensize[0]**2 * (1 + 1/1.7**2)) + # calculate screen diag, if we would have a screen with our height, but correct ratio + diag2 = math.sqrt(screensize[1]**2 * (1 + 1.7**2)) + + # what we expect to be visible from server + calculated_visible_width = diag_server / math.sqrt(1+1/ratio**2) + calculated_visible_height = diag_server / math.sqrt(1+ ratio**2) + + zoom1 = screensize[0] / calculated_visible_width + zoom2 = screensize[1] / calculated_visible_height + + zoom = min(zoom1,zoom2) / 2 -zoom = calc_zoom() def world_to_win_length(l): return int(l*zoom) @@ -238,6 +258,19 @@ def draw_leaderboard(): # screen.blit(surface, (5, next_y)) next_y += surface.get_height()+5 +def draw_visible_window_borders(): + global screen + + vignette_color=(192,192,192) + vignette_width = int(max(0, (screensize[0]-world_to_win_length(calculated_visible_width))/2)) + vignette_height = int(max(0, (screensize[1]-world_to_win_length(calculated_visible_height))/2)) + + screen.fill(vignette_color, rect=((0,0),(vignette_width,screensize[1]))) + screen.fill(vignette_color, rect=((screensize[0]-vignette_width,0),(vignette_width,screensize[1]))) + screen.fill(vignette_color, rect=((0,0),(screensize[0],vignette_height))) + screen.fill(vignette_color, rect=((0,screensize[1]-vignette_height),(screensize[0],vignette_height))) + + def draw_world_borders(): top = int((c.world.top_left[0] - c.player.center[1])*zoom + screensize[1]/2) left = int((c.world.top_left[1] - c.player.center[0])*zoom + screensize[0]/2) @@ -291,8 +324,10 @@ def draw_frame(): pygame.event.pump() clock.tick() + update_zoom() clear_screen() + draw_visible_window_borders() draw_world_borders() food = list(filter(lambda x: x.is_food, c.world.cells.values())) @@ -327,7 +362,7 @@ def draw_frame(): if event.type == VIDEORESIZE: screensize = event.dict['size'] screen=pygame.display.set_mode(screensize, HWSURFACE|DOUBLEBUF|RESIZABLE) - zoom = calc_zoom() + update_zoom() pygame.display.update() if event.type == QUIT: pygame.display.quit() diff --git a/mechanics.py b/mechanics.py index d242493..1f9d5cc 100644 --- a/mechanics.py +++ b/mechanics.py @@ -1,3 +1,6 @@ def speed(size): return 86 / (size**0.45) +def viewport_diag(sizesum): + return 370 * max(sizesum,70)**0.431776 + diff --git a/reversing_game_mechanics/zoomlevel/README b/reversing_game_mechanics/zoomlevel/README index 7845ea3..a2acc90 100644 --- a/reversing_game_mechanics/zoomlevel/README +++ b/reversing_game_mechanics/zoomlevel/README @@ -28,3 +28,5 @@ Result: visible diagonal = 369.399 * sum(sizes)**0.431776 Also, analyze.py tells us that the viewport ratio is 1.7 : 1 +Additionally, if size<70, then the value 70 instead of "size" is used (found +out by tinkering around manually) diff --git a/reversing_game_mechanics/zoomlevel/fit.log b/reversing_game_mechanics/zoomlevel/fit.log deleted file mode 100644 index 10e4639..0000000 --- a/reversing_game_mechanics/zoomlevel/fit.log +++ /dev/null @@ -1,46 +0,0 @@ - - -******************************************************************************* -Thu Aug 27 21:04:27 2015 - - -FIT: data read from "win.size.all.filtered" using 1:2 - format = x:z - #datapoints = 227 - residuals are weighted equally (unit weight) - -function used for fitting: f(x) -fitted parameters initialized with current variable values - - - - Iteration 0 - WSSR : 1.99006e+09 delta(WSSR)/WSSR : 0 - delta(WSSR) : 0 limit for stopping : 1e-05 - lambda : 543.709 - -initial set of free parameter values - -a = 1 -b = 1 - -After 187 iterations the fit converged. -final sum of squares of residuals : 316175 -rel. change during last iteration : -9.20903e-11 - -degrees of freedom (FIT_NDF) : 225 -rms of residuals (FIT_STDFIT) = sqrt(WSSR/ndf) : 37.4863 -variance of residuals (reduced chisquare) = WSSR/ndf : 1405.22 - -Final set of parameters Asymptotic Standard Error -======================= ========================== - -a = 369.399 +/- 4.401 (1.191%) -b = 0.431776 +/- 0.002383 (0.5519%) - - -correlation matrix of the fit parameters: - - a b -a 1.000 -b -0.998 1.000 diff --git a/reversing_game_mechanics/zoomlevel/win.size.gnuplot b/reversing_game_mechanics/zoomlevel/win.size.gnuplot index 90886c3..aa5499c 100644 --- a/reversing_game_mechanics/zoomlevel/win.size.gnuplot +++ b/reversing_game_mechanics/zoomlevel/win.size.gnuplot @@ -2,7 +2,9 @@ min(a,b)=(a<b)?a:b max(a,b)=(a>b)?a:b f(x) = a* x**b +g(x) = aa* x**bb + cc fit f(x) "win.size.all.filtered" using 1:2 via a,b +fit g(x) "win.size.all.filtered" using 1:2 via aa,bb,cc plot "win.size.1" using 1:2:(min(1,$3/100)) lt rgb "red" pt 2 ps variable, \ "win.size.2" using 1:2:(min(1,$3/100)) lt rgb "blue" pt 2 ps variable, \ @@ -12,5 +14,6 @@ plot "win.size.1" using 1:2:(min(1,$3/100)) lt rgb "red" pt 2 ps variable, \ "win.size.6" using 1:2:(1) lt rgb "orange" pt 2 ps variable, \ x**0.4*460+50 lt rgb "gray", \ x**0.407*460-400 lt rgb "gray", \ - f(x) lt rgb "black" + f(x) lt rgb "black", \ + g(x) lt rgb "black" pause -1 |