File: hyperion6.lua

package info (click to toggle)
blobby 1.1.1%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,944 kB
  • sloc: cpp: 22,442; xml: 779; python: 56; makefile: 3
file content (331 lines) | stat: -rw-r--r-- 6,806 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
-- Dies ist der BlobbyVolley2 Bot "Hyperion"
-- geschrieben und getestet wurde der Bot mit der SVN-Version
-- Die Version Blobby0.6 hatte verschiedene Bugs, unter anderem bei der oppx() und der estimate() Funktion
--
-- Hyperion ver. 0.6

-- <Abschnitt 1> - Einige Konstanten die die physikalische Welt in BlobbyVolley2 beschreiben

g=0.28
g_p=0.88
v0=14.5
v_p=4.5
jb_p=0.44
r1=31.5

-- </Abschnitt 1>


-- <Abschnitt 2> - kleine unkomplizierte Hilfsfunktionen die ich benötige

function max(a,b)
	if (a>b) then
		return a
	else
		return b
	end
end

function min(a,b)
	if (a<b) then
		return a
	else
		return b
	end
end

function y_b(y,vy,t)
-- Eingabe: Position und Geschwindigkeit des Balles, Zeitpunkt an dem man die y-Koordinate des Balles wissen möchte
-- Ausgabe: Höhe des Balles nach der Zeit t
	return y+(vy-g/10)*t-1/2*g*t^2
end

function peak(y,vy)
	return vy/g-1/10
end

function ymax_b(y,vy)
	return y_b(v,vy,peak(y,vy))
end

function move(x)
	if (posx()<x) and (math.abs(posx()-x)>2.6) then right()
	elseif (posx()>x) and (math.abs(posx()-x)>2.6) then left()
	end
end

function t1_y(y,vy,height)
-- Eingabe: Position und Geschwindigkeit des Balles, Höhe die der Ball erreichen soll
-- Ausgabe: Ausgabe der Zeit bis zur Höhe height
	if (vy^2/g^2-vy/(5*g)+1/100+2*(y-height)/g<0) then
		return -1
	else
		return -1/10+vy/g-math.sqrt( vy^2/g^2-vy/(5*g)+1/100+2*(y-height)/g )
	end
end

function t2_y(y,vy,height)
-- Eingabe: Position und Geschwindigkeit des Balles, Höhe die der Ball erreichen soll
-- Ausgabe: Ausgabe der Zeit bis zur Höhe height
	if (vy^2/g^2-vy/(5*g)+1/100+2*(y-height)/g<0) then
		return -1
	else
		return -1/10+vy/g+math.sqrt( vy^2/g^2-vy/(5*g)+1/100+2*(y-height)/g )
	end
end

function y_p(y,t)
-- Eingabe: Position und Geschwindigkeit des Players, Zeitpunkt an dem man die y-Koordinate des Players wissen möchte
-- Ausgabe: Höhe des Players nach der Zeit t
	return y+(v0+jb_p/2+g_p/10)*t-1/2*(g_p-jb_p)*t^2
end

tp_peak=(14.5+0.44/2+0.88/10)/(0.88-0.44)
yp_max=y_p(144.5,tp_peak)

function time(t)
	return 1/5*math.ceil(5*t)
end

function t2_yp(y,vy,height)
y=144.5
	return (v0+jb_p/2+g_p/10)/(g_p-jb_p)+math.sqrt((v0+jb_p/2+g_p/10)^2/(g_p-jb_p)^2+2*y/(g_p-jb_p))
end
-- </Abschnitt 2>


-- <Abschnitt 3> - Komplizierte Funktionen die die Game-Engine nachbilden und so Einschlagpunkte, etc. berechnen.

function collide(x,y,vx,vy,x2,y2,r2)
-- Berechnet, ob und nach welcher Zeit der Ball im Zustand (x,y,vx,vy) mit der Kugel an (x2,y2) mit Radius r2 kollidiert
local leftb=x2-r2-r1
local rightb=x2+r2+r1
local lowerb=y2-r2-r1
local upperb=y2+r2+r1

local txlb=time((leftb-x)/vx) -- Zeit zur linken Begrenzung
local txrb=time((rightb-x)/vx) -- Zeit zur rechten Begrenzung
local tyla=time(t1_y(y,vy,lowerb)) --untere Grenze steigend (ascending)
local tyld=time(t2_y(y,vy,lowerb)) --untere Grenze fallend (descending)
local tyua=time(t1_y(y,vy,upperb)) --obere Grenze steigend (ascending)
local tyud=time(t2_y(y,vy,upperb)) --obere Grenze fallend (descending)
local tp=time(vy/g-1/10) -- Zeit bis die Ballkurve auf dem Höhepunkt ist (kann in der Vergangenheit liegen)

local t1,t2,t_coll=0,0,-1

if (vx>0) then
		t1=max(max(txlb,tyla),0)
		t2=min(txrb,tyld)
	else
		t1=max(max(txrb,tyla),0)
		t2=min(txlb,tyld)
end

if (t1<t2) and (t1<300) and (math.abs(t1-t2)<100) then
	for t=t1,t2,0.2 do
		local xnew,ynew=x+vx*t,y_b(y,vy,t)
		if ((xnew-x2)^2+(ynew-y2)^2<(r1+r2)^2) then
			t_coll=t
			break
		end
	end
end

return t_coll
end

function estimate_t(x,y,vx,vy,height)
-- schätzt den Ort des Balles bei der Höhe height fallend und die Zeit bis dahin

local collision=1
local t_wall,t_net,t_netsphere=0,0,0
local t_ret,x_ret,y_ret,vx_ret,vy_ret=0,0,0,0,0
local t_height=0
while(collision==1) do
	t_netsphere=collide(x,y,vx,vy,400,316,7)
	if (vx>0)
		then
		t_wall=time((768.5-x)/vx)
		t_net=time((361.5-x)/vx)
		else
		t_wall=time((31.5-x)/vx)
		t_net=time((438.5-x)/vx)
	end
	local t=10000
	if ((t_netsphere>0) and (t_netsphere<t)) then t=t_netsphere end
	if (((t_net>0) and (t_net<t)) and (y_b(y,vy,t_net)<316)) then t=t_net end
	if ((t_wall>0) and (t_wall<t)) then t=t_wall end
	t_height=time(t2_y(y,vy,height))
	if (t_height>t) then
		if (t==t_netsphere) then
			t_ret=t_ret+t
			vx_ret=0
			vy_ret=0
			x_ret=400
			y_ret=316
			collision=0
		end
		if (t==t_net) or (t==t_wall) then
			t_ret=t_ret+t
			x=x+vx*t
			y=y_b(y,vy,t)
			vx=-vx
			vy=vy-g*t
			collision=1
		end
	else
		t_ret=t_ret+t_height
		vx_ret=vx
		vy_ret=vy-g*t_height
		x_ret=x+vx*t_height
		y_ret=y_b(y,vy,t_height)
		collision=0
	end


end -- while Ende
return x_ret,y_ret,vx_ret,vy_ret,t_ret
end




function impact(x,y,vx,vy,xpos,ypos)
-- schätzt den Einschlagsort des Balles wenn er mit dem Blobby an Position xpos kollidiert ist und dann losfliegt.
-- Funktioniert mit minimalem Fehler

r1=31.5
r2=25
--local x,y,vx,vy,t1=estimate_t(x,y,vx,vy,(ypos+19+25)+31.5) Die Wete haben schon nahe genug zu sein
local t=time(collide(x,y,vx,vy,xpos,ypos+19,25))
if(t>0) then
	x=x+vx*t
	y=y_b(y,vy,t)
	dx=x-xpos
	dy=y-(ypos+19)
	l=math.sqrt(dx^2+dy^2)
	vx=dx/l
	vy=dy/l
	x=x+vx*3
	y=y+vy*3
	vy=vy*13.125
	vx=vx*13.125
--	x=x+vx/5
--	y=y+vy/5
	x,y,vx,vy,t=estimate_t(x,y,vx,vy,220.5)
	return x,y,vx,vy,t
else
	return -1,-1,-1,-1,-1
end

end -- Funktionsende

function xtoplayto(target,height)

local x,y,vx,vy,t=estimate_t(ballx(),bally(),bspeedx(),bspeedy(),height+(25+19)+31.5+5)
local xpos=estimate_t(ballx(),bally(),bspeedx(),bspeedy(),height+(25+19)+31.5)
local sgn=0
if (x<target) then sgn=-1 else sgn=1 end
local imp=0
local oldimpact=-1000

for pos=xpos,xpos+sgn*30,sgn*2.5 do
	imp=impact(x,y,vx,vy,pos,height)
	if (math.abs(imp-target)<math.abs(oldimpact-target)) then
		oldimpact=imp
	else
		xpos=pos-sgn*2.5
		break
	end
end

return xpos
end


-- </Abschnitt 3>

-- <Abschnitt 4> - High-Level Funktionen die bestimmen wo man s

function stellen(tox,height)
--t2_yp
--t2_y
if (tox<390) then

elseif (390<tox) and (tox<410) then

elseif (tox>410) then

end

move(xplayto(tox,posy()))
end


function schmettern()

end

function ueberspielen()

end



-- </Abschnitt 4>

-- <Abschnitt 5> - Die Hauptfunktionen des Spiels
function OnOpponentServe()
end

function OnServe(ballready)
if (math.abs(math.floor(posx()/4.5)-posx()/4.5)<0.4)
	then
		if(math.abs(180-posx())<2) then jump() else moveto(180) end
	else
		moveto(400)
	end
	old=5
end

function OnGame()




x1=ballx()
y1=bally()
vx1=bspeedx()
vy1=bspeedy()
x2=oppx()
y2=163.5
r2=25

xe=estimate_t(x1,y1,vx1,vy1,220.5)
--debug(xe)
-- debug(x2)
xr,yr,vxr,vyr,tr=impact(x1,y1,vx1,vy1,x2,144.5)


-- debug(xr)
-- debug(0)


if (xe<400) then
		
		if (touches()==0) then
		test=xtoplayto(320,144.5)
		move(test)
		else
		test=xtoplayto(400,144.5)
		move(test-3.1)
		end


elseif (xe==400) then
	move(180)
else
	move(180)
end
old=touches()
end