### Author Topic: [ENDED] Code Golf Contest #5  (Read 20077 times)

0 Members and 1 Guest are viewing this topic.

#### JWinslow23

• Coder Of Tomorrow
• LV7 Elite (Next: 700)
• Posts: 556
• Rating: +43/-6
• I make quality calculator games...when I have time
##### [ENDED] Code Golf Contest #5
« on: August 11, 2014, 01:19:21 pm »
This challenge will never happen again.

NEXT: Here
PREVIOUS: Here

Challenge 5

Problem
You must make a game of Snake (or Nibbles, if you know it as that). It must follow all of these guidelines:
• It must be played on an square "grid" (each space being the width of one snake segment) as large as possible
• The graphics for the food and the snake segments must each be different
• The border must be clearly defined, and have different graphics from the food or the snake
• The food must spawn on a random EMPTY square, Adriweb
• The snake is moved with interactive input (such as a getKey-like command) if possible; if not supported, you may enter a direction each frame
• Your snake must wrap around the sides of the board
• At game's end, the program must display however many pieces of food were eaten in some way
• Your game, above all, must be playable
August 18, 2014, 1:00 AM EST

As there is random chance involved, and it is interactive input, no sample input shall be given.

If any further clarification is needed, contact me or Runer112. We will try to guide your heads in the right direction. (Get it? Like, you're guiding the snake's head in a certain dire...ah, just forget it.)

