Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7570737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:29:53+00:00 2026-05-30T15:29:53+00:00

I cannot get the array to display rooks or bishops (r & b). I

  • 0

I cannot get the array to display rooks or bishops (r & b). I need them displayed on the row in front of the King (k), G, s, n, l.
The case statements should run through and draw all the pieces on the board, however it will only run through 18 times, then crash, but I’m sure I declared the array to have 40 pieces (In shogi each player starts with 20 pieces).
The case statements also ignore case r and b at the moment.

    private void setUpNewPieces(){
    for (int i = 0; i < 2; i++){
        //Sets back row.
        pieces[20 * i] = new Piece ('K', i, 4, (8 * i));
        pieces[(20 * i) + 1] = new Piece('G', i, 3, (8 * i));
        pieces[(20 * i) + 2] = new Piece('s', i, 2, (8 * i));
        pieces[(20 * i) + 3] = new Piece('n', i, 1, (8 * i));
        pieces[(20 * i) + 4] = new Piece('l', i, 0, (8 * i));
        pieces[(20 * i) + 5] = new Piece('G', i, 5, (8 * i));
        pieces[(20 * i) + 6] = new Piece('s', i, 6, (8 * i));
        pieces[(20 * i) + 7] = new Piece('n', i, 7, (8 * i));
        pieces[(20 * i) + 8] = new Piece('l', i, 8, (8 * i));

        for (int i3 = 0; i3 < 2; i3++){
            pieces[(20 * i) + 9] = new Piece('b', i, i3, (7 * i));
            pieces[(20 * i) + 10] = new Piece('r', i, i3, (7 * 1));
        }
        //Set pawns.
        for (int i2 = 0; i2 < 9; i2++){
            pieces[(18 * i) + 9 + i2] = new Piece('p', i, i2,(6 * i));
        }
        Log.d("setUpNewPieces", "pawnDone");
    }
    Log.d("setUpNewPieces", "nonPawnDone");
}//END private void newPieces()



