2012-03-01 4 views
0

루크 또는 주교를 표시하도록 배열을 가져올 수 없습니다 (r & b). 나는 그들을 킹 (k), G, s, n, l 앞 줄에 표시 할 필요가있다. case 문은 보드를 통과하여 모든 조각을 그려야합니다. 그러나 18 번만 실행되고 충돌은 발생하지만 배열을 40 조각으로 선언해야합니다. (각 플레이어는 20 개의 조각으로 시작합니다.). case 문은 현재 r과 b를 무시합니다. 여기 배열의 보드 게임 조각을

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/[email protected]@[email protected] -> /data/dalvik-cache/[email protected]@[email protected] 
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/[email protected]@[email protected] 
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 

이 조각의 클래스입니다 : 여기
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{ 

전체 오류 로그입니다

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 
+0

오류 로그 많은 방법이 거기에있다 – Triode

+0

이해할 수있을 것이다 게시 할 때 오류 로그 형식을 지정합니까? 지금은 하나의 커다란 선으로 나옵니다. 읽기가 어렵습니다. @slayton 코드를 다시 작성하고 일부 값을 변경하려고 시도했지만 아무 것도 시도하지 않은 것 같습니다. –

+0

전체 스택 추적을 단일 코드 블록에 복사하여 붙여 넣습니다. – slayton

답변

0

이해야 :

:

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

이 될(10)를 통해 또한

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

, 조각 0 pieces에 instered되지만, 당신은 졸 9 및 10 (당신의 B와 R 조각을) 덮어 씁니다.


제안, 당신은 다음 INT의 pieceNum을 만들고 해달라고 이유는 사용

pieces[pieceNum++] = ... 

을 대신 오프셋 계산.


당신이 그 클래스를 게시하지 않았기 때문에 당신의 생성자 args도 보지 않았습니다. pieces 배열에 대한 오프셋 계산에는 충분한 문제가 있습니다. 이 코드의 첫 번째 패스에

는, 오프셋 (코멘트)에 보면 (당신의 외부 변수 i = 1 인 동안) :

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

고마워, 나는 단지 나 자신을 알아 차렸다. 나는 어떻게 그것이 1이되었는지 알지 못하지만 ... –

+0

@OneGlove 더 많은 것을 알고있다. 편집을 확인한다 – tcarvin

+0

b와 r에 대한 (7 * i)가 폰보다 위의 행에 표시 될 것이라고 생각했거나, i3을 사용하여 for 루프의 닫기 괄호를 이동 하시겠습니까? –

관련 문제