• 11-22-2008, 10:33 PM
TrungTran
Hi
i'm trying to write Pentago game for my AI class and i got stuck at this, can anyone help me plz :

here is the part of the code:

public class rotate {

public static int[][] matrixrotateLeft(int[][] board, int gameBlock)
{
int[][] rotLeft = board;

int rowOffset = ((gameBlock-1)/2)*3 ;
int colOffset = ((gameBlock-1)%2)*3 ;
for(int i=0+rowOffset; i<3+rowOffset; i++)
for(int j=0+colOffset; j<3+colOffset; j++)
rotLeft[2-j+rowOffset+colOffset][i-rowOffset+colOffset] = board[i][j] ;
return rotLeft ;
}

public static int[][] matrixrotateRight(int[][] board, int gameBlock)
{
int[][] rotRight = board; ;
//------------
//------------

int rowOffset = ((gameBlock-1)/2)*3 ;
//System.out.println("-rowOffset-" + rowOffset) ;
int colOffset = ((gameBlock-1)%2)*3 ;

for(int i= rowOffset; i<3+rowOffset; i++){
for(int j= colOffset; j<3+colOffset; j++){
rotRight[j+rowOffset-colOffset][2-i+rowOffset+colOffset] = board[i][j] ;
}}
return rotRight ;
}

public static void main(String[] args)
{
/*
int[][] Matrix = new int[][] {
{ 1, 2, 3, 10, 11 ,12 },
{ 4, 5, 6, 13, 14 ,15 },
{ 7, 8, 9, 16, 17 ,18 },

{ 19, 20, 21, 28, 29 ,30 },
{ 22, 23, 24, 31, 32 ,33 },
{ 25, 26, 27, 34, 35 ,36 },
};
*/
int[][] Matrix = new int[][] {
{ 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 },
};

for (int r=0; r<Matrix.length; r++) {
for (int c=0; c<Matrix[r].length; c++) {
System.out.print(" " + Matrix[r][c]); }
System.out.println(""); }

System.out.println("-----------------------------------------");

Matrix = matrixrotateRight(Matrix,1);

for (int r=0; r<Matrix.length; r++) {
for (int c=0; c<Matrix[r].length; c++) {
System.out.print(" " + Matrix[r][c]); }
System.out.println(""); }

}

}

here is the out put but it;s wrong :
1 2 3
4 5 6
7 8 9
-----------------------------------------
7 4 1
2 5 2
1 2 1

it should be this output

7 4 1
8 5 2
9 6 3

can anyone point out what did i do wrong ..
thank you ,
• 11-23-2008, 02:49 AM
Nicholas Jordan
Wow, rank beginner wants shippable code for Vector Math. What's next, brain implants for total software download?

See our discussion in Jokes and Funny things. Probably get the help you need there.

Latratus Maximus, Canni Sonti Est.
• 11-23-2008, 05:04 AM
TrungTran
sorry i 'm new to this forum. i'm not sure where to post this.