4Balls another sliding block puzzle

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

4Balls another sliding block puzzle

Post by 3622 »

Here's another slider in the same vein as Simplicity.

Just move the 4 coloured round pieces to their respective coloured (home or goal) positions.


To slide a coloured piece : right click and drag.
A coloured piece can only move to into an empty space ( black = empty).
A home or goal square is a valid space to move into if it is empty ie you have moved the round coloured piece
from it and it now shows a black circle.


Inspiration came from this site : https://layton.fandom.com/wiki/Puzzle:Four_Balls

64 Bit only.

Code: Select all


'		64 Bit Only 

'		4Balls.bas			Move each round piece to the area with the same colour

screenres 480, 480, 32

const as ulongint mask = &HFFFB83C3C3C1DFFF
const as double pi = 3.1415926535897932

type board
    bb as ulongint
    colour as integer
end type
   
dim as board piece(12)
dim as integer i, j, move

data &H4000000000000, rgb(215, 40, 40)									' red goal			0
data &H20000, rgb(40, 40, 215)											' blue goal			1
data &H2000, rgb(60, 200, 60)											' green goal		2
data &H400000000000, rgb(215, 215, 40)									' yellow goal		3
data &H4000000000000, rgb(14, 243, 14)									' green circle		4
data &H20000, rgb(243, 243, 14)											' yellow circle		5
data &H2000, rgb(243, 12, 12)											' red circle		6
data &H400000000000, rgb(14, 14, 243)									' blue circle		7
data &HC0000000000, rgb(13, 243, 13)									' green piece		8
data &H300000, rgb(12, 243, 12)											' green piece		9
data &H202000000000, rgb(13, 13, 243)									' blue piece		10
data &H4040000, rgb(12, 12, 243)										' blue piece		11
data &H1818000000, rgb(243, 10, 10)										' red square piece	12

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

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

sub brick(x as integer, y as integer, x1 as integer, y1 as integer)

dim as integer temp, a = 0, b = 20

line (x, y) - (x1, y1),rgb(127, 127, 127) ,bf
line (x, y) - (x1, y1), ,b

while y < y1
    line (x, y) -(x1, y)  
    y += 20
    swap a, b
    temp = x + a   
    while temp < x1
        line (temp, y - 20) - (temp, y)
        temp += 40
    wend   
wend

end sub

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

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

dim as integer i, j, k, c

windowtitle "Move each round piece to its coloured area : " +str(move)

screenlock()

cls

brick(0, 0, 319, 79)
brick(400, 0, 479, 319)
brick(160, 400, 479, 479)
brick(0, 160, 79, 479)

for k = 0 to 12
    c = 54
    for i = 0 to 7
        for j = 0 to 7       
            if bit(piece(k).bb, c) = -1 then
                select case k
                    case 0 to 3
                        line (j * 80, i * 80) - (j * 80 + 79, i * 80 + 79), piece(k).colour, bf
                        circle (j * 80 + 40, i * 80 + 40), 32, 0, , , , f                                     
                    case 4 to 7         
                        circle (j * 80 + 40, i * 80 + 40), 30, piece(k).colour, , , , f                 
                    case 8 to 12
                        line (j * 80, i * 80) - (j * 80 + 79, i * 80 + 79), piece(k).colour, bf
                end select   
            end if    
            c -= 1
        next
    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
dim as uinteger dum
dim as ulongint all,temp 

for i = 4 to 12
    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 rgb(14, 243, 14)
        target = 4
    case rgb(243, 243, 14)
        target = 5
    case rgb(243, 12, 12)
        target = 6
    case rgb(14, 14, 243)
        target = 7
    case rgb(13, 243, 13)
        target = 8
    case rgb(12, 243, 12)
        target = 9
    case rgb(13, 13, 243)
        target = 10
    case rgb(12, 12, 243)
        target = 11
    case rgb(243, 10, 10)
        target = 12                
    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 8) 
        if c < 0 then temp = (piece(target).bb  shl 8) 
    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 i, j, x(3), y(3)

if piece(6).bb = piece(0).bb and piece(7).bb = piece(1).bb and piece(4).bb = piece(2).bb and piece(5).bb = piece(3).bb then
    x(0) = 360 : y(0) = 40
    x(1) = 440 : y(1) = 360
    x(2) = 120 : y(2) = 440
    x(3) = 40 : y(3) = 120

    for i = 0 to 3                
        circle (x(i) - 10, y(i) - 5), 5, rgb(0, 0, 0), , , , f
        circle (x(i) + 10, y(i) - 5), 5, rgb(0, 0, 0), , , , f
    
        for j = 1 to 30 step 2
            circle (x(i), y(i) + 8), 15, rgb(0, 0, 0), pi , 2 * pi, 0.54 + (j * .005)
        next           
    next
    
    sleep 2000
    
    for i = 0 to 3
        circle (x(i) + 10, y(i) - 5), 5 , point(x(i), y(i)), , , , f        
        circle (x(i) + 10, y(i) - 5), 5, rgb(0, 0, 0), pi, 2 * pi, .75, f
    next
        
    sleep 500
    
    for i = 0 to 3    
        circle (x(i) + 10, y(i) - 5), 5, rgb(0, 0, 0), , , , f        
    next
    
    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 Oct 23, 2020 21:52, edited 2 times in total.
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: 4Balls another sliding block puzzle

Post by Tourist Trap »

I don't understand how you make anything move here. I made click and keyboard inputs, nothing moves. Can be kind and give a hint?
fxm
Moderator
Posts: 12131
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: 4Balls another sliding block puzzle

Post by fxm »

@3622
You should list the valid movements !

But by groping, we find:
The different pieces (rectangles, square, disks) can slide to an empty space (in black), including to a square with its black disk if it has been freed from its colored disk.
paul doe
Moderator
Posts: 1735
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: 4Balls another sliding block puzzle

Post by paul doe »

3622 wrote:Here's another slider in the same vein as Simplicity.
Nice! I solved it in 46 moves =D
3622
Posts: 24
Joined: Mar 14, 2015 23:53

Re: 4Balls another sliding block puzzle

Post by 3622 »

My apologies Tourist Trap.

Right click on coloured piece and drag to move. Black indicates an empty space. You can only move into an empty space.

Similar to Simplicity puzzle.
3622
Posts: 24
Joined: Mar 14, 2015 23:53

Re: 4Balls another sliding block puzzle

Post by 3622 »

@fxm
Sorry !

I have now edited the original post.


@paul doe
Wow ! I'm impressed.

My first attempt resulted in defeat after many, many hundreds of moves.
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: 4Balls another sliding block puzzle

Post by Tourist Trap »

3622 wrote: Right click on coloured piece and drag to move. Black indicates an empty space. You can only move into an empty space.
Thank you. I did it in 199 moves. To place the last ball, we must leave the opposite ball out of its hole. It took me too much moves to figure it out. Nice game again :)
Post Reply