GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 24-Jul-2008, 22:57
engotpacs engotpacs is offline
New Member
 
Join Date: Jul 2008
Posts: 2
engotpacs is on a distinguished road
Unhappy

Can somebody convert this JAVA code to PHP?


hey... can anyone of you here knows how to convert this java source code to php? I really need it....

and oh...

does anyone of you here have a source code on "knight's tour"???
it is where the knight in a chessboard tours around the chessboard without
repeating its steps...
if you'd be so kind... please email me the source code...
i need it in class...

engotpacs@gmail.com


JAVA Code:
import java.awt.*;//for class Point

public class AccessibilityMatrix
{
	static int iCells[][];

	public static void init()
	{
		iCells = new int[8][8];

		iCells[0][0] = 2;
		iCells[0][1] = 3;
		iCells[0][2] = 4;
		iCells[0][3] = 4;
		iCells[0][4] = 4;
		iCells[0][5] = 4;
		iCells[0][6] = 3;
		iCells[0][7] = 2;

		iCells[1][0] = 3;
		iCells[1][1] = 4;
		iCells[1][2] = 6;
		iCells[1][3] = 6;
		iCells[1][4] = 6;
		iCells[1][5] = 6;
		iCells[1][6] = 4;
		iCells[1][7] = 3;

		iCells[2][0] = 4;
		iCells[2][1] = 6;
		iCells[2][2] = 8;
		iCells[2][3] = 8;
		iCells[2][4] = 8;
		iCells[2][5] = 8;
		iCells[2][6] = 6;
		iCells[2][7] = 4;

		iCells[3][0] = 4;
		iCells[3][1] = 6;
		iCells[3][2] = 8;
		iCells[3][3] = 8;
		iCells[3][4] = 8;
		iCells[3][5] = 8;
		iCells[3][6] = 6;
		iCells[3][7] = 4;

		iCells[4][0] = 4;
		iCells[4][1] = 6;
		iCells[4][2] = 8;
		iCells[4][3] = 8;
		iCells[4][4] = 8;
		iCells[4][5] = 8;
		iCells[4][6] = 6;
		iCells[4][7] = 4;

		iCells[5][0] = 4;
		iCells[5][1] = 6;
		iCells[5][2] = 8;
		iCells[5][3] = 8;
		iCells[5][4] = 8;
		iCells[5][5] = 8;
		iCells[5][6] = 6;
		iCells[5][7] = 4;

		iCells[6][0] = 3;
		iCells[6][1] = 4;
		iCells[6][2] = 6;
		iCells[6][3] = 6;
		iCells[6][4] = 6;
		iCells[6][5] = 6;
		iCells[6][6] = 4;
		iCells[6][7] = 3;

		iCells[7][0] = 2;
		iCells[7][1] = 3;
		iCells[7][2] = 4;
		iCells[7][3] = 4;
		iCells[7][4] = 4;
		iCells[7][5] = 4;
		iCells[7][6] = 3;
		iCells[7][7] = 2;
	}

	public static int getAccessibility( Point ptPos )
	{
		return iCells[ptPos.x][ptPos.y];
	}

	public static int getAptMove( int[] iMoves, Point ptPos )
	{
		int iAptMove;
		int i;
		int iCurrentAccessibility;
		Point ptTemp = new Point( ptPos );

		iAptMove = iMoves[0];
		ptTemp.x += KnightMoves.iHorizontalMove[ iMoves[0] ];
		ptTemp.y += KnightMoves.iVerticalMove[ iMoves[0] ];
		iCurrentAccessibility = getAccessibility( ptTemp );

		for( i = 1 ; ( i < 8 ) && ( iMoves[i] != -1 ) ; ++i )
		{
			ptTemp = new Point( ptPos );
			ptTemp.x += KnightMoves.iHorizontalMove[ iMoves[i] ];
			ptTemp.y += KnightMoves.iVerticalMove[ iMoves[i] ];
			int iNewAccessibility = getAccessibility( ptTemp );

			if( iNewAccessibility < iCurrentAccessibility )
			{
				iCurrentAccessibility = iNewAccessibility;
				iAptMove = iMoves[i];
			}
			else if( iNewAccessibility == iCurrentAccessibility )
			{
				int iNewAcc = getLeastAccessibility( ptTemp );
				
				ptTemp = new Point( ptPos );
				ptTemp.x += KnightMoves.iHorizontalMove[ iAptMove ];
				ptTemp.y += KnightMoves.iVerticalMove[ iAptMove ];
				
				int iOldAcc = getLeastAccessibility( ptTemp );
				
				if( iNewAcc < iOldAcc )
				{
					iCurrentAccessibility = iNewAccessibility;
					iAptMove = iMoves[i];
				}
			}
		}

		return iAptMove;
	}
	
