B4J Question Challenge. Human Intelligence.

LucaMs

Expert
Licensed User
Longtime User
I like this game:
https://games.washingtonpost.com/games/trizzle-halloween

1748166867379.png


and I would love to have a SW like this for PC, without connection, off line.
Of course, it would be great if it was also an app, so a B4XPages project.

I recently asked 3 AIs to solve a couple of problems:

1 - rows and columns scroll; the images at the ends must gradually re-enter from the opposite side;
2 - the SW must understand if I am scrolling a row or a column.

Well, none of the 3 AIs produced working stuff.

The challenge: will any of you be able to solve this thing (especially point 1)?
 
Solution
Try this quickly thrown together example. Just basic (uses button not mouse to move). Lots needs to be added but shows smooth scroll of image.

AnandGupta

Expert
Licensed User
Longtime User
I saw the page source, I understand it is some java script.
If one knows java script or whatever language it is, he/she can take it out and then give to A.I. to convert to say, java/python.
A.I. may do the job better then.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I saw the page source, I understand it is some java script.
If one knows java script or whatever language it is, he/she can take it out and then give to A.I. to convert to say, java/python.
A.I. may do the job better then.
I don't even know where that JS source is.
Anyway, it would be good if our intelligence (?) could "invent" the solution.
 
Upvote 0

PaulMeuris

Well-Known Member
Licensed User
The demo solves your 2 problems but there is no animation when you drag a panel up, down, left or right.
The end result is the same as in the game.
Maybe you should try again with your 3 AI's...
And if you make an exact copy of the game then you might have a problem with the copyright.
For me it was a nice exercise...
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Try this quickly thrown together example. Just basic (uses button not mouse to move). Lots needs to be added but shows smooth scroll of image.
 

Attachments

  • Project.zip
    12.4 KB · Views: 106
Upvote 0
Solution

Daestrum

Expert
Licensed User
Longtime User
These two routines might be useful in addition to the example above (allows for mouse to move the image)

B4X:
Sub imageview1_MousePressed (EventData As MouseEvent)
    ' mousex and y are global ints
    mousex = EventData.X
    mousey = EventData.Y
    'Log("X: " & mousex & " Y: " & mousey )
End Sub

Sub imageview1_MouseDragged (EventData As MouseEvent)
    'Log(EventData.X & ", " & EventData.Y)
    'Log("Distance X = " & (EventData.X - mousex).As(Int))
    'Log("Distance Y = " & (EventData.Y - mousey).As(Int))
    Dim img As Image = can.Snapshot
    'the 100 offset in following line is because there is 1 tile (100x100) before first shown
    rectangle = rectangle.InitializeNewInstance("javafx.geometry.Rectangle2D",Array(100 + (mousex - EventData.x),0.0,500.0,100.0))
    ImageView1.SetImage(img)
    ImageView1.As(JavaObject).RunMethod("setViewport",Array(rectangle))
End Sub
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Very good, @Daestrum, great solution.

I have to try to change some things, but the base is really good:

- When scrolling the second time, the images do not stay (start) in the correct positions.
java_IDaiNNx2kX.gif


- Transparent background of ImageViews

I also need to make sure that when I stop scrolling the row/column, it will be positioned so that the images are aligned.

The "problem" is that it is not crossplatform; I will try to fix this.




Note that I ran it yesterday and the compiler reported an error; I didn't want to find out why, I did it now and it's very simple, you have the following line:
B4X:
#JavaCompilerPath: 23, D:\jdk-23\bin\javac.exe
which obviously is not compatible with my environment 😁



P.S. I forgot one very important missing thing: how would it behave in a 5x5 grid?
 
Last edited:
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Working on it Luca,The reason it jumps is I didnt add logic to update the array after the move, so each move is from original order.
I have it snapping to correct position on scroll now. the test app was just a quicky sample, the proper one will have 5 x 5 grid but the array holding the tiles will be 13 x 13, to allow for a full swipe to left or right (or up and down). Just chopping up code to remove redundant copies. It wont be 100% but the idea will get you started.

This is the snap code (its untidy as I just got it working - lots of duplicated code)
B4X:
Sub horiz_MouseReleased (EventData As MouseEvent)
    Log("x: " & EventData.X)
    Log("y: " & EventData.Y)
    If Sender.As(ImageView).Tag.As(Int) = 0 Then
        Dim img As Image = can.Snapshot
        'the 100 offset in following line is because there is 1 tile (100x100) before first shown
        Dim dist As Int = Round((mousex - EventData.X) / 100) ' Ensure whole tile snap
        Dim offset As Double = dist * 100 + 100.0 ' Maintain tile alignment
        rectangle = rectangle.InitializeNewInstance("javafx.geometry.Rectangle2D",Array(offset,0.0,500.0,100.0))
        ImageView1.SetImage(img)
        ImageView1.As(JavaObject).RunMethod("setViewport",Array(rectangle))
    else if Sender.As(ImageView).Tag.As(Int) = 1 Then
        Dim img As Image = can1.Snapshot
        'the 100 offset in following line is because there is 1 tile (100x100) before first shown
        Dim dist As Int = Round((mousex - EventData.X) / 100) ' Ensure whole tile snap
        Dim offset As Double = dist * 100 + 100.0 ' Maintain tile alignment
        rectangle = rectangle.InitializeNewInstance("javafx.geometry.Rectangle2D",Array(offset,0.0,500.0,100.0))
        ImageView2.SetImage(img)
        ImageView2.As(JavaObject).RunMethod("setViewport",Array(rectangle))
    End If
End Sub
 
Last edited:
Upvote 0
Top