private void updateBoard(){
    Location field;
    int x, y;

    String theArray;
    for(int jkl=0;jkl < pieces.length;jkl++){
        theArray = jkl + ": " + String.valueOf(pieces[jkl].type) + "-" + String.valueOf(pieces[jkl].direction);
        Log.d("TheArray",theArray);
    }

    //Draw pieces.
    for (int i = 0; i < 40; i++){
        field = pieces [i].getLocation();
        Log.d("DrawPieces - i",String.valueOf(i));
        Log.d("DrawPieces - type",String.valueOf(pieces[i].type));
        Log.d("DrawPieces - direction",String.valueOf(pieces[i].direction));
        x = field.getX();
        y = field.getY();

        if(!field.isEmpty()){
            switch (pieces[i].direction){
            case 0:
                Log.d("pieces[i].d...","case0Start");
                switch (pieces[i].type){
                case 'K':
                    gameBoardView[x][y].setImageResource(R.drawable.king);
                    break;
                case 'G':
                    gameBoardView[x][y].setImageResource(R.drawable.gold);
                    break;
                case 's':
                    gameBoardView[x][y].setImageResource(R.drawable.silver);
                    break;
                case 'S':
                    gameBoardView[x][y].setImageResource(R.drawable.silver_p);
                    break;
                case 'n':
                    gameBoardView[x][y].setImageResource(R.drawable.knight);
                    break;
                case 'N':
                    gameBoardView[x][y].setImageResource(R.drawable.knight_p);
                    break;
                case 'l':
                    gameBoardView[x][y].setImageResource(R.drawable.lance);
                    break;
                case 'L':
                    gameBoardView[x][y].setImageResource(R.drawable.lance_p);
                    break;
                case 'b':
                    gameBoardView[x][y].setImageResource(R.drawable.bishop);
                    break;
                case 'B':
                    gameBoardView[x][y].setImageResource(R.drawable.bishop_p);
                    break;
                case 'r':
                    gameBoardView[x][y].setImageResource(R.drawable.rook);
                    break;
                case 'R':
                    gameBoardView[x][y].setImageResource(R.drawable.rook_p);
                    break;
                case 'p':
                    gameBoardView[x][y].setImageResource(R.drawable.pawn);
                    break;
                case 'P':
                    gameBoardView[x][y].setImageResource(R.drawable.pawn_p);
                    break;
                }//END switch (pieces[i].type) WITHIN case 0
                Log.d("pieces[i].d...","case0Finish");
                break;
            case 1:
                Log.d("pieces[i].d...","case1Start");
                switch (pieces[i].type){
                case 'K':
                    gameBoardView[x][y].setImageResource(R.drawable.king_rot);
                    break;
                case 'G':
                    gameBoardView[x][y].setImageResource(R.drawable.gold_rot);
                    break;
                case 's':
                    gameBoardView[x][y].setImageResource(R.drawable.silver_rot);
                    break;
                case 'S':
                    gameBoardView[x][y].setImageResource(R.drawable.silver_p_rot);
                    break;
                case 'n':
                    gameBoardView[x][y].setImageResource(R.drawable.knight_rot);
                    break;
                case 'N':
                    gameBoardView[x][y].setImageResource(R.drawable.knight_p_rot);
                    break;
                case 'l':
                    gameBoardView[x][y].setImageResource(R.drawable.lance_rot);
                    break;
                case 'L':
                    gameBoardView[x][y].setImageResource(R.drawable.lance_p_rot);
                    break;
                case 'b':
                    gameBoardView[x][y].setImageResource(R.drawable.bishop_rot);
                    break;
                case 'B':
                    gameBoardView[x][y].setImageResource(R.drawable.bishop_p_rot);
                    break;
                case 'r':
                    gameBoardView[x][y].setImageResource(R.drawable.rook_rot);
                    break;
                case 'R':
                    gameBoardView[x][y].setImageResource(R.drawable.rook_p_rot);
                    break;
                case 'p':
                    gameBoardView[x][y].setImageResource(R.drawable.pawn_rot);
                    break;
                case 'P':
                    gameBoardView[x][y].setImageResource(R.drawable.pawn_p_rot);
                    break;
                }//END switch (pieces[i].type) WITHIN case 1
                Log.d("pieces[i].d...","case1Finish");
                break;

            }//END switch (pieces[i].direction)
            Log.d("updateBoardDrawPieces", "drawDone");
        }//END if(!field.isEmpty())
    }//END for (int i = 0; i < 40; i++)

}//END updateBoard{

Here is the full error log:

03-01 14:59:55.262: DEBUG/AndroidRuntime(579): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
03-01 14:59:55.272: DEBUG/AndroidRuntime(579): CheckJNI is ON
03-01 14:59:55.522: DEBUG/AndroidRuntime(579): --- registering native functions ---
03-01 14:59:56.742: DEBUG/dalvikvm(184): GC_EXPLICIT freed 121 objects / 6392 bytes in 153ms
03-01 14:59:56.852: DEBUG/PackageParser(68): Scanning package: /data/app/vmdl73743.tmp
03-01 14:59:57.242: DEBUG/dalvikvm(68): GC_FOR_MALLOC freed 14819 objects / 820272 bytes in 171ms
03-01 14:59:58.022: INFO/PackageManager(68): Removing non-system package:com.coursework.shogi
03-01 14:59:58.022: INFO/ActivityManager(68): Force stopping package com.coursework.shogi uid=10036
03-01 14:59:58.252: DEBUG/PackageManager(68): Scanning package com.coursework.shogi
03-01 14:59:58.252: INFO/PackageManager(68): Package com.coursework.shogi codePath changed from /data/app/com.coursework.shogi-2.apk to /data/app/com.coursework.shogi-1.apk; Retaining data and using new
03-01 14:59:58.272: INFO/PackageManager(68): /data/app/com.coursework.shogi-1.apk changed; unpacking
03-01 14:59:58.322: DEBUG/installd(35): DexInv: --- BEGIN '/data/app/com.coursework.shogi-1.apk' ---
03-01 14:59:58.692: DEBUG/dalvikvm(586): DexOpt: load 64ms, verify 143ms, opt 4ms
03-01 14:59:58.705: DEBUG/installd(35): DexInv: --- END '/data/app/com.coursework.shogi-1.apk' (success) ---
03-01 14:59:58.712: WARN/PackageManager(68): Code path for pkg : com.coursework.shogi changing from /data/app/com.coursework.shogi-2.apk to /data/app/com.coursework.shogi-1.apk
03-01 14:59:58.712: WARN/PackageManager(68): Resource path for pkg : com.coursework.shogi changing from /data/app/com.coursework.shogi-2.apk to /data/app/com.coursework.shogi-1.apk
03-01 14:59:58.712: DEBUG/PackageManager(68):   Activities: com.coursework.shogi.Shogi com.coursework.shogi.Instructions com.coursework.shogi.Game com.coursework.shogi.Prefs
03-01 14:59:58.732: INFO/ActivityManager(68): Force stopping package com.coursework.shogi uid=10036
03-01 14:59:58.932: INFO/installd(35): move /data/dalvik-cache/data@app@com.coursework.shogi-1.apk@classes.dex -> /data/dalvik-cache/data@app@com.coursework.shogi-1.apk@classes.dex
03-01 14:59:58.932: DEBUG/PackageManager(68): New package installed in /data/app/com.coursework.shogi-1.apk
03-01 14:59:59.192: INFO/ActivityManager(68): Force stopping package com.coursework.shogi uid=10036
03-01 14:59:59.332: DEBUG/dalvikvm(127): GC_EXPLICIT freed 796 objects / 43384 bytes in 117ms
03-01 14:59:59.742: WARN/RecognitionManagerService(68): no available voice recognition services found
03-01 15:00:00.182: DEBUG/dalvikvm(68): GC_EXPLICIT freed 12265 objects / 682336 bytes in 190ms
03-01 15:00:00.262: DEBUG/dalvikvm(165): GC_EXPLICIT freed 1580 objects / 80600 bytes in 895ms
03-01 15:00:00.342: INFO/installd(35): unlink /data/dalvik-cache/data@app@com.coursework.shogi-2.apk@classes.dex
03-01 15:00:00.372: DEBUG/AndroidRuntime(579): Shutting down VM
03-01 15:00:00.382: DEBUG/dalvikvm(579): Debugger has detached; object registry had 1 entries
03-01 15:00:00.412: INFO/AndroidRuntime(579): NOTE: attach of thread 'Binder Thread #3' failed
03-01 15:00:01.212: DEBUG/AndroidRuntime(592): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
03-01 15:00:01.212: DEBUG/AndroidRuntime(592): CheckJNI is ON
03-01 15:00:01.582: DEBUG/AndroidRuntime(592): --- registering native functions ---
03-01 15:00:02.673: INFO/ActivityManager(68): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.coursework.shogi/.Shogi }
03-01 15:00:02.942: DEBUG/AndroidRuntime(592): Shutting down VM
03-01 15:00:02.973: DEBUG/dalvikvm(592): Debugger has detached; object registry had 1 entries
03-01 15:00:03.052: INFO/AndroidRuntime(592): NOTE: attach of thread 'Binder Thread #3' failed
03-01 15:00:03.104: INFO/ActivityManager(68): Start proc com.coursework.shogi for activity com.coursework.shogi/.Shogi: pid=599 uid=10036 gids={}
03-01 15:00:04.702: INFO/ActivityManager(68): Displayed activity com.coursework.shogi/.Shogi: 1768 ms (total 2033641 ms)
03-01 15:00:07.112: INFO/ActivityManager(68): Starting activity: Intent { cmp=com.coursework.shogi/.Game }
03-01 15:00:07.622: DEBUG/setContentView(599): Called in protected void
03-01 15:00:07.652: DEBUG/setUpObjects(599): setUpGameBoardViewCalled
03-01 15:00:07.682: DEBUG/setUpObjects(599): initialseGridViews