Nspire Lua
 Rank User Size Board Size Date Code 1 Adriweb 548 23*23 8/16/2014 4:57:21 PM Spoiler For Spoiler: a,b=5,2x,y=0,1g,h={5},{2}c=0f=0m=math.randomr=table.removetimer.start(.1)on={charIn=function(n)x=({x=-1,z=1})[n]or 0y=({r=-1,y=1})[n]or 0end,paint=function(n)z=n.drawStringz(n,f,14*a,9*b)for e=1,#g doz(n,8,14*g[e],9*h[e])endend,timer=function()g[#g+1]=(g[#g]+x)%23h[#h+1]=(h[#h]+y)%23for n=1,#g-1 doif g[n]==g[#g]and h[n]==h[#h]thenerror(c)endendif a==g[#g]and b==h[#h]thenrepeata=m(22)b=m(21)for n=1,#g doif a==g[n]and b==h[n]thend=0breakelsed=1endenduntil d>0c=c+1elser(g,1)r(h,1)endplatform.window:invalidate()end}

TI-83+ BASIC
 Rank User Size Board Size Date Code 1 JWinslow23 301 21*21 8/11/2014 9:55:09 AM Spoiler For Spoiler: 26->K1.01->B{4Ans->A"300fPart(Ans)-2->u"2-3int(Ans->vClrDrawAxesOffZStandard104->Xmax~72->YminZIntegerVertical 63For(A,1,440Repeat not(sum(⌊A=AnsrandInt(1,21)+.01randInt(1,21->CEndRepeat sum(Ans=CA->dim(⌊A⌊A(1Pt-On(u,v,2BPt-Off(u,v,2CPt-On(u,v,3Pt-Off(u,vgetKey->LIf Ans=34 or 2>abs(Ans-25Ans->K⌊A(A->B⌊A(1)+(K=34)-(K=25)+.01((K=26)-(K=24Ans+21(not(int(Ans))-(22=int(Ans))+.01(not(fPart(Ans))-(.22=fPart(AnsIf L=45 or sum(⌊A=AnsGoto 0augment({Ans},⌊A->AEndaugment(Ans,{Ans(A->AEndLbl 0ClrHomeA

TI-84+CSE BASIC
 Rank User Size Board Size Date Code 1 JWinslow23 336 165*165 8/12/2014 4:02:45 PM Spoiler For Spoiler: 26->K:1.001->B:{4Ans->AClrDraw:AxesOffBorderColor 3BackgroundOff:ZStandardVertical 2.5,12For(A,1,600Repeat not(sum(⌊A=AnsrandInt(1,165)+.001randInt(1,165->CEndRepeat sum(Ans=CA->dim(⌊A⌊A(1Pxl-On(fPart(Ans)E3-1,int(Ans-1),14Pxl-Off(fPart(B)E3-1,1-int(B-1Pxl-On(fPart(C)E3-1,1-int(C-1),11getKey->LIf Ans=34 or 2>abs(Ans-25Ans->K⌊A(A->B⌊A(1)+(K=34)-(K=25)+.001((K=26)-(K=24Ans+165(not(int(Ans))-(166=int(Ans)))+.165(not(fPart(Ans))-(.166=fPart(AnsIf L=45 or sum(⌊A=AnsGoto 0augment({Ans},⌊A->AEndaugment(Ans,{Ans(A->AEndLbl 0ClrHomeA

Java
 Rank User Size Board Size Date Code 1 ben_g 1610 (screen_height-20)*(screen_height-20) 8/12/2014 1:16:46 PM Spoiler For Spoiler: import java.awt.*;import java.awt.event.*;import java.util.*;import java.util.List;import javax.swing.*;class S{static List s;static int x=20,y=20,d=0,h,i=x,j=y,o=0;static Graphics g;public static void main(String[]a){s=new ArrayList();for(int i=0;i<60;i++)s.add(new N(19,20));final JFrame f = new JFrame();f.setUndecorated(true);h=Toolkit.getDefaultToolkit().getScreenSize().height-20;f.setBounds(0,20,h,h);f.addKeyListener(new KeyListener(){@Overridepublic void keyPressed(KeyEvent k){if(k.getKeyCode()==k.VK_ESCAPE)System.exit(0);if(k.getKeyCode()==k.VK_RIGHT)d=0;if(k.getKeyCode()==k.VK_DOWN)d=1;if(k.getKeyCode()==k.VK_LEFT)d=2;if(k.getKeyCode()==k.VK_UP)d=3;}@Overridepublic void keyReleased(KeyEvent k){}@Overridepublic void keyTyped(KeyEvent k){}});JPanel p=new JPanel();f.setContentPane(p);f.setVisible(true);g=f.getGraphics();while(!c(x,y)){x%=h;y%=h;if(x<0)x=h-1;if(y<0)y=h-1;g.setColor(Color.green);g.fillRect(x,y,1,1);g.setColor(Color.red);g.fillRect(i,j,1,1);g.setColor(Color.white);g.fillRect(s.get(0).x,s.get(0).y,1,1);s.add(new N(x,y));if(i==x&&j==y){o=0;for(int i=0;i<30;i++)s.add(new N(x,y));if(s.size()>=h*h)System.exit(0);}else{s.remove(0);}if(o==0){o=1;f();}long m=System.currentTimeMillis();while(System.currentTimeMillis()-m<20){}if(d==0)x++;if(d==1)y++;if(d==2)x--;if(d==3)y--;}System.out.print(s.size()/10-7);System.exit(0);}static void f(){while(c(i,j)){i=(int)(Math.random()*h);j=(int)(Math.random()*h);}}static boolean c(int x,int y){for(int i=0;i

SysRPL
 Rank User Size Board Size Date Code 1 3298 278 64*64 8/17/2014 6:59:16 PM Spoiler For Spoiler: ::  RECLAIMDISP BINT0 BINT64 BINT128  2DUP BINT0 2OVER LINEON LINEON  BINT2 BINT4  BINT32 DUP TWO{}N ONE{}N TRUE  BEGIN    VERYSLOW    IT ::      BEGIN        BINT64 UNCOERCE DUP        %RAN %* COERCE #2* SWAP        %RAN %* COERCE        2DUP PIXON? UNROT PIXON      NOT_UNTIL      ROT#1+UNROT    ;    SWAP GETTOUCH IT ::      { BINT10 BINT14 BINT15 BINT16 }      NTHOF DUP#0<> ?SWAPDROP    ;    DUPDUP 4UNROLL    BINT1 #AND #0=    3PICK FPTR2 ^LASTCOMP INCOMPDROP    3PICK ?SWAP 4ROLL    BINT2 #>ITE BINT1 BINT63 #+    BINT63 #AND    ROT ?SWAP 2DUP TWO{}N    4ROLLSWAP >TCOMP UNROTSWAP    #2* SWAP2DUP PIXON?    3PICK3PICK SWAP#1+SWAP PIXON?    2SWAP 2DUP SWAP#1+SWAP LINEON    5PICK 4PICK LENCOMP #< IT ::      ROTDUP CDRCOMP 4UNROLL      CARCOMP INCOMPDROP      SWAP #2* SWAP2DUP SWAP#1+SWAP      LINEOFF    ;  UNTIL 3DROP;

Ruby
 Rank User Size Board Size Date Code 1 Juju 611 (height-1)*(height-1) 8/18/2014 11:40:15 AM Spoiler For Spoiler: f=[7,7]s=[[4,4]]t=0z=trued=:rl,r=stty size.splitl=l.to_i-1while z doprint"\x1b[2J\x1b["+f[1].to_s+";"+f[0].to_s+"H*"s.each{|a|print"\x1b["+a[1].to_s+";"+a[0].to_s+"H#"}print"\x1b["+(l+1).to_s+";1H"+t.to_sstty raw -echoc=STDIN.read_nonblock(1)rescue nilstty -raw echocase cwhen'a'd=:lwhen's'd=:dwhen'w'd=:uwhen'd'd=:rendx,y=s[-1]case dwhen:lx-=1when:dy+=1when:uy-=1when:rx+=1endx=1 if x>lx=l if x<1y=1 if y>ly=l if y<1n=[x,y]if s.index(n)!=nilz=falseelses.push(n)if n==ft+=1while(f=[1+rand(l),1+rand(l)]).index(n)!=nil do endelses.shiftendendsleep 0.1end

Language Ranking
 Rank Lang User Size Board Size Date 1 SysRPL 3298 278 64*64 8/17/2014 6:59:16 PM 2 TI-83+ BASIC JWinslow23 301 21*21 8/11/2014 9:55:09 AM 3 TI-84+CSE BASIC JWinslow23 305 165*165 8/12/2014 4:02:45 PM 4 Nspire Lua Adriweb 548 23*23 8/16/2014 4:57:21 PM 5 Ruby Juju 611 (height-1)*(height-1) 8/18/2014 11:40:15 AM 6 Java ben_g 1610 (screen_height-20)*(screen_height-20) 8/12/2014 1:16:46 PM
« Last Edit: June 11, 2015, 08:57:59 am by pimathbrainiac »
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
= ?

#### Matrefeytontias

• Axe roxxor (kinda)
• LV10 31337 u53r (Next: 2000)
• Posts: 1982
• Rating: +310/-12
• Axe roxxor
##### Re: Code Golf Contest #5
« Reply #1 on: August 11, 2014, 01:20:49 pm »
Just so you know, someone made a 256-bytes Snake on Cemetech using z80 ASM, and it does all you said (although it uses a 16*16 grid).

#### ClrDraw

• LV7 Elite (Next: 700)
• Posts: 627
• Rating: +61/-2
##### Re: Code Golf Contest #5
« Reply #2 on: August 11, 2014, 02:15:56 pm »
I made one just the other week but it's a 33 x 21 grid and I'm too lazy to change it.

http://clrdraw.weebly.com/

Quote
Just so you know, someone made a 256-bytes Snake on Cemetech using z80 ASM, and it does all you said (although it uses a 16*16 grid).
Woah    that's awesome.
« Last Edit: August 11, 2014, 02:17:38 pm by ClrDraw »
Visit my GitHub for all my TI programs as well as other projects.
Also check out my website.

#### JWinslow23

• Coder Of Tomorrow
• LV7 Elite (Next: 700)
• Posts: 556
• Rating: +43/-6
• I make quality calculator games...when I have time
##### Re: Code Golf Contest #5
« Reply #3 on: August 11, 2014, 02:57:37 pm »
Just so you know, someone made a 256-bytes Snake on Cemetech using z80 ASM, and it does all you said (although it uses a 16*16 grid).
Notify that someone! He can change it, and submit it!

And this challenge is more oriented towards computer languages and stuff, as a quick Google search will bring up an already made answer for TI-BASIC (which I will not allow anyone to submit but the author, whom I do not know).
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
= ?

#### ben_g

• Hey cool I can set a custom title now :)
• LV9 Veteran (Next: 1337)
• Posts: 1002
• Rating: +125/-4
• Asm noob
##### Re: Code Golf Contest #5
« Reply #4 on: August 11, 2014, 03:15:10 pm »
Coded golf 5? Does that mean 4 is over already?
* Ben_g0 forgot to submit his entry again :S

Anyway, I'll try this one. Can we use simple command-line text graphics and rely on the user to set the window to the correct size?
My projects
- The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
- Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
- An android version of oxo (java)  ACTIVE
- A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
- A java MORPG. (pc) DEEP COMA(read more)(screenshot)
- a minecraft game in axe DEAD (source code available)
- a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

#### JWinslow23

• Coder Of Tomorrow
• LV7 Elite (Next: 700)
• Posts: 556
• Rating: +43/-6
• I make quality calculator games...when I have time
##### Re: Code Golf Contest #5
« Reply #5 on: August 11, 2014, 03:46:53 pm »
Coded golf 5? Does that mean 4 is over already?
* Ben_g0 forgot to submit his entry again :S

Anyway, I'll try this one. Can we use simple command-line text graphics and rely on the user to set the window to the correct size?
It doesn't matter the size of the window as long as the play area is 8 snake pieces tall and 16 snake pieces wide. And yes, you can use ASCII graphics.
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
= ?

#### ben_g

• Hey cool I can set a custom title now :)
• LV9 Veteran (Next: 1337)
• Posts: 1002
• Rating: +125/-4
• Asm noob
##### Re: Code Golf Contest #5
« Reply #6 on: August 11, 2014, 03:56:28 pm »
Well, I mainly meant that if you output text in a command line larger than the area you use, it may show garbage on the edges, like the remainder of previous frames.
My projects
- The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
- Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
- An android version of oxo (java)  ACTIVE
- A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
- A java MORPG. (pc) DEEP COMA(read more)(screenshot)
- a minecraft game in axe DEAD (source code available)
- a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

#### JWinslow23

• Coder Of Tomorrow
• LV7 Elite (Next: 700)
• Posts: 556
• Rating: +43/-6
• I make quality calculator games...when I have time
##### Re: Code Golf Contest #5
« Reply #7 on: August 11, 2014, 04:02:06 pm »
Well, I mainly meant that if you output text in a command line larger than the area you use, it may show garbage on the edges, like the remainder of previous frames.
I think you can assume that the window is at least 8*16, but if you want to change the window size to a certain number, you can.
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
= ?

• Editor
• LV10 31337 u53r (Next: 2000)
• Posts: 1708
• Rating: +229/-17
##### Re: Code Golf Contest #5
« Reply #8 on: August 11, 2014, 05:52:55 pm »
I got a working one at 533 bytes in Nspire-Lua.
Still working on it.

Also, just to be sure : we loose whenever the head of the snake touches any part of its body, right ?
(that's what I did anyway)
« Last Edit: August 11, 2014, 05:56:41 pm by Adriweb »
My calculator programs
TI-Nspire Lua programming : Tutorials  |  API Documentation

#### willrandship

• Omnimagus of the Multi-Base.
• LV11 Super Veteran (Next: 3000)
• Posts: 2953
• Rating: +98/-13
• Insert sugar to begin programming subroutine.
##### Re: Code Golf Contest #5
« Reply #9 on: August 11, 2014, 05:57:44 pm »
What are the rules on how input must work? All the languages I've been using so far don't support raw input without libraries, and it would be faster to do it via line based input, but also much worse.

It will also be impossible for you to test without installing perl/python and whatever library I use.

#### JWinslow23

• Coder Of Tomorrow
• LV7 Elite (Next: 700)
• Posts: 556
• Rating: +43/-6
• I make quality calculator games...when I have time
##### Re: Code Golf Contest #5
« Reply #10 on: August 11, 2014, 06:14:22 pm »
What are the rules on how input must work? All the languages I've been using so far don't support raw input without libraries, and it would be faster to do it via line based input, but also much worse.

It will also be impossible for you to test without installing perl/python and whatever library I use.
I will install perl or python, whichever I get submissions for. I will, however, have to see an animated screenie of any entries of Nspire Lua and any other language I can't test.
If you press a certain key, the snake goes a certain direction. If no key is pressed, the snake keeps going in its current direction. That's how input works. Plain and simple. Like getKey for TI-BASIC, or some complicated sequence with CHOICE for Batch.
Also, yes, Adriweb, that is how it works.
« Last Edit: August 11, 2014, 06:17:21 pm by JWinslow23 »
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
= ?

• Editor
• LV10 31337 u53r (Next: 2000)
• Posts: 1708
• Rating: +229/-17
##### Re: Code Golf Contest #5
« Reply #11 on: August 11, 2014, 06:16:52 pm »
I will, however, have to see an animated screenie of any entries of Nspire Lua and any other language I can't test.
My code works on Jim's js Nspire-Lua tester ^^
http://bwns.be/jim/WEBspire/editor.html
(edit : well, there's a weird behaviour on some modulus cases, though - the snake simply decides to vanish from the screen )

Also, down to 523 bytes
Edit : 522
Edit : 517
Edit : 502
« Last Edit: August 11, 2014, 06:44:07 pm by Adriweb »
My calculator programs
TI-Nspire Lua programming : Tutorials  |  API Documentation

#### JWinslow23

• Coder Of Tomorrow
• LV7 Elite (Next: 700)
• Posts: 556
• Rating: +43/-6
• I make quality calculator games...when I have time
##### Re: Code Golf Contest #5
« Reply #12 on: August 11, 2014, 06:18:07 pm »
That's great!
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
= ?

#### willrandship

• Omnimagus of the Multi-Base.
• LV11 Super Veteran (Next: 3000)
• Posts: 2953
• Rating: +98/-13
• Insert sugar to begin programming subroutine.
##### Re: Code Golf Contest #5
« Reply #13 on: August 11, 2014, 06:19:14 pm »
That's really not simple at all for any terminal-based language. Input for those languages is not handled in real time. Imagine making a basic snake with only input, not getkey, and you'll be pretty much spot on.

#### JWinslow23

• Coder Of Tomorrow
• LV7 Elite (Next: 700)
• Posts: 556
• Rating: +43/-6
• I make quality calculator games...when I have time
##### Re: Code Golf Contest #5
« Reply #14 on: August 11, 2014, 06:32:45 pm »
That's really not simple at all for any terminal-based language. Input for those languages is not handled in real time. Imagine making a basic snake with only input, not getkey, and you'll be pretty much spot on.
Is there a command like CHOICE?

http://ss64.com/nt/choice.html

If there is one of that kind of command, it should be simple enough.
« Last Edit: August 11, 2014, 06:34:19 pm by JWinslow23 »
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?