This site requires JavaScript, please enable it in your browser!
Greenfoot back
magentaink
magentaink wrote ...

2024/11/29

Checking the Solution for a Picross Game

magentaink magentaink

2024/11/29

#
Hi! I'm pretty new to Greenfoot and Java,, at the moment I'm making a picross game. What would be the best way for me to check the solution to the puzzles against what the user enters? I was thinkin boolean arrays?
danpost danpost

2024/11/30

#
magentaink wrote...
Hi! I'm pretty new to Greenfoot and Java,, at the moment I'm making a picross game. What would be the best way for me to check the solution to the puzzles against what the user enters? I was thinkin boolean arrays?
Is your program going to be checking that each entry is correct or not, or just checking the end result of the solve? The end result check should be simple enough -- in that all the clues must be satisfied (just check that). If checking along the way, then the solution should be stored in memory to see that each entry in correct (checking entry with correct value). Obviously, if the solution is stored, then, either way, you can check cell by cell.
magentaink magentaink

2024/12/12

#
I'm aiming to have it so that every time a square is clicked, it checks to see if the current state of the puzzle aligns with the solution. I currently have it so that when the image for a square is filled, its state is true and if the image is unfilled, its state is false but am struggling to implement a good way to store and check it against the solution.
danpost danpost

2024/12/13

#
magentaink wrote...
I'm aiming to have it so that every time a square is clicked, it checks to see if the current state of the puzzle aligns with the solution. I currently have it so that when the image for a square is filled, its state is true and if the image is unfilled, its state is false but am struggling to implement a good way to store and check it against the solution.
An array of ones and zeros would be sufficient:
public int[][] grid = new int[HEIGHT][WIDTH];
Just need to keep it updated as things changes
magentaink magentaink

2024/12/17

#
How would I implement this? I have each square as an individual object.
danpost danpost

2024/12/17

#
magentaink wrote...
How would I implement this? I have each square as an individual object.
Maybe I should ask how the solution is stored. Plus, how the clues are given.
magentaink magentaink

yesterday

#
The clues are just images on the side of the grid. At the moment I have the solution in the square class like this:
 private void solutionOne()
{
gridone|0][0]=0:gridone[1][0]=0:gridone[21[0]=0:gridone[3][0]=0:gridone[41[0]=0
gridone[0][1]=1;gridone[1][1]=0;grid0ne[2][1]=0;gridone[3][1]=0;gridone[4][1]=1;
gridone[0][2]=0;gridone[1][2]=0;gridone[2][2]=0;gridone[3][2]=0;gridone[4][2]=0;
gridone[0][3]=1;gridone[1][3]=0;gridOne[2][3]=0;gridone[3][3]=0;gridone[4][3]=1;
gridone[0][4]=1;gridone[1][4]=1;gridOne[2][4]=1;gridone[3][4]=1;gridone[4][4]=1; 
} 
Thanks :'] edit: just realised there was a typo
danpost danpost

yesterday

#
magentaink wrote...
The clues are just images on the side of the grid. At the moment I have the solution in the square class like this: << Code Omitted >>
A better way to assign the entries is like this:
gridone = new int[][] {
    { 0, 1, 0, 1, 1 },
    { 0, 0, 0, 0, 1 },
    { 0, 0, 0, 0, 1 },
    { 0, 0, 0, 0, 1 },
    { 0, 1, 0, 1, 1 }
};
Furthermore, it should not be in your square class -- it should be in your game world class. Also, as above, you should be able to visually see the solution within the entries. If the rows and columns are mixed up and the visual looks tipped on its side, then switch the rows and columns. That is, use the following to assign the entire array in one statementrr:
gridone = new int[][] {
    { 0, 0, 0, 0, 0 },
    { 1, 0, 0, 0, 1 },
    { 0, 0, 0, 0, 0 },
    { 1, 0, 0, 0, 1 },
    { 1, 1, 0, 1, 1 },
};
(I always have the entries as such:
int [ colNumber ] [ rowNumber ]
That is only in code block because brackets are being used here (which will not work well in standard text. Anyway, it is easier to check that you entered the solution properly when everything is aligned. As far as the clues -- you might want to represent them among your data as values. That way, your world can accept (as parameters) as two 2-D arrays (a 3-D array which contains two 2-D arrays for (1) row clues and (2) column clues. Then you can write an algorithm that compares the current solve state with what the clues should produce to verify correctness of the solve. You must already have a way to determine whether a square is filled or not -- otherwise, you would not be able to change its state. So, you should be able to check each squares state against the solution.
You need to login to post a reply.