It calls the class 40 times, as I wanted...

03-01 15:00:07.692: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.692: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.692: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.702: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.722: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.722: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.722: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.722: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.734: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.734: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.741: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.741: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.752: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.752: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.752: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.752: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.762: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.762: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.772: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.772: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.772: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.772: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.772: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.772: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.772: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.772: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.772: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.772: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.772: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.772: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.772: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.772: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.772: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.772: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.772: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.772: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.772: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.792: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.792: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.792: DEBUG/publicClassPiece(599): Started
03-01 15:00:07.792: DEBUG/setUpObjects(599): lastMoveInitialised
03-01 15:00:07.792: DEBUG/setUpObjects(599): Called in protected void
03-01 15:00:07.792: DEBUG/setUpNewPieces(599): pawnDone
03-01 15:00:07.792: DEBUG/setUpNewPieces(599): pawnDone
03-01 15:00:07.792: DEBUG/setUpNewPieces(599): nonPawnDone
03-01 15:00:07.792: DEBUG/setUpNewPieces(599): Called in protected void

Here TheArray is only called 18 times, I was told this is because I only have 18 spaces in the array, and it then crashes because there is no more room. It calls the back row of pieces and the pawns, ignoring the rook and bishop; and never getting to the second player
(Sorry if I repeated myself, but i thought this may help).

