Simplicity

Game development specific discussions.
Post Reply
3622
Posts: 24
Joined: Mar 14, 2015 23:53

Simplicity

Post by 3622 »

Simplicity is a 2D sliding block puzzle, my small and simple lockdown offering.
Just get the red block to the top left corner.
Tested on Linux 64 but should work on 32 bit and Windows.
It may amuse someone for 2 minutes.

Code: Select all


'		simplicity.bas

screenres 400,400
width , 400 / 16

const as ulong mask = 4167140895
const as double pi = 3.1415926535897932

dim as integer i, j, move

type board
    bb as ulong
    colour as integer
end type
   
dim as board piece(3)

data 8320, 49
data 1572864, 55
data 4192, 40
data 17170432, 44

for i = 0 to 3
    read piece(i).bb
    read piece(i).colour
next

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

sub display(piece() as board, move as integer)

dim as integer i, j, k, r, c

windowtitle "Simplicity Move : " +str(move)

screenlock()

cls
print "Get The Red" 
print " One here !" 

for i = 0 to 3
    k = -1
    for j = 5 to 26
        if bit(mask, j) = 0 then
            k += 1         
            if bit(piece(i).bb, j) = -1 then 
                r = ( 3 - (k mod 4)) * 100
                c = ( 3 - int(k / 4)) * 100
                line (r, c) - (r + 100, c + 100), piece(i).colour, bf
            end if    
        end if
    next
next 
           
screenunlock() 
   
end sub

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

function getmove( piece() as board) as integer

dim as integer x, y, buttons, res, i ,j, oldx, oldy, r, c, target, z, dum
dim as ulong all,temp 

for i = 0 to 3
    all or= piece(i).bb
next

do 
    res=getmouse(x,y,,buttons)

    if inkey = chr(255,107) then end

    if res = 0 then  
        oldx = x
        oldy = y    
    end if

    res=getmouse(x,y,,buttons)
    if res = 0 then            
        if (buttons and 1) then
            z=1
            dum = point(x, y)
        end if
    end if          
loop while z = 0 

do
    getmouse(x,y,,buttons)
loop while (buttons and 1)

r=x-oldx
c=y-oldy

select case dum
    case 49
        target = 0
    case 55
        target = 1
    case 40
        target = 2
    case 44
        target = 3
    case else
        return 0                        
end select

temp = 0

if r<> 0 or c<> 0 then            
    if abs(r) > abs(c) then
        if r > 0 then temp = (piece(target).bb  shr 1)
        if r < 0 then temp = (piece(target).bb  shl 1)
    end if        

    if abs(r) < abs(c) then
        if c > 0 then temp = (piece(target).bb  shr 6) or (piece(target).bb shl(26))
        if c < 0 then temp = (piece(target).bb  shl 6) or (piece(target).bb shr(26))
    end if 
           
    if (temp and mask) = 0 then
        if ((all xor piece(target).bb) and temp) = 0 then
            piece(target).bb = temp
            return 1
        end if
    else
        return 0    
    end if    
end if

return 0

end function

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

function wincheck(piece() as board) as integer

dim as integer j

if piece(2).bb = 68681728 then
    circle (150,50),25,14, , , , f
    circle (140,45),5,0, , , , f
    circle (160,45),5,0, , , , f
    for j = 1 to 30 step 2
        circle (150,55),15,0,pi , 2 * pi, 0.54 + (j * .005)
    next           
    sleep 2000
    circle (160,45),5,14, , , , f        
    circle (160,45),5,0, pi, 2 * pi, .75, f
    sleep 500
    circle (160,45),5,0, , , , f        

    return 1

end if
    
return 0

end function

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'	 main

display(piece(), move)

do
    while getmove(piece()) = 0
    wend
    move += 1
    display(piece(), move)
    sleep 50
loop while wincheck(piece()) = 0

sleep

Last edited by 3622 on Aug 19, 2020 21:12, edited 1 time in total.
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Simplicity

Post by badidea »

Nice, I did need more than 2 minutes.
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: Simplicity

Post by grindstone »

In principle it works here with WinXP 32, but mostly it takes 2 or 3 attempts of dragging before the piece really moves.
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Simplicity

Post by badidea »

I changed the sleep 50 to sleep 1. Then better response.
xlucas
Posts: 334
Joined: May 09, 2014 21:19
Location: Argentina

Re: Simplicity

Post by xlucas »

Nice game! Reminds me of a physical board game I had as a child called "Trabado". It's this one:
Image
It surely exists outside the Spanish speaking world with a different name.

By the way, I solved Simplicity in over 2 minutes.... maybe over 5. At a point, I started to think it was going to take a lot longer, but it's interesting how you change your mind after making another move. I love this kind of games :)

I am using GNU/Linux 64 bit and did get the difficulty for dragging the pieces, but it does work well.

PS: I found it! The traditional form of this game is called Klotski
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Simplicity

Post by D.J.Peters »

Really nice well done it's fun to play.

Joshy
3622
Posts: 24
Joined: Mar 14, 2015 23:53

Re: Simplicity

Post by 3622 »

Thanks to you all for trying Simplicity and for your replies.

Badidea, I tried changing Sleep to 1, and on my setup, PCLinuxos KDE 5Plasma, it made no noticeable difference but rebooting to same OS
under XFCE there was a definite improvement. However, my mouse setup in XFCE is very sensitive ( the mouse cursor flys around the screen
with barely any mouse movement) so that may be of some significance.

Anyhow, I have made a very small change to the original code and this seems to make the responsiveness better, on my setup at least.

I downloaded a small PDF about 10 years ago which was my inspiration for this. Here is a link to the same info : http://www.mathpuzzle.com/MAA/31-Slidin ... 13_04.html

My best score is 31 moves. I hope this can be bettered.
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: Simplicity

Post by Tourist Trap »

3622 wrote: My best score is 31 moves. I hope this can be bettered.
How damn, 205 moves before I could see the smiling face. Good game anyway :)
3622
Posts: 24
Joined: Mar 14, 2015 23:53

Re: Simplicity

Post by 3622 »

@ Tourist Trap

I admire your perseverance ( and honesty) !
Post Reply