1K Terminal challenge

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: 1K Terminal challange

Post by ivan »

Robin wrote:The rules don't require any type of visual feedback. ;)
You cheeky!
Any ideas for next 1K challenge?
User avatar
Sir_Silver
Party member
Posts: 286
Joined: Mon Aug 22, 2016 2:25 pm
Contact:

Re: 1K Terminal challenge

Post by Sir_Silver »

What does the K in 1K in this challenge refer to? Is that supposed to be the maximum characters of code written, or perhaps it's supposed to mean 1KB file size? I read the rules in the first post and it did not really cover that as far as I could see.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: 1K Terminal challenge

Post by zorg »

If you choose "ANSI" or similar encoding, then 1 character will be == 1 byte; so 1000 (or 1024 if you're one of the 10 kinds of people) characters will be 1K bytes as well.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
hatninja
Prole
Posts: 30
Joined: Sun Apr 07, 2013 1:31 am
Contact:

Re: 1K Terminal challange

Post by hatninja »

ivan wrote:Any ideas for next 1K challenge?
I tried for Tetris once, it is really hard.
Nontheless, i think a clone of Asteroids or Space Invaders could be a good choice.
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: 1K Terminal challenge

Post by ivan »

Yes, what Zorg said.
Just make sure to use ANSI encoding and if you're on Windows replace newlines with ; since those could take up 2 bytes instead of 1.
hatninja wrote:i think a clone of Asteroids or Space Invaders could be a good choice.
Tetris might be too hard, but I'll see if Space Invaders or Asteroids are possible (personally leaning more towards Asteroids).
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: 1K Terminal challenge

Post by zorg »

tetris could be fine, though i'm not sure a <1K implementation is possible; you need to store the tetromino forms, keep track of them as tables (objects, position, type, rotation info; though all this could be encoded into 2 bytes; you need 20,10,6,1/2/4 numbers plus a bit denoting the currently active one, so in bits:5,4,3,2,1 for a total of 16 bits.)original tetris didn't have "wall kick" mechanics, just 4x4 (I,O) and 3x3(T,J,L,Z,S) grids that defined the piece rotations; if the rotated form collided with an already locked one then you could not rotate. three inputs, CW,CCW rotations, and dropping, which is also not mandatory.
If someone would want to try, here's a good resource:
http://tetris.wikia.com/wiki/Rotation_system (In the ORS article, the line "It is absolutely identical to Nintendo Rotation System, right handed version, except that the horizontal orientation of the I piece is one block higher." wanted to mean that the horizontal I piece's vertical placement is one block higher.)
https://en.wikipedia.org/wiki/Tetromino
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: 1K Terminal challenge

Post by pgimeno »

There was Space Invaders for the 1K ZX81. It would be a shame if it couldn't be done in LÖVE :nyu:
User avatar
hatninja
Prole
Posts: 30
Joined: Sun Apr 07, 2013 1:31 am
Contact:

Re: 1K Terminal challenge

Post by hatninja »

zorg wrote:tetris could be fine, though i'm not sure a <1K implementation is possible
I don't think it's possible.
I have made it to 1,223 bytes, but it seems to be around the limit before you have to start sacrificing some core features.

If anybody really does want to try, then you can have a look at my try if you want.
Attachments
1K Tetris.love
(2.65 KiB) Downloaded 102 times
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: 1K Terminal challenge

Post by zorg »

I'm currently at these milestones:
(Tetromino data is a string of 27B, includes all 7 shapes and 4/2/1 distinct rotations, counted in the 113B below)
Tetronimo pixel data to table conversion: 113B
Tetronimo flat table to hiearchical conv.: 267B
Input: 169B (supports rotation and drop)
I'd need to fit logic and draw into the remaining 475B.

Edit: Also i should probably open a new thread for this...

Edit2: Nevermind, i give up, here's what i managed to code tho, maybe someone else can find it useful:

Code: Select all

-------------------------------------------------------------------------------
--[[
	0000011001100000                        -- O 16 1 4
	0000111100000000 0010001000100010       -- I 16 2 4
	000111001 010010110 100111000 011010010 -- J  9 4 3
	000111100 110010010 001111000 010010011 -- L  9 4 3
	000011110 010011001 000011110 010011001 -- S  9 4 3
	000110011 001011010 000110011 001011010 -- Z  9 4 3
	000111010 010110010 010111000 010011010 -- T  9 4 3
	0x0660
	0x0f002222
	0x1ca5a70d2
	0x1e648f093
	0x0f2643c99
	0x19968665a
	0x1d2c9709a
	"`""¥§
!æHð“&Cɑ™hfZ,—	"
--]]

--[[
	-- 4bit version
	T,t,_={},"06600f0022221ca5a70d21e648f0930f2643c9919968665a1d2c9709a",{9,4,3}
	for c in t:gmatch"." do for i=0,3 do T[#T+1]=(tonumber(c,16)/2^i)%1 end end
--]]

-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
--[[ 109 Bytes - Tetromino data flat tableize ]]--

-- T is the temporary flat table of cells to be processed into a hierarchical one
-- t is temporary hexstring holding all the tetromino types and rotations (in order, makes it easier)
-- Goes through all bytes in the string, and stores all bits in those bytes into T

--[[
T,t={},[=[`""¥§
!æHð“&Cɑ™hfZ,—	]=];for c in t:gmatch"." do for i=0,7 do T[#T+1]=(string.byte(c)/2^i)%1 end end
--]]
T,t={},[=[`""¥§
!æHð“&Cɑ™hfZ,—	]=];for c=1,#t do for i=7,0,-1 do T[#T+1]=(string.byte(c)/2^i)%1 end end
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
--[[ 267 Bytes - Tetromino data hierarchical tableize ]]--

-- The below barf doesn't work right, so yeah...

-- _ is temporary for 3x3 ones, since we can save 6 chars per inclusion
-- A is tetronimo hierarchical table
-- Create the hierarchy: type, rotation, row index, cell content (0/1)
_={9,4,3};
t,A,a,b,c,d={{16,1,4},{16,2,4},_,_,_,_,_},{},1,0,0,0;
for i=1,#T do
	if b==0 then A[#A+1]={} end
	if b<t[a][2] then
		B=A[#A];
		B[#B+1]={};
		b=b+1;
		if c<t[a][3] then 
			C=B[#B];
			C[#C+1]={};
			c=c+1;
			if d<t[a][1] then
			 D=C[#C];
			 D[#D+1]=T[i];
			 print(A,B,C,D,a,b,c,d)
			 d=d+1;
			 else
			  d=0 
			  end 
			  else 
			  	c=0
			  	 end 
			  	 else 
			  	 	b=0;
			  	 	a=a+1 
			  	 	end 
			  	 end
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------

-- T is holder array for block "parts" (the grid), inited to 10x20 0-s.
-- t is the active block
-- I is whether t exists or not (may not save enough chars; alternative would be to do "if type(t)~='table' then" for Spawn)
-- t has these fields: 1 type1based 2 rota0based 3 rotacount0based 4 moveaction 5 y0based 6 x0based 7 rotaaction
-- t's fields for the coords denote the topleft of the 3x3 or 4x4 square of the chosen piece.
-- D is Delta accum
-- G is whether gravity is 1 cell/second (0) or 20 (1).
T,t,I,D,G,m={},{},0,1,0,math;for i=1,10 do T[i]={};for j=1,20 do T[i][j]=0 end end

love.update=function(d)
	-- Spawn
	if I<1 then -- ==0
		a=love.math.random(1,7);I,t=1,{a,0,#A[a],0,0,0,0}; -- No active blocks -> create a new one.
	end
	-- Move
	t[5]=t[4]<0 and m.max(t[5]-1,0)
	t[5]=t[4]>0 and m.min(t[5]+1,10-#A[t[1]][1])
	-- Rotate & test
	if t[7]>0 then

	end
	-- Drop / Settle
	D=D-d;
	if D<0 then -- <=0

		D=G>0 and .05 or 1 -- 1/20
	end
end

love.draw=function()
	love.graphics.points(t[5],t[6])
end

--(T[t][2]+K[k])%T[t][3]

--[[
	Spawn block if no active is present
	Block may be rotated if a key was pressed, 
	Block descends one cell per second
		If it hits another during descent, it will cease to be active: table -> number (0)

--]]

-------------------------------------------------------------------------------
--[[ 202 Bytes ]]--
-- K is supported rota keys

-- First if is move, second rota, third is drop
K={['a']=-1,['d']=1};love.keypressed=function(k)if K[k] then t[4]=K[k] end if k=='w' then t[7]=1 end if k=='d' then G=1 end end love.keyreleased=function(k) if k=='w' then G=0 else t[4],t[7]=0,0 end end
-------------------------------------------------------------------------------
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: 1K Terminal challenge

Post by ivan »

Looks pretty hard, but not impossible. :)
zorg wrote:Edit: Also i should probably open a new thread for this...
Go ahead, we might get a few more entries that way.
Post Reply

Who is online

Users browsing this forum: No registered users and 207 guests