03-01 15:00:07.792: DEBUG/TheArray(599): 0: K-0
03-01 15:00:07.792: DEBUG/TheArray(599): 1: G-0
03-01 15:00:07.792: DEBUG/TheArray(599): 2: s-0
03-01 15:00:07.792: DEBUG/TheArray(599): 3: n-0
03-01 15:00:07.792: DEBUG/TheArray(599): 4: l-0
03-01 15:00:07.792: DEBUG/TheArray(599): 5: G-0
03-01 15:00:07.792: DEBUG/TheArray(599): 6: s-0
03-01 15:00:07.792: DEBUG/TheArray(599): 7: n-0
03-01 15:00:07.792: DEBUG/TheArray(599): 8: l-0
03-01 15:00:07.792: DEBUG/TheArray(599): 9: p-0
03-01 15:00:07.792: DEBUG/TheArray(599): 10: p-0
03-01 15:00:07.792: DEBUG/TheArray(599): 11: p-0
03-01 15:00:07.792: DEBUG/TheArray(599): 12: p-0
03-01 15:00:07.792: DEBUG/TheArray(599): 13: p-0
03-01 15:00:07.792: DEBUG/TheArray(599): 14: p-0
03-01 15:00:07.802: DEBUG/TheArray(599): 15: p-0
03-01 15:00:07.802: DEBUG/TheArray(599): 16: p-0
03-01 15:00:07.802: DEBUG/TheArray(599): 17: p-0
03-01 15:00:07.802: DEBUG/AndroidRuntime(599): Shutting down VM
03-01 15:00:07.802: WARN/dalvikvm(599): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
03-01 15:00:07.852: ERROR/AndroidRuntime(599): FATAL EXCEPTION: main
03-01 15:00:07.852: ERROR/AndroidRuntime(599): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.coursework.shogi/com.coursework.shogi.Game}: java.lang.NullPointerException
03-01 15:00:07.852: ERROR/AndroidRuntime(599):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
03-01 15:00:07.852: ERROR/AndroidRuntime(599):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-01 15:00:07.852: ERROR/AndroidRuntime(599):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-01 15:00:07.852: ERROR/AndroidRuntime(599):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-01 15:00:07.852: ERROR/AndroidRuntime(599):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-01 15:00:07.852: ERROR/AndroidRuntime(599):     at android.os.Looper.loop(Looper.java:123)
03-01 15:00:07.852: ERROR/AndroidRuntime(599):     at android.app.ActivityThread.main(ActivityThread.java:4627)
03-01 15:00:07.852: ERROR/AndroidRuntime(599):     at java.lang.reflect.Method.invokeNative(Native Method)
03-01 15:00:07.852: ERROR/AndroidRuntime(599):     at java.lang.reflect.Method.invoke(Method.java:521)
03-01 15:00:07.852: ERROR/AndroidRuntime(599):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-01 15:00:07.852: ERROR/AndroidRuntime(599):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-01 15:00:07.852: ERROR/AndroidRuntime(599):     at dalvik.system.NativeStart.main(Native Method)
03-01 15:00:07.852: ERROR/AndroidRuntime(599): Caused by: java.lang.NullPointerException
03-01 15:00:07.852: ERROR/AndroidRuntime(599):     at com.coursework.shogi.Game$Piece.access$0(Game.java:72)
03-01 15:00:07.852: ERROR/AndroidRuntime(599):     at com.coursework.shogi.Game.updateBoard(Game.java:434)
03-01 15:00:07.852: ERROR/AndroidRuntime(599):     at com.coursework.shogi.Game.onCreate(Game.java:30)
03-01 15:00:07.852: ERROR/AndroidRuntime(599):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-01 15:00:07.852: ERROR/AndroidRuntime(599):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-01 15:00:07.852: ERROR/AndroidRuntime(599):     ... 11 more
03-01 15:00:07.904: WARN/ActivityManager(68):   Force finishing activity com.coursework.shogi/.Game
03-01 15:00:07.912: WARN/ActivityManager(68):   Force finishing activity com.coursework.shogi/.Shogi
03-01 15:00:08.413: WARN/ActivityManager(68): Activity pause timeout for HistoryRecord{45009650 com.coursework.shogi/.Game}
03-01 15:00:14.871: DEBUG/dalvikvm(184): GC_EXPLICIT freed 163 objects / 11848 bytes in 158ms
03-01 15:00:19.523: WARN/ActivityManager(68): Activity destroy timeout for HistoryRecord{44ff8a00 com.coursework.shogi/.Shogi}
03-01 15:00:19.523: WARN/ActivityManager(68): Activity destroy timeout for HistoryRecord{45009650 com.coursework.shogi/.Game}
03-01 15:00:19.912: DEBUG/dalvikvm(262): GC_EXPLICIT freed 47 objects / 2264 bytes in 154ms

Here is the class for the pieces:

public class Piece {
    /**Type List:
     * K = King
     * G = Gold General
     * s = Silver General
     * S = Promoted Silver
     * n = Knight
     * N = Promoted Knight
     * l = Lance
     * L = Promoted Lance
     * b = Bishop
     * B = Dragon Horse (Promoted Bishop)
     * r = Rook
     * R = Dragon (Promoted Rook)
     * p = Pawn
     * P = Token (Promoted Pawn)
     */
    private char type;//see above for the variables used for the types of piece..
    private int direction;//0 = black/gote, 1 = white/sente. 
    private Location field = new Location();
    private boolean moved;
    private boolean onBoard;//if false, the piece will be in a token reservoir.
        //private bool onBoard not implemented

    public Piece(char setType, int setDirection, int setX, int setY){
        this.type = setType;
        this.direction = setDirection;
        this.field.setX(setX);
        this.field.setY(setY);
        this.moved = false;
        this.onBoard = true;
    }

    public Piece(){
        this.type = 'K';
        this.direction = 0;
        this.field.empty();
        this.moved = false;
        this.onBoard = true;
    }

    public void copyFrom(Piece p){
        type = p.getType();
        direction = p.getDirection();
        field.setX(p.getLocation().getX());
        field.setY(p.getLocation().getY());
    }

    public Location getLocation(){
        return field;
    }

