So, our story starts in a castle far far away, named Hogwarts. Oh wait, that's the wrong site
Yeah so uh, let's try again . Our story starts in July, 2010, when the Interguild Olympics started. The Interguild Olympics (or in short, IO) is a big tournament consisting of a set of competitions here in the Interguild, which is held annually. This year, the IO is divided to weeks - every week, new competitions are announced.
In Week One, one of the competitions was the Pentathlon. In this competition, each participant had to make a level in a new game - meaning, for the first time.
Until then, our game Gravity Grid wasn't quite a popular game on the site. This game is really easy to understand and use, but since the only controls are three rotation options, it's not easy to make a decent level in it, not to mention an enjoyable one. So people started making levels for this game. And I was one of those - or at least, almost. I *wanted* to be, since it can also qualify for the Math Olympiad, one of the other competitions that week.
So, as a cool person , I thought to myself: "Wait a mo. Why would *I* have to think out these levels? The amount of vailable positions is finite.. Why shouldn't I let the computer do that?"
So I opened my BlueJ, and...started thinking. :hmm
And then, voila! I knew just what to do . So I started writing! And writing...and writing...and writing......
And I finished. So I was all full of myself and stuff, so I wanted to check how it's doing. For those who know and might be interested, this:
Spoiler:
import java.util.*;
public class Main
{
public static void activateGrav(int[][] a)
{
int check=0;
for(int L=1;L<10;L++)
{
for(int j=0;j<10;j++)
{
if(a[L-1][j]==0 && a[L][j]!=0)
{
a[L-1][j]=a[L][j];
a[L][j]=0;
check=1;
if(check==0)
{
erase(a);
else activateGrav(a);
//// In a given situation, activates Gravity, and erases erasables.
//// Stops when no changes are made.
public static void erase(int[][] a)
{
int check=0;
for(int L=0;L<10;L++)
{
for(int j=0;j<10;j++)
{
if(a[L+1][j]==a[L][j])
{
if(a[L+2][j]==a[L][j])
{
check=1;
a[L+2][j]=0;
a[L+1][j]=0;
a[L][j]=0;
//// Checks all trios available to the RIGHT and UP, starting from the buttom left.
//// Works together with activateGrav.
static Scanner scan=new Scanner(System.in);
public static int[][] activate()
{
System.out.println("Insert state of board. left to right, buttom to top");
int[][] Arr=new int[12][12];
for(int L=10;L<12;L++){for(int j=0;j<12;j++){Arr[L][j]=0;
for(int L=0;L<12;L++){for(int j=10;j<12;j++){Arr[L][j]=0;
///These two lines insert 0's in the top and rightmost 2 culumns and rows.
//// Receives the array, one tile at a time, step by step.
public static void RotateCW(int[][] a)
{
int[][] b=new int[12][12];
for(int L=0;L<10;L++)
{
for(int j=0;j<10;j++)
{
b[L][j]=a[9-j][L];
activateGrav(b);
//// Self expanatory...
public static void RotateCCW(int[][] a)
{
int[][] b=new int[12][12];
for(int L=0;L<10;L++)
{
for(int j=0;j<10;j++)
{
b[L][j]=a[j][9-L];
activateGrav(b);
//// Self expanatory...
public static void flip(int[][] a)
{
int[][] b=new int[12][12];
for(int L=0;L<10;L++)
{
for(int j=0;j<10;j++)
{
b[L][j]=a[L][9-j];
activateGrav(b);
//// Self expanatory...
public static boolean isWinning(int[][] a)
{
for(int L=0;L<10;L++)
{
for(int j=0;j<10;j++)
{
if (a[L][j]!=0)
return false;
return true;
//// Checks if the board is in a winning position.
public static boolean isWinable()
{
System.out.println("Insert maximal amounf of moves needed to win");
int x=scan.nextInt();
int[][] a=new int[12][12];
a=activate();
return checkWin(x,a);
//// Checks if you can win in x moves.
public static boolean checkWin(int x,int[][] a)
{
if(x==0)
{
return isWinning(a);
However, as you might have guessed, when I tested it on one of the main game levels, it failed miserably >_<
...
then I noticed how I messed up the grid's size - I thought it was 10x10 when it's really 9x9. Oh well. So I'll fix it, and it'll be ready.
~~~~~~
How to use:
Create a new class; start the method isWinable() and follow instructions, so that when you enter the grid's situation, an empty place is a 0, and any other color is a number, when same colors are same numbers of course.
This, however, will only tell you if it's possible
In order to make it tell you how to solve a level, just make sure it's possible, and then insert the grid after a rotation with -1 in moves left, again and again, following the True path till you're done
~~~~~~ Remember!
That the code up there is still wrong! And that I was too lazy to fix it so you do it!...
Wherever there's a number(which isn't a 0 or a 1), just decrease it by one, I think.
I edited that with another point. I don't know if you accounted for the tile that doesn't get removed from the grid.
That said, I'm not really sure what you were trying to accomplish with this program. Are you trying to make GG levels? Solve them? (Easily brute-forced with recursion). What?
Well, yes, I ignored these completely; I forgot about them. but it shouldn't be hard to do at all, just adding an OR at the isWinning, an if in the erase, and...well that's it, I think.
at first, I was trying to create a program such that I give it a situation and it gives me the fastest solution. it shouldn't be hard at all, but I have a test in the university next Thursday and I don't wanna start thinking. with a program like that, using Prolog you can pull out the starting position that requires the most moves to be beaten. that was my goal.
Um. I don't get 95% of this guide and the other 5% is nonsensical/irrational/does not make any sense at all. All I get is that it's about Gravity Grid.