So, I have a program that simply simulates checkers (but instead of jumping, one part just βeatsβ another play). I have a simple class that implements an object of the "Checkers" class and creates an int array variable called "chips", there are "WHILE" instructions that create a loop, while the chips [0] and the chips [1] of integers are larger 0. it looks like this:
public static void main(String [] args){ Checkers c = new Checkers(); c.init(); c.printBoard(); int[] chips = c.count(); Scanner kbd = new Scanner(System.in); while(chips[0]>0 && chips[1]>0){ System.out.println("\nYour move? 4 ints: src row, src col, dest row, dest col separated by [SPACE]"); int srcR = kbd.nextInt(); int srcC = kbd.nextInt(); int destR = kbd.nextInt(); int destC = kbd.nextInt(); kbd.nextLine(); c.move(srcR,srcC,destR,destC); c.printBoard(); System.out.println(c.getMessage()); c.count(); } }
My counting method in the Checkers class is as follows:
public int[] count() { int wht=0; int blk=0; System.out.println(); for(int i=0; i<board.length;i++) { for(int z=0; z<board[0].length;z++) { if(board[i][z] instanceof White) { wht++; } else if(board[i][z] instanceof Black) { blk++; } } } int[] arr = {wht,blk}; System.out.println("Whites: "+wht+"\nBlacks: "+blk); return arr; }
The board is 8 x 8 (this is what board.length is), and the count method simply returns the value βarrβ so that it can report to the βchipsβ to decide if there will be chips [1] and chips [0] - more than one (they both have at least one piece of white or black on the board). The array should consist of only two values ββ(ie {White, black};) I tried to reformat the entire counter () in different ways, but this is just one of several ways to compile the code.
here is the result:
01234567
0 | ........
1 | ..B .....
2 | ........
3 | ........
4 | ........
5 | ... BBB
6 | .BBBB
As you can see, there are no more white pieces (they are supposed to be at the top). I would be grateful for the help that this is probably an easy fix, looking right under my nose, but it is annoying, so I hope I have explained it quite well. Thanks.
oh btw, I was told not to touch the main method at all.