1. Member Join Date
Nov 2008
Posts
4
Rep Power
0

## Need help real bad on 2D array please !

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 ,  Reply With Quote

2. ## 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.  Reply With Quote

3. Member Join Date
Nov 2008
Posts
4
Rep Power
0

## sorry i 'm new to this forum. i'm not sure where to post this.  Reply With Quote

#### Posting Permissions

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