Results 1 to 6 of 6
  1. #1
    alsanober is offline Member
    Join Date
    Mar 2017
    Posts
    2
    Rep Power
    0

    Default Need help with Java code

    Hello Guys,

    I am relatively inexperience in Java and trying to enhance my understanding. I did a Uni project few years back in VB 6. i thought about converting that project and see how far i can get with it. I use Jump2Java to convert the project. I am stuck with it and was hoping to get help from Gurus here

    so the it is a game called Gomoku where a player play again computer and try to get 5 cross in a row. just like tic tac toe but on bigger grid. 5 in a row could be vertical, horizontal or diagonal. i am issue in following method where a computer tries to make a move

    Syntax Error in lines 148, 151, 182, 185 and 220.

    Java Code:
    private void aIsTurn()
    	{
    		int redim_Os[][] = null;
    		int redim_Xs[][] = null;
    		int arrayIndex0 = 0;
    		int omatrix = 0; int xmatrix = 0; int x = 0; int y = 0;
    		int i = 0; int j = 0; int index = 0; int tmp = 0;
    		int xs[][] = null; int os[][] = null; int newI = 0;
    		final int Cx = 0;
    		final int Cy = 1;
    		final int max = 2;
    		final int bits = 3;
    		final int bmask = 4;
    		final double HighBit = Math.pow(2, 24);
    		int bitGroup[] = new int[5];
    		
    		
    		os = new int[5][1];
    		for(arrayIndex0 = 0; arrayIndex0 <= 4; arrayIndex0++)
    			os[arrayIndex0] = new int[1];
    		
    		//Computers advantages are saved in this array
    		xs = new int[5][1];
    		for(arrayIndex0 = 0; arrayIndex0 <= 4; arrayIndex0++)
    			xs[arrayIndex0] = new int[1];
    		
    		//Players advantages are saved in this array
    		
    		
    		
    		
    		for(x = 0; x <= 14; x++)
    		{
    			//Scan 225 5X5 Matrices for any of the 12 winning combos
    			for(y = 0; y <= 14; y++)
    			{
    				//
    				
    				//build matrices
    				omatrix = 0;
    				xmatrix = 0;
    				for(i = 0; i <= 4; i++)
    				{
    					//convert Matrices to serial binary stream
    					for(j = 0; j <= 4; j++)
    					{
    						//
    						index = (short)((y + j) * 19 + (x + i));
    						//Translate Cartesian coordinates to countinous array indexing
    						
    						omatrix = (int)(omatrix * 2 + CInteraction.iIf(label1[index].getText().equals("O"), new CVariant(1), new CVariant(0)).toDouble());
    						//Shift binary stream to the left and set bits for Os
    						xmatrix = (int)(xmatrix * 2 + CInteraction.iIf(label1[index].getText().equals("X"), new CVariant(1), new CVariant(0)).toDouble());
    						//Shift binary stream to the left and set bits for Os
    					}
    				}
    				//End of build matrices
    				
    				// check for winnable combos - compare matrices with winning 12 masks (12*225=2700 passes)
    				for(i = 0; i <= 11; i++)
    				{
    					//the following logic to all combos
    					//if a winnable combination is occupied with both Xs and Os then it is not a threat to the computer
    					//if a winnable combination is occupied with both Xs and Os then it is not winnable by the computer
    					//if a winnable combo is occupied only by the player it's is considered threat and rated by number of Xs
    					//if a winnable combo is occupied only by the computer it's is considered winnable and rated by number of Os
    					//friendly check
    					if( (omatrix & mask[i]) > 0 && (xmatrix & mask[i]) == 0 )//Check for Winnable combo Os with no Xs
    					{
    						newI = (short)( + 1);
    						//find new array index
    						redim_Os = new int[5][newI + 1];
    						if( os != null )
    						{
    							for(arrayIndex0 = 0; arrayIndex0 <= 5; arrayIndex0++)
    							{
    								redim_Os[arrayIndex0] = new int[newI + 1];
    								System.arraycopy(os[arrayIndex0], 0, redim_Os[arrayIndex0], 0, Math.min(os[arrayIndex0].length, redim_Os[arrayIndex0].length));
    							}
    						}
    						os = redim_Os;
    						//add to array
    						os[Cx][newI] = x;
    						os[Cy][newI] = y;
    						//store matrix coords
    						os[bits][newI] = omatrix & mask[i] ^ mask[i];
    						//check for open positions by inverting bits
    						os[bmask][newI] = mask[i];
    						//store mask bits to idnetify combo
    						j = os[bits][newI];
    						//get temporary clone of bits
    						os[max][newI] = 0;
    						//set Winnable  level to zero
    						while( j > 0 )
    						{
    							//count playable open bits equals level
    							os[max][newI] = os[max][newI] + (j & 1);
    							//1 bit would mean that combo wins the game.
    							j = (int)(long)(j / (float)2);
    						}
    					}
    					//unfriendly check
    					if( (xmatrix & mask[i]) > 0 && (omatrix & mask[i]) == 0 )//Check for Threat combo Xs with no Os
    					{
    						newI = (short)( + 1);
    						//find new array index
    						redim_Xs = new int[5][newI + 1];
    						if( xs != null )
    						{
    							for(arrayIndex0 = 0; arrayIndex0 <= 5; arrayIndex0++)
    							{
    								redim_Xs[arrayIndex0] = new int[newI + 1];
    								System.arraycopy(xs[arrayIndex0], 0, redim_Xs[arrayIndex0], 0, Math.min(xs[arrayIndex0].length, redim_Xs[arrayIndex0].length));
    							}
    						}
    						xs = redim_Xs;
    						//add to array
    						xs[Cx][newI] = x;
    						xs[Cy][newI] = y;
    						//store matrix coords
    						xs[bits][newI] = xmatrix & mask[i] ^ mask[i];
    						//check for open positions by inverting bits
    						xs[bmask][newI] = mask[i];
    						//store mask bits to identify combo
    						j = xs[bits][newI];
    						//get temporary clone of bits
    						xs[max][newI] = 0;
    						//set threat level to zero
    						while( j > 0 )
    						{
    							//count playable open bits equals level
    							xs[max][newI] = xs[max][newI] + (j & 1);
    							//1 bit would mean that combo wins the game.
    							
    							j = (int)(long)(j / (float)2);
    						}
    					}
    				}
    			}
    		}
    		
    		//End of Scan (225 5X5 Matrices for any of the 12 winning combos
    		
    		
    		//sort X's
    		//gnome sort sets the order of the threats from highes to lowest - from(google gnome sort)
    		
    		i = (short);
    		while( i < ( + 1) )
    		{
    			if( i ==  )
    			{
    				i = (short)(i + 1);
    			}
    			else if( xs[max][i - 1] <= xs[max][i] )
    			{
    				i = (short)(i + 1);
    			}
    			else
    			{
    				tmp = xs[max][i];
    				xs[max][i] = xs[max][i - 1];
    				xs[max][i - 1] = tmp;
    				tmp = xs[Cx][i];
    				xs[Cx][i] = xs[Cx][i - 1];
    				xs[Cx][i - 1] = tmp;
    				tmp = xs[Cy][i];
    				xs[Cy][i] = xs[Cy][i - 1];
    				xs[Cy][i - 1] = tmp;
    				tmp = xs[bits][i];
    				xs[bits][i] = xs[bits][i - 1];
    				xs[bits][i - 1] = tmp;
    				tmp = xs[bmask][i];
    				xs[bmask][i] = xs[bmask][i - 1];
    				xs[bmask][i - 1] = tmp;
    				i = (short)(i - 1);
    			}
    		}
    		
    		//sort Os
    		//gnome sort sets the order of the winnables from highest to lowest(from google)
    		i = (short);
    		while( i < ( + 1) )
    		{
    			if( i ==  )
    			{
    				i = (short)(i + 1);
    			}
    			else if( os[max][i - 1] <= os[max][i] )
    			{
    				i = (short)(i + 1);
    			}
    			else
    			{
    				tmp = os[max][i];
    				os[max][i] = os[max][i - 1];
    				os[max][i - 1] = tmp;
    				tmp = os[Cx][i];
    				os[Cx][i] = os[Cx][i - 1];
    				os[Cx][i - 1] = tmp;
    				tmp = os[Cy][i];
    				os[Cy][i] = os[Cy][i - 1];
    				os[Cy][i - 1] = tmp;
    				tmp = os[bits][i];
    				os[bits][i] = os[bits][i - 1];
    				os[bits][i - 1] = tmp;
    				tmp = os[bmask][i];
    				os[bmask][i] = os[bmask][i - 1];
    				os[bmask][i - 1] = tmp;
    				i = (short)(i - 1);
    			}
    		}
    		
    		//set up necessary variables
    		x = 0;
    		i = 0;
    		tmp = (int)HighBit;
    		
    		// If first move go for a block
    		if(  == 0 )
    		{
    			
    		}
    		
    		
    		//we Previously sorted moves by most winnable (least moves to win) to least winnable
    		//If defense has advantage choose defense
    		if( os[max][1] > xs[max][1] )
    		{
    			
    		}
    		
    		//construct bit image
    		//convert 5X5 array to 1X5 for analysis
    		while( (tmp != 0) )
    		{
    			if( (os[bmask][1] & tmp) > 0 )
    			{
    				if( (os[bits][1] & tmp) > 0 )
    				{
    					bitGroup[i] = x + 1;
    					//
    					i = (short)(i + 1);
    				}
    				else
    				{
    					bitGroup[i] = -(x + 1);
    					i = (short)(i + 1);
    				}
    			}
    			x = (short)(x + 1);
    			tmp = (int)(long)(tmp / (float)2);
    		}
    		//place new piece adjacent to existing
    		//check for adjacency
    		for(i = 0; i <= 3; i++)
    		{
    			if( (CMath.Sgn(bitGroup[i]) != CMath.Sgn(bitGroup[i + 1])) )
    			{
    				if( bitGroup[i] > 0 )
    				{
    					x = (short)(bitGroup[i] - 1);
    				}
    				else
    				{
    					x = (short)(bitGroup[i + 1] - 1);
    				}
    			}
    		}
    		//convert move to cartesian coordinat
    		y = (short)((os[Cy][1] + (x % 5)) * 19 + (os[Cx][1] + (long)(x / (float)5)));
    		
    		//click it
    		label1Click(y);
    	}

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Need help with Java code

    Syntax Error in
    Please copy the full text of the error message and paste it here. It has important info about the error.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    alsanober is offline Member
    Join Date
    Mar 2017
    Posts
    2
    Rep Power
    0

    Default Re: Need help with Java code

    Quote Originally Posted by Norm View Post
    Please copy the full text of the error message and paste it here. It has important info about the error.
    on line 148 i get Syntax error on token ")", Expression expected after this token

    151 Syntax error on token "==", Expression expected after this token

    Line 182 error: Syntax error on token ")", Expression expected after this token

    Line 185 error:
    Syntax error on token "==", Expression expected after this token

    Line 220: Syntax error on token "==", delete this token

    Thank you

  4. #4
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,342
    Rep Power
    12

    Default Re: Need help with Java code

    Quote Originally Posted by alsanober View Post
    on line 148 i get Syntax error on token ")", Expression expected after this token
    Let's start at the beginning. Are you using (short) to attempt to cast variables to the "short" data type? You pretty much never need/want to do this in java. Regular ints are fine, no need to cast unless switching between integer and real number types (like int and double). I would start by removing all the short casts, and try again.

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Need help with Java code

    The error messages do not show the source line which we need to see to recommend a fix. Often times the line numbers in the posted code do not match those in the error messages, so it's better if the source line is included.

    The message should show the source with a ^ under the location of the error.
    Here is a sample from the javac compiler:
    Java Code:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Need help with Java code

    Well, there are errors at those line numbers.

    Java Code:
    i = (short);  // several of these and it is incorrect.  You need to assign a value to i, not a type
    if (i == ); // several of these.  You need to compare two values (e.g. i == 5)
    And line 183

    Java Code:
    while( i < ( + 1) ) // This is syntactically correct, even though it looks
                           // like it could be missing something.  It is the same
                           // as
       while (i < 1)
    And once you learn Java, get away from all those arrays. You might be better off declaring some classes over
    2-d arrays.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 16
    Last Post: 01-31-2012, 08:36 PM
  2. Translate Vb.net code into Java code
    By Radu in forum New To Java
    Replies: 5
    Last Post: 04-12-2011, 09:27 AM
  3. Replies: 0
    Last Post: 02-21-2011, 11:50 AM
  4. Convert java code to midlet code
    By coldvoice05 in forum New To Java
    Replies: 1
    Last Post: 08-12-2009, 11:14 AM
  5. Convert java code to midlet code
    By coldvoice05 in forum Advanced Java
    Replies: 1
    Last Post: 08-09-2009, 01:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •