puzzle forge clone, with ranting and other bullshit

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
monkyyy
Prole
Posts: 47
Joined: Fri Mar 16, 2012 5:29 pm

puzzle forge clone, with ranting and other bullshit

Post by monkyyy » Sat Jan 19, 2019 11:05 pm

My quick a dirty prototype works boop
main.lua
(1.94 KiB) Downloaded 28 times
If your unaware, its sorta like 2048 but you place the pieces and it takes 3 to combine and they are unmoving

I like the game puzzle forge but its was way to easy once you learned the system, so I'm going to add "threes" like separate base elements (as opposed to its simplified clone 2048); or example the base elements are copper and iron, 3 of each make refined versions. 2 iron and 1 copper makes bronze, 2 copper 1 iron makes tin(?) etc.

I would like a proper functional like pattern matching to do this, because imagine that going out 4 or 5 tiers and the 4 and 5 combination cases, thats allot of messy if statements, I'm like nah. But google searches talk about string whatevers.

Also is there a better way to do this function? Besides cleaning up the repetition

Code: Select all

function combinecheck(x,y,size)

	function touchingcheck(xx,yy,f)
		if grid[xx][yy]==size then
			f(xx,yy)
			--------
			if (not (x == xx+1 and y== yy  ) and grid[xx+1][yy  ]==size) then f(xx+1,yy  ) end
			if (not (x == xx-1 and y== yy  ) and grid[xx-1][yy  ]==size) then f(xx-1,yy  ) end
			if (not (x == xx   and y== yy+1) and grid[xx  ][yy+1]==size) then f(xx  ,yy+1) end
			if (not (x == xx   and y== yy-1) and grid[xx  ][yy-1]==size) then f(xx  ,yy-1) end
		end
	end

	touchingcount = 0
	function count(xx,yy)
		touchingcount = touchingcount + 1
	end

	function zero(xx,yy)
		grid[xx][yy]= 0
	end


	touchingcheck(x+1,y  ,count)
	touchingcheck(x-1,y  ,count)
	touchingcheck(x  ,y+1,count)
	touchingcheck(x  ,y-1,count)
	

	------

	if (touchingcount >= 2) then

		touchingcheck(x+1,y  ,zero)
		touchingcheck(x-1,y  ,zero)
		touchingcheck(x  ,y+1,zero)
		touchingcheck(x  ,y-1,zero)

		grid[x][y]=size+1
		combinecheck(x,y,size+1)
	end
end
Last edited by monkyyy on Thu Jan 24, 2019 6:31 am, edited 2 times in total.

monkyyy
Prole
Posts: 47
Joined: Fri Mar 16, 2012 5:29 pm

Re: Making a puzzle forge clone; can has pattern matching lib?

Post by monkyyy » Mon Jan 21, 2019 1:33 pm

I found "tamale", its 8 years old and I'm quite sure lua has been updated since then but who knows letssa go

https://github.com/silentbicycle/tamale

For google "functional style pattern matching lua" "lua pattern matching -strings" that was a pain to find

In theory this table should match my notes; but this "when" tag uses "captures" ???? and shockingly I want to use functional like functions some more so I'm guessing I'll need to learn that shit, if anyone has any good sources, the manual was overly technical. I'm planning on giving the magic function a sorted table of a fixed length of 7, thats also why empty has a z in front of it

Code: Select all


local tamale.var = V

local c,i,e = "copper", "iron", "z_empty"
local a,b,c =  V"a", V"b",V"c"
local w = V"_"


tier_1_table ={
	{ 
		{1,2,3,4,5,6,7} , {2,"wordswordswords"}, when= false},
		{w,w,w,w,w,w,w} , {2,"obsidion"}, 		 when= no(contains(z_empty))},
		{i,i,i,i,i,w,e} , {2,"P_iron"}},
		{c,c,c,c,c,c,e} , {2,"P_copper"}},
		{c,c,c,c,c,e,e} , {2,"P_copper"}},
		{i,i,i,w,e,e,e} , {2,"R_iron"}},
		{c,c,c,e,e,e,e} , {2,"R_copper"}},
		{c,c,c,c,e,e,e} , {2,"R_copper"}},
		{c,c,i,i,e,e,e} , {2,"unnamed"}},
		{c,c,c,i,i,i,e} , {2,"unnamed"}},
		{c,c,w,w,w,w,e} , {2,"bronze"}, when= more(c,i)},
		{a,b,w,w,w,w,e} , {2,"trash"}, when= more(i,c)},
}
  • 3 copper ore -> refined copper
    3 iron ore -> refined iron
    5 copper ore -> pure copper
    5 iron ore -> pure iron
    2 copper ore + 2 iron ore -> unnamed precursor to Damascus steel
    1 iron + 2 copper -> bronze
    2 iron + 1 copper -> trash
    7 anything -> obsidion

monkyyy
Prole
Posts: 47
Joined: Fri Mar 16, 2012 5:29 pm

Re: [solved] wanted a functional pattern matching lib, found one

Post by monkyyy » Thu Jan 24, 2019 6:30 am

Got the pattern marcher "working" within my prototype

The block of magic code is still wrong, but its functioning within love2d and not a lua5.1 interpreter

I'm confused why this line

>combine_table = table.sort(combine_table)

breaks things, but in theory I don't need it

maybe I rewrite my code to precount the types of inputs?

Thoughts?
Attachments
humble blacksmith.love
(6.02 KiB) Downloaded 21 times

monkyyy
Prole
Posts: 47
Joined: Fri Mar 16, 2012 5:29 pm

Re: puzzle forge clone, with ranting and other bullshit

Post by monkyyy » Sat Jan 26, 2019 1:38 pm

art.png
art.png (1.17 MiB) Viewed 912 times
Now with art!

Still open to comment on how best to set up my pattern matching tables.

is precounting and generating an table like {"copper" = 3, "iron" = 0} my best option?

----

I'm going to be throwing together a 1028 style "minimum viable product", any suggestions on a scoring system?
Attachments
humble blacksmith.love
(1.17 MiB) Downloaded 12 times

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Exabot [Bot], Google [Bot], Stifu, yoki and 11 guests