    public void setLocation(int x, int y, boolean move){
        field.setX(x);
        field.setY(y);
        if (move){
            moved = true;
        }
    }

    public int getX(){
        return field.getX();
    }

    public int getY(){
        return field.getY();
    }

    public void setX(int x){
        field.setX(x);
    }

    public void setY(int y){
        field.setY(y);
    }

    public boolean compareLocation(Location l){
        return field.equals(l);
    }

    public boolean compareLocation(int x, int y){
        return ((x == field.getX()) && (y == field.getY()));
    }

    public int getDirection(){
        return direction;
    }

    public void setDirection(int i){
        direction = i;
    }

    public char getType(){
        return type;
    }

    public void setType(int i){
        type = (char) i;
    }

    public boolean hasMoved(){
        return moved;
    }

    public void setMoved(byte b){
        moved = (b == 1);
    }

}//END public class Piece
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T15:29:54+00:00Added an answer on May 30, 2026 at 3:29 pm

    Should this:

    pieces[(20 * i) + 10] = new Piece('r', i, i3, (7 * 1));
    

    be this:

    pieces[(20 * i) + 10] = new Piece('r', i, i3, (7 * i));
    

    Also, pieces 0 through 10 are instered in pieces, but then you overwrite 9 and 10 (your b and r pieces) with the pawns.


    Suggestion, why dont you create an int pieceNum and then use:

    pieces[pieceNum++] = ...
    

    instead of calculating the offset.


    I’m not even looking at your constructor args because you didn’t post that class. There are enough problems on the calculation of the offset into the pieces array.

    On the first pass of this code (while your outer i variable is = 1), look at the OFFSET (in the comments):

    pieces[20 * i] = new Piece ('K', i, 4, (8 * i)); // OFFSET = 0
    pieces[(20 * i) + 1] = new Piece('G', i, 3, (8 * i)); // OFFSET = 1
    pieces[(20 * i) + 2] = new Piece('s', i, 2, (8 * i)); // OFFSET = 2
    pieces[(20 * i) + 3] = new Piece('n', i, 1, (8 * i)); // OFFSET = 3
    pieces[(20 * i) + 4] = new Piece('l', i, 0, (8 * i)); // OFFSET = 4
    pieces[(20 * i) + 5] = new Piece('G', i, 5, (8 * i)); // OFFSET = 5
    pieces[(20 * i) + 6] = new Piece('s', i, 6, (8 * i)); // OFFSET = 6
    pieces[(20 * i) + 7] = new Piece('n', i, 7, (8 * i)); // OFFSET = 7
    pieces[(20 * i) + 8] = new Piece('l', i, 8, (8 * i)); // OFFSET = 8
    
    for (int i3 = 0; i3 < 2; i3++){             
       pieces[(20 * i) + 9] = new Piece('b', i, i3, (7 * i)); // OFFSET = 9 for both bishops, the 2nd overwrites the 1st
       pieces[(20 * i) + 10] = new Piece('r', i, i3, (7 * 1)); // OFFSET = 10 for both rooks, the 2nd overwrites the 1st
    }         
    
    for (int i2 = 0; i2 < 9; i2++){             
       pieces[(18 * i) + 9 + i2] = new Piece('p', i, i2,(6 * i)); // OFFSET = 9 thru 16, overwriting the bishop and rook set above
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cannot get the DropDownHeight of the ComboBox set properly to display all the
I cannot get a two-way bind in WPF to work. I have a string
I cannot get the internet explorer web developer tool bar to work with a
I cannot get std::tr1::shared_ptr for my WinMobile project since the STL for WinCE is
I cannot get my SID working ... <?php session_start(); // Or maybe pass along
I cannot get Bindable LINQ to work with VB.NET for the life of me.
I cannot get the background to stretch behind the contentbox. The strange thing is,
I cannot get the jQuery slideDown function to work on <table> elements. They just
I cannot get the example Python programs to run. When executing the Python command
I cannot get the following route to fire when a url is requested from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.