
-----------------------------------
jMan
Fri Jan 25, 2008 7:26 pm

Requesting some help.
-----------------------------------
Hello, I'm new to this forum as of posting, but I've been reading it for a little while now. I'm working on a little game and I'm stuck. Its similar to "Nim" or "Pearls before Swine". Anyways I having trouble accessing my columns in a array. I'm try to verify a move for my game. This is how the game works:

Its a single player game played against a computer. The point of the game is to make your opponent remove the last "bean". The board is made with a 2 dimensional array. This is what the game board looks like:

0
000
00000
0000000
000000000 

Anyways if you know the rules of "Pearls Before Swine" theres no need to read this next part. 


The human player moves first. The player can move as many beans as they want as long
as they all come from the same row. To move, the player must specify the row and
column of the bean to be removed. All beans to the right of the specified bean are also
removed. For instance, if you wanted to remove four beans from the third row, you
would enter 3 and 2 (you will have to take into consideration that arrays are indexed
starting at zero and adjust so that the player can count from 1). The result would be:

0
000
0
0000000
000000000

The computer then takes a turn removing a selected number of beans the result of which
is also displayed to the user. The computer should choose his moves intelligently (ie. it
should be difficult to beat). The player who must remove the last bean loses. Input
should be validated so that the player cannot crash the game.

Anyways I'm having trouble verifying the removal of a "bean". This is my code so far:

import java.util.*;
import java.util.Random;

public class beanGame
{
   private int playingBoard[][] = { {0}, {0,0,0}, {0,0,0,0,0}, {0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0} };
	private int beans, row, comRow, comBeans;
	private boolean isRow = false, isBean = false;
	private int counters[]; 
											 
   public static void main(String[] args)
	{
	   beanGame game = new beanGame();
		System.out.println("Welcome to the bean game.");
		game.printBoard();
		game.countBean();
		game.userMove();
		game.compMove();
	}
	public void printBoard()
	{
	   for ( int i = 0; i < playingBoard.length; i++ )
      {       
			for ( int j = 0; j < playingBoard[i].length; j++ )
         {
            System.out.print( playingBoard[ i ][ j ] + " " );
         }
			System.out.println( "" );
      }
	}
	public void countBean()
	{
	   counters = new int[ 5 ];
		for ( int i = 0; i < playingBoard.length; i++ )
		{
		   for ( int j = 0; j < playingBoard[i].length ; j++ )
			{
			   if ( playingBoard[i][j] == 0 )
				   counters[i]++;
			}
		}
	}
	public void userMove()
	{
	   Scanner scanner = new Scanner( System.in );
		boolean isRow = false;
		while( !isRow )
		{
	      System.out.println( "What row would you like to remove beans from?" );
		   row = scanner.nextInt();
			
			if ( row >= 1 && row = 1 &&  beans = 1 && comRow = 1 && comBeans 