	private static int getLeastAccessibility( Point ptPos )
	{
		int iAccessibilities[] = getAccessibilities( ptPos );
		int iLeastAccessibility;
		int iCurrentAccessibility, i;
		
		iLeastAccessibility = iAccessibilities[0];
		
		for( i = 1 ; (i < iAccessibilities.length) ; ++i )
		{
			iCurrentAccessibility = iAccessibilities[i];
			
			if( iCurrentAccessibility < iLeastAccessibility )
				iLeastAccessibility = iCurrentAccessibility;
		}
		
		return iLeastAccessibility;
	}
	
	private static int[] getAccessibilities( Point ptPos )
	{
		int iMoves[] = KnightMoves.enumerateMoves( ptPos );
		int iAccessibilities[] = new int[8];
		
		for( int i = 0 ; (i < iAccessibilities.length) && 
						(iMoves[i] != -1) ; ++i )
		{
			Point ptTemp = new Point( ptPos );
			ptTemp.x += KnightMoves.iHorizontalMove[ iMoves[i] ];
			ptTemp.y += KnightMoves.iVerticalMove[ iMoves[i] ];
			
			iAccessibilities[i] = getAccessibility( ptTemp );
		}
		
		return iAccessibilities;
	}
}


and one more thing...

iHorizontalMove = new int[8];

how do you create an integer array in php?
Last edited by admin : 26-Jul-2008 at 03:30. Reason: Please insert your example Java codes between [JAVA] and [/JAVA] tags
  #2  
Old 24-Jul-2008, 22:58
engotpacs engotpacs is offline
New Member
 
Join Date: Jul 2008
Posts: 2
engotpacs is on a distinguished road

Re: can somebody convert this java code to php???


correction.... its "knight's tour" source code on php format...
  #3  
Old 27-Jul-2008, 20:52
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Can somebody convert this JAVA code to PHP?


Quote:
Originally Posted by engotpacs
hey... can anyone of you here knows how to convert this java source code to php? I really need it....
if you'd be so kind... please email me the source code...
i need it in class...
I think I can claim that many posters here won't do other people's homework. (although there are a stray few that will, but it is usually dependent on how much effort you've done yourself)

However, that being said, we CAN assist in helping with the conversion for specific points (or areas) that are giving the most trouble, OR if that isn't good enough, there is an nifty website here that can potentially do everything for you completely.

Quote:
Originally Posted by engotpacs
iHorizontalMove = new int[8];

how do you create an integer array in php?
Based on the Java code that you posted, that would NOT be difficult to convert into PHP form.

Know that PHP does not require an explicit type for variable(s), as PHP assigns the type based on the value assigned, so a basic int array in PHP could look something like this:
PHP Code:

$iHorizontalMove = array( 2, 3, 4, 4, 4, 4, 3, 4 ); 


More about PHP's arrays can be found here.
More about PHP's type handling can be found here.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C code to Java bengt23648 Java Forum 2 09-Sep-2007 06:33
To post messages / click Buttons of a Java Jar App using code Jun0 C Programming Language 1 06-Jan-2007 15:44
To post messages / click Buttons of a Java Jar App using code Jun0 Java Forum 0 06-Jan-2007 12:14
Convert sentence to morse code earachefl C++ Forum 8 03-May-2006 08:39

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 13:25.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.