Results 1 to 3 of 3
  1. #1
    TrungTran is offline Member
    Join Date
    Nov 2008
    Posts
    4
    Rep Power
    0

    Arrow 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 ,

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    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.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #3
    TrungTran is offline Member
    Join Date
    Nov 2008
    Posts
    4
    Rep Power
    0

    Default

    sorry i 'm new to this forum. i'm not sure where to post this.

Similar Threads

  1. Replies: 7
    Last Post: 09-16-2008, 06:20 PM
  2. Replies: 0
    Last Post: 08-13-2008, 10:46 PM
  3. Replies: 0
    Last Post: 08-01-2008, 11:59 AM
  4. Replies: 0
    Last Post: 07-31-2008, 11:33 AM
  5. real world java
    By Zosden in forum Forum Lobby
    Replies: 6
    Last Post: 06-25-2008, 05:39 AM

Posting Permissions

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