Re: Compétition PurePunch Juillet-Août 2014
Publié : lun. 21/juil./2014 12:33
Question bête, on peut voter pour soi ?
Forums PureBasic - Français
https://www.purebasic.fr/french/
Code : Tout sélectionner
;*******************************************************************************
;*
;* July-August 2014 PurePunch contest
;* PureBasic 5.22
;* 50 lines of 80 chars, 2 months delay
;*
;* Name : MoonLander nightmare
;* Author : Graph100
;* Date : 21/07/2014
;* Notes : You are inside an asteroid, and must go on as long as possible,
;* collecting fuel and point. Try to have the higest score !
;*
;* [Left][Rigth] : direction booster
;* [Bas] : main thrust
;* [Haut] : syncro Booster
;*
;* Version 6
;*******************************************************************************
Macro M:Macro:EndMacro:M E:End:End#M:M St:Structure:End#M:M Sp:Sprite:End#M:C.d;
M H:Element:E#M:M Q:#PB_Key_:E#M:M R:Window:E#M:M U:Random:E#M:M Ke:Keyboard:E#M
Init#Sp():M SM:x.d:y.d:a.d:u.d:v.d:m.d:l.d:b.d:E#St:E#M:UsePNGImageDecoder():T.d
St Mo:SM:St Ob:w.d:I.d:List f.Mo():SM:K.Ob:B.Ob:L.Ob:Open#R(0,0,0,800,600,"M",;#
#PB_#R#_ScreenCentered|#PB_#R#_SystemMenu):Open#R#edScreen(R#ID(0),0,0,800,600);
Load#Sp(0,"M.png"):M N:Next:E#M:Init#Ke():x.d:y.d:M CC(i,x,y,k,l,b=2):Copy#Sp(0,
i,4):Clip#Sp(i,x,y,k,l):Zoom#Sp(i,k*b,l*b):E#M:Clip#Sp(0,2,21,55,42):CC(1,61,38,
15,25,1):For i=0 To 9:CC(10+i,80,3+i*6,5,7):N:CC(9,80,9,13,7):CC(6,56,3,25,7);##
CC(7,60,9,21,7):CC(8,1,9,53,9,4):Create#Sp(4,10,10):F.d:Procedure DN(L,x,y):i=0+
Int(Log10(L)):p=Pow(10,i):For j=0 To i:r=Int(L/p):L-r*p:p/10:Display#Sp(10+r,x,;
y):x+8:N:E#Procedure:DB: :NewList S.Ob():Clear#St(L,Ob):Initialize#St(L,Ob):D.d;
L\x=400:L\b=50000000:L\y=300:L\m=1206:L\I=43172:#P=#PI/2:*d.Mo=Add#H(L\f()):CR=0
*g.Mo=Add#H(L\f()):*d\a=0.715743:*d\l=30.479501:*c.Mo=Add#H(L\f()):*d\b=-#P:CS=5
*g\a=2.425849:*g\l=30.4:*g\b=-#P:Initialize#St(K,Ob):*o.Mo=Add#H(K\f()):*c\b=-#P
M El:ElapsedMilliseconds():E#M:K\x=-10:K\y=300:*c\m=0:*c\a=#P:*o\m=50:Ke#Mode(1)
CB=50:*c\l=5:*o\a=0:*o\l=300:ti=El:Repeat:*d\m=0:*g\m=0:Z.d=(El-ti)/1000:*c\m=0;
Repeat:EV=R#Event():If EV=#PB_Event_Close#R:E:E#If:Until EV=0:Examine#Ke():ti=El
If Ke#Pushed(Q#Escape):E:E#If:If CR:Z=0:If Ke#Pushed(Q#Space):Goto DB:E#If:Else;
If Ke#Pushed(Q#Up):*d\m=10000:*g\m=10000:D=0:E#If:If Ke#Pushed(Q#Left):*d\m+5000
E#If:A.d=0:If Ke#Pushed(Q#Right):*g\m+5000:E#If:If Ke#Pushed(Q#Down):*c\m=50000;
E#If:E#If:C=0:CT+1:ForEach L\f():*m.Mo=L\f():L\b-*m\m:If L\b<0:L\b=0:Break:E#If;
T=L\a+*m\a:*m\x=*m\l*Cos(T):G.d:*m\y=*m\l*Sin(T):T=L\a+*m\b:*m\u=*m\m*Cos(T);###
*m\v=*m\m*Sin(T):D+*m\x**m\v-*m\u**m\y:A+*m\u:C+*m\v:N:A/L\m:C/L\m+10:D/L\I:L\u+
A*Z:L\v+C*Z:L\w+D*Z:L\a+L\w*Z:T=L\u*Z:B\x-T:K\x-T:T=L\v*Z:B\y-T:ClearScreen(0);#
K\y-T:Rotate#Sp(0,L\a*90/#P,0):DisplayTransparent#Sp(0,L\x-27,L\y-21):Grab#Sp(2,
L\x-34,L\y-34,68,68,4):ClearScreen($FFFFFF):Repeat:If F>=-200 And F<=1000 And;##
G>=-200 And G<=800:x1.d:*e.Mo=Add#H(K\f()):*e\a=*o\a+(U(20)-10)/#P/20:*e\l=*o\l+
U(20)-10:If *e\l<100:*e\l=100:E#If:If *e\l>400:*e\l=400:E#If:CB-1:CS-1:*e\m=0+;#
U(20)+40:*e=*o:E#If:F=K\x:G=K\y:ForEach K\f():T=K\f()\a+#P:x=F+K\f()\l*Cos(T)/2;
y=G+K\f()\l*Sin(T)/2:T=K\f()\a-#P:x1=F+K\f()\l*Cos(T)/2:F+K\f()\m*Cos(K\f()\a);#
y1.d=G+K\f()\l*Sin(T)/2:G+K\f()\m*Sin(K\f()\a):Transform#Sp(4,x,y,ox.d,oy.d,J.d,
oy1.d,x1,y1):Display#Sp(4,0,0):ox=x:oy=y:J=x1:oy1=y1:N:If CB<0:CB=30;###########
T=K\f()\l-60:T=(U(T)-T/2):B\x=F+T*Cos(K\f()\a+#P):B\y=G+T*Sin(K\f()\a+#P):B\l=1;
E#If:If CS<0:CS=5:Last#H(S()):Add#H(S()):T=K\f()\l-60:T=(U(T)-T/2):S()\x=F+;####
T*Cos(K\f()\a+#P):S()\y=G+T*Sin(K\f()\a+#P):S()\v=100*Abs(T)/(K\f()\l/2-50);####
S()\l=1:E#If:If ListSize(K\f())>40:First#H(K\f()):K\x=K\x+K\f()\m*Cos(K\f()\a);#
K\y=K\y+K\f()\m*Sin(K\f()\a):Delete#H(K\f()):*o=Last#H(K\f()):E#If;#############
Until F<-200 Or F>1000 Or G<-200 Or G>800:StartDrawing(ScreenOutput());#########
For i=0 To 15:T=i*2*#PI/15:If Point(400+22*Cos(T),300+22*Sin(T)):CR=1:E#If:Next;
If Point(400+34*Cos(0.64+L\a),300+34*Sin(0.64+L\a)) Or Point(400+34*Cos(2.5+;###
L\a),300+34*Sin(2.5+L\a)):CR=1:E#If:If L\b:ForEach L\f():For i=-5 To 5:T=L\a+;##
L\f()\b+i/10:LineXY(L\x+L\f()\x,L\y+L\f()\y,L\x+L\f()\x-L\f()\m*Cos(T)/500,L\y+;
L\f()\y-L\f()\m*Sin(T)/500,$88FF):N:N:E#If:StopDrawing();#######################
DisplayTransparent#Sp(2,L\x-34,L\y-34):If B\l:If Sp#PixelCollision(1,B\x-7,B\y+;
-12,2,L\x-34,L\y-34):L\b+25000000:B\l=0:E#If:DisplayTransparent#Sp(1,B\x-7,B\y+;
-12):E#If:ForEach S():S()\x-L\u*Z:S()\y-L\v*Z:If S()\l:If Sp#PixelCollision(9,;#
S()\x-6,S()\y-3,2,L\x-34,L\y-34):S()\l=0:L\l+S()\v:E#If:DN(S()\v,S()\x-6,S()\y+;
-3):E#If:N:Display#Sp(6,352,5):DN(L\l,400,5): Display#Sp(7,360,19):DN(L\b/5000,;
400,19):If CR And CT%50<30:Display#Sp(8,294,282):E#If:FlipBuffers():ForEver;####
;################PURE#PUNCH###AOUT#2014###MOONLANDER#BY#GRAPH100################
Code : Tout sélectionner
;*****************************************************************************
;*
;* July-August 2014 PurePunch contest
;* PureBasic 5.22
;* 50 lines of 80 chars, 2 months delay
;*
;* Name : PurePunch Cruncher
;* Author : Majikeyric
;* Date : 22/07/2014
;* Notes : A tool to crunch your PB sources without any effort and
;* enter the PurePunch contest!
;*
;*****************************************************************************
Macro M:Macro:EndMacro:M CP:Compiler:EndMacro:M Z:Select:EndMacro:M Y:Case;;;;;;
EndMacro:M B:EndIf:EndMacro:M X:EndSelect:EndMacro:M W:CompilerCase:EndMacro;;;;
M PR:Procedure:EndMacro:M EP:EndProcedure:EndMacro:M SK:ReadAsciiCharacter(fe);;
EndMacro:M G:Gadget:EndMacro:M S1:String:EndMacro:M XY(t,k,d):Y k:Z et:Y #F;;;;;
c$=t#FileRequester("","","*.*|*.*",0):If c$<>"":Set#G#Text(d,c$):B:X:EndMacro;;;
M AE(s):AddElement(c()):c()\v=s:EndMacro:M RI(n,c):Right(I$,n)<>c:EndMacro;;;;;;
M MR(a,s):MessageRequester(a,s):EndMacro:#Q=34:#P=#PB_Any:#X=#PB_Compiler_OS;;;;
#W=#PB_OS_Windows:#M=#PB_OS_MacOS:#L=#PB_OS_Linux:#F=#PB_EventType_LeftClick;;;;
#Z=#PB_Window_SystemMenu|#PB_Window_ScreenCentered:#N=0:#Ch=1:#CC=2:#Co=3:#Es=4;
Global I$,L$:Global FS,Er,TLM,NCI,NL,Et:PR CEC(p,t.s):If p<=0 Or p>Len(t);;;;;;;
PR#Return 0:B:i=1:While i<=p:If Asc(Mid(t,i,1))=#Q:r!1:B:i+1:Wend:PR#Return r:EP
PR RPT(c$):Structure Re:v.s:p.i:EndStructure:NewList c.Re():AE(":"):AE("rO");;;;
AE("rOX"):AE("dnA"):AE(","):AE("+"):c$=Left(c$,TLM):ch$=c$:p=1:While p<=TLM;;;;;
If CEC(p,ch$):c$=Left(c$,p-1)+"-"+Mid(c$,p+1):B:p+1:Wend:c$=Reverse#S1(c$);;;;;;
ForEach c():p=Find#S1(c$,c()\v):If p<>0:p=TLM-p+1:B:c()\p=p:Next;;;;;;;;;;;;;;;;
SortStructuredList(c(),#PB_Sort_Descending,OffsetOf(Re\p),#PB_Integer);;;;;;;;;;
FirstElement(c()):PR#Return c()\p:EP:PR EI(ft=0):If I$<>"" Or ft:If Right(I$,;;;
1)<>"," And RI(1,"+") And RI(2,Chr(#Q)+"+") And RI(2,"Or") And RI(3,"XOr") And;;
RI(3,"And"):If L$="" Or I$="":s.s="":Else:s=":":B:L$=L$+s+I$:I$="";;;;;;;;;;;;;;
While Len(L$)>=TLM And Not Er:If Len(L$)=TLM:Write#S1#N(FS,L$):NL+1:L$="";;;;;;;
ElseIf Len(L$)>TLM:If CEC(TLM,L$) And CEC(TLM-1,L$) And CEC(TLM-2,L$);;;;;;;;;;;
Write#S1#N(FS,Left(L$,TLM-2)+Chr(#Q)+"+"):NL+1:L$=Chr(#Q)+Mid(L$,TLM-1):Else;;;;
p=RPT(L$):If p=0:Er=4:Else:If Mid(L$,p,1)=":":L$=Replace#S1(L$,":","",;;;;;;;;;;
#PB_#S1#_CaseSensitive,p,1):p-1:B:Write#S1#N(FS,LSet(Left(L$,p),TLM,";")):NL+1;;
NCI+TLM-Len(Left(L$,p)):L$=Trim(Mid(L$,p+1)):B:B:B:Wend:If ft And L$<>"";;;;;;;;
Write#S1#N(FS,LSet(L$,TLM,";")):NCI+TLM-Len(L$):NL+1:B:ElseIf Right(I$,;;;;;;;;;
2)=Chr(#Q)+"+":I$=Left(I$,Len(I$)-2):Et=#CC:B:B:EP:PR C(s$,t$,l):Er=0:NCI=0;;;;;
TLM=l:fe=ReadFile(#P,s$):If fe:FS=CreateFile(#P,t$):If FS:Et=#N:L$="":I$="":NL=0
While Not Eof(fe) And Not Er:o=ReadAsciiCharacter(fe):Z Et:Y #N:Z o:Y #Q:Et=#Ch;
I$+Chr(o):Y 59:EI():eac=Et:Et=#Co:Y 58:EI():Y 32,9:Et=#Es:CP#Z #X:W #W:Y $0d:SK;
W #M:Y $0d:W #L:Y $0a:CompilerEndSelect:EI():Default:I$+Chr(o):X:Y #Ch:Z o:Y #Q;
Et=#N:I$+Chr(o):Y $0d,$0a:Er=3:Default:I$+Chr(o):X:Y #CC:Z o:Y #Q:Et=#Ch:Y $0d,;
$0a:Er=3:X:Y #Co:CP#Z #X:W #W:If o=$0d:SK:W #M:If o=$0d:W #L:If o=$0a;;;;;;;;;;;
CompilerEndSelect:Et=eac:B:Y #Es:Z o:CP#Z #X:W #W:Y $0d:SK:W #M:Y $0d:W #L:Y $0a
CompilerEndSelect:Et=#N:EI():Y 59:EI():eac=Et:Et=#Co:Y 58:Et=#N:EI():Y 32,9;;;;;
Y 44,61,43,45,42,47,38,124,33,126,60,62,37,41:I$+Chr(o):Et=#N:Default:If I$<>"";
If Find#S1(",=+-*/&|!~<>%(",Right(I$,1)):I$+Chr(o):Else:I$+" "+Chr(o):EndIf:Else
I$=Chr(o):B:If o=#Q:Et=#Ch:Else:Et=#N:B:X:X:Wend:If Not Er:If L$<>"" Or I$<>"";;
EI(1):B:B:CloseFile(FS):Else:Er=2:B:CloseFile(fe):Else:Er=1:B:Z Er:Y 1:me$="Op"+
"en err":Y 2:me$="Write err":Y 3:me$="EOL in string":Y 4:me$="line>"+Str(TLM)+;;
" chars":X:If me$="":MR("","Lines:"+Str(NL)+",free chars:"+Str(NCI)):Else:MR("",
me$):B:EP:OpenWindow(0,0,0,360,103,"PurePunch Cruncher",#Z):Text#G(#P,10,12,70,;
25,"Source file :"):Text#G(#P,10,42,70,25,"Target file :"):ss=S1#G(#P,75,10,240,
20,""):st=S1#G(#P,75,40,240,20,""):bs=Button#G(#P,320,10,30,20,"...");;;;;;;;;;;
BT=Button#G(#P,320,40,30,20,"..."):bc=Button#G(#P,120,69,230,23,"Crunch");;;;;;;
Text#G(#P,10,72,100,20,"Line length :"):sl=String#G(#P,75,70,40,20,"80"):Repeat;
e=WaitWindowEvent():eg=Event#G():et=EventType():Z e:Y #PB_Event_CloseWindow:End;
Y #PB_Event_#G:Z eg:XY(Open,bs,ss):XY(Save,BT,st):Y bc:Z et:Y #F;;;;;;;;;;;;;;;;
s$=Get#G#Text(ss):t$=Get#G#Text(st):l$=Get#G#Text(sl):If s$="" Or t$="" Or l$=""
MR("","Empty!"):ElseIf s$=t$:MR("","S=T!"):Else:C(s$,t$,Val(l$)):B:X:X:X:ForEver
majikeyric a écrit :Plus d'excuses pour ne pas participer
Ah ben, il n'est pas fait pour être facile ^^G-Rom a écrit :@Graph100
Tendu quand même ^^ , heureusement que tu ne bosses pas à la nasa pour la prochaine mission d’atterrissage sur Mars...
Mon objectif pour un premier jet était de rentrer dans les 50 lignes car n'oublions pas que c'est un punch.graph100 a écrit :sympa ton utilitaire, tu rajouteras pas la détection des variables, des commandes nombreuses, pour raccourcir les nom ?
Whaouuu 9 lignes de gagnées! c'est pas négligeable.falsam a écrit :@majikeyric: Merci pour ton code. Mon Pure Punch Code est passé de 48 lignes à 39 lignes. Peut être que je vais ajouter une nouvelle fonctionnalité à mon code.