Problems with a player for Checkers

Hi every1,

I have a problem writting my player for tha game Checkers (i guess all of you know this game).  
So - I'm talking about the International version of the game  10x10. I have the board (it is in german, but it is not so important). My task is to write a player for it. Everything is in Java 2. I have the last version 1.5_06. As a development program - Eclipse 3.1.
I'm ready with the algorithms and so on and I am able to load the player, but when the game starts - a become the NullPointerException. Inside I work with a couple of lists and 2 arries. I have already checked everything more than 3 times... but I cannot see my error.

If someone wants to help, I am ready to send my source, the board and its source too (of course). I guess it is something little, but I can't find it :(
You can reach me under:  keksy@yahoo.com at any time

Thanks in advance
keksyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ikeworkCommented:
hi keksy,

its not in the terms of ee to resolve the questions apart from here via email!

maybe you should post a pointer in the java-area to this question, since this is more a java-related question, than a ai/physics - one.
if you are unsure, how to create a pointer, post a request here.

i'm not a java-programmer, but c++, but debugging is quite general, so lets go ..

did you find the code, where this exception is thrown? if not use a debugger and find it.. then post it here, so we can try to help you.

good luck :)
ike
0
keksyAuthor Commented:
Yes, please, tell me how to post a request to the Java-area...
Debugger - I cannot run it, because I have problems with references to the functions... :(
0
ikeworkCommented:
you should fix that... programming without debugger gets harder and harder, the grater the project grows...
download another ide, if you cant fix it. if you dont get the debugger running insert debug-output to your
programm at significant places and where you suspect the error to be.. try to find out, where the app crashes.

go to the java area and add a question called "pointer to ... blablabla". put the url to this question into the body, like this:
http://www.experts-exchange.com/Programming/Game_Development/AI_Physics/Q_21799592.html
give it 20 points, dont worry you get them back as long as nobody posts to this thread, but even if someone posts there
you can ask in community-support for points refund, thats ok...

ike
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

CEHJCommented:
Please post the stack trace of the exception
0
sciuriwareCommented:
>>> Debugger - I cannot run it, because I have problems with references to the functions... :(

Impossible that's C++ : in JAVA there are no references to functions!

;JOOP!
0
keksyAuthor Commented:
No, this is Java. The problem is that I have given the board and I have also a Player.class file and I should use this...  and when try to add a main-method in my classes, is says: "Cannot make static reference to non-static methods". If I create an object in the main-class, it is not the same, as it should be in original :(
I'll do my best to debug it, but... I am not sure I can handle it out.
The code is long and I do not know if it'll be a good idea to post it here...  I can upload it in my website and post here the links
0
sciuriwareCommented:
>>> "Cannot make static reference to non-static methods".

Do you understand this? If not, drop the task and start a tutorial, because this is essential.

;JOOP!
0
keksyAuthor Commented:
Thanks for the tip, sciuriware :)

So, here is the link I have promissed. It is too long to place it here...
http://kater.duo-vision.com/

In regard to points - I give all my points (at about 500)...

Thanks in advance
0
sciuriwareCommented:
I've looked at your 'whole' package.
The error is a null reference encountered when an action is fired: probably a false argument to "addActionListener()"
when setting up the GUI.
Now, I can't find any kind of GUI build-up in your sources ..................

;JOOP!
0
keksyAuthor Commented:
I do not get your point... :(
And what kind of GUI are you looking for?  Under GUI I mean the board...
0
keksyAuthor Commented:
I am trying to debug it, while adding to the player/kater/Kater.java file this:

public static void main (String args[]){
      Moves board = new Moves();
      Kater cat = new Kater(board);
      cat.play();
}


but I'm getting:
java.lang.NoSuchMethodError: main
Exception in thread "main"

I really don't get it anymore - totally confused! Just sitting in front of the screen and... out of ideas :(((
0
sciuriwareCommented:
In ECLIPSE you must create a project; I think you did it.
Then, for the first time, select the main module (Kater.java) and select Run As.
That will work; from then it runs after Ctrl/F11

Now that GUI: I just read the error messages in your package. Are those not actual?

;JOOP!
0
keksyAuthor Commented:
Yes, I did a priject, imported the .jar file and so on... I also know how to run and re-run a file... but exactly the Eclipse gives me this error... :(

The error messages are actual, but this what I get here is nothing to do with those errors (or I am wrong) ??
Am I writing something, that doesn't match... I think the code, with which I am trying to run and debug the Kater.java is correct... and it gives me this funny erros.. damn :(
0
sciuriwareCommented:
I found something: Kater.java ====    public class Kater extends kater.Kater{}

That's a weird class: ECLIPSE doesn't understand that it inherits a 'main()'.
You should change that by giving it a main that calls the super class's main.

;JOOP!
0
keksyAuthor Commented:
Actually I do not touch this "start-class" (if I can say like this) right now.  I am trying to debug tha player and now I work within the package Kater. I am trying to add a main-function to the kater.java, which is inside tha package and I see this error... :(
The file kater.java, in which is this: "public class Kater extends kater.Kater{}" is used from the game to load the player from the verry beginning. It just shows to the game where are the player's .class files...
Should I chage anything there? I don't think so, but if you say it is necessary - I will!

I just don't get it - I am adding a main-method in the kater.java (in the file in tha package), I am 101% sure there are no miss-spelling or something else, I declare an object from type Kater and I apply the function play() to this newly created object...  and I get:

java.lang.NoSuchMethodError: main
Exception in thread "main"

What the f.... is going on :(((((((((((((((((((((((((
0
sciuriwareCommented:
Do you want to change Kater.java?

Then it is simple:

Kater.java :

public class Kater
{
      public static void main(String args[])
      {
            kater.Kater.main(args);
      }

}

This class will simply call the other one.

;JOOP!
0
sciuriwareCommented:
And don't curse the computer: the poor thing is always right.

;JOOP!
0
keksyAuthor Commented:
This doesn't help, sciuriwave. It doesn't change anything. This just adds a link to the main, that I have already written. And I still get the same error... :(((
0
sciuriwareCommented:
You start the application by Kater.java, containing the above and it says "java.lang.NoSuchMethodError: main"?

Impossible, can you post the entire Kater.java as it is now?

;JOOP!
0
keksyAuthor Commented:
As you want...


package kater;
import eMad.Player;
import eMad.Board;

/* Kater.java : My own player
 * Copyright (C) 2006  Vasil Vasilev
 */

public class Kater extends Player{
 
  private Moves currentBoard;
  private int color;


  /**
   * The maximum depth for the minimax-method
   */
  private static final int maxDepth = 3;

  /**
   * Weight of the fields of the board
   */

  private static final int tableWeight[] = { 5, 5, 5, 5, 5,
                                             5, 4, 4, 4, 4,
                                             4, 3, 3, 3, 5,
                                             5, 3, 2, 2, 4,
                                             4, 2, 1, 3, 5,
                                             5, 3, 1, 2, 4,
                                             4, 2, 2, 3, 5,
                                             5, 3, 3, 3, 4,
                                             4, 4, 4, 4, 5,
                                             5, 5, 5, 5, 5};
 
 
 
  /**
   * Constructor.
   * @param gameBoard The board, that the player uses for his moves
   */
  public Kater (Moves gameBoard) {
      currentBoard = gameBoard;
    //color = BLACK;
  }
  public Kater (){};

  /**
   * This method is called always, when it is the player's turn to move
   */
  public void play () {
    try {
      List moves = minimax (currentBoard);
      //int status = getManToJump();    
     
      if (!moves.isEmpty ())
        currentBoard.move (moves);
    }
    catch (BadMoveException bad) {
      bad.printStackTrace ();
      System.exit (-1);
    }
  }


  //public void setBoard (Moves board) {
  //  currentBoard = board;
  //}

  /**
   * Indicates if there is an available move to play
   */
  private boolean mayPlay (List moves) {
    return !moves.isEmpty () && !((List) moves.peek_head ()).isEmpty ();
  }
 

  /**
   * The minimax-strategy algorithm
   */
  private List minimax (Moves board) throws BadMoveException {
    List sucessors;
    List move, bestMove = null;
    Moves nextBoard;
    int value, maxValue = Integer.MIN_VALUE;

    sucessors = board.legalMoves ();
    while (mayPlay (sucessors)) {
      move =  (List) sucessors.pop_front ();
      nextBoard = (Moves) board.clone ();

      //Debug.println ("******************************************************************");
      nextBoard.move (move);
      value = minMove (nextBoard, 1, maxValue, Integer.MAX_VALUE);

      if (value > maxValue) {
        //Debug.println ("Max value : " + value + " at depth : 0");
        maxValue = value;
        bestMove = move;
      }
    }

    //Debug.println ("Move value selected : " + maxValue + " at depth : 0");

    return bestMove;
  }
 
  /**
   * Returns the most valuable move a player can make
   */
  private int maxMove (Moves board, int depth, int alpha, int beta)
   throws BadMoveException {
    if (cutOffTest (board, depth))
      return eval (board);


    List sucessors;
    List move;
    Moves nextBoard;
    int value;

    sucessors = board.legalMoves ();
    while (mayPlay (sucessors)) {
      move = (List) sucessors.pop_front ();
      nextBoard = (Moves) board.clone ();
      nextBoard.move (move);
      value = minMove (nextBoard, depth + 1, alpha, beta);

      if (value > alpha) {
        alpha = value;
      }

      if (alpha > beta) {
        return beta;
      }
 
    }

    return alpha;
  }

  /**
   * Returns the worst move a player can make
   */
  private int minMove (Moves board, int depth, int alpha, int beta)
   throws BadMoveException {
    if (cutOffTest (board, depth))
      return eval (board);


    List sucessors;
    List move;
    Moves nextBoard;
    int value;

   
    sucessors = (List) board.legalMoves ();
    while (mayPlay (sucessors)) {
      move = (List) sucessors.pop_front ();
      nextBoard = (Moves) board.clone ();
      nextBoard.move (move);
      value = maxMove (nextBoard, depth + 1, alpha, beta);

      if (value < beta) {
        beta = value;
      }

      if (beta < alpha) {
        return alpha;
      }
    }

    return beta;
  }

   /**
    * Evaluates the force of the current player
    */
   private int eval (Moves board) {
      int colorQueen;
      int enemy, enemyQueen;
     
      if (color == Moves.WHITE) {
        colorQueen = Moves.WHITE_QUEEN;
        enemy = Moves.BLACK;
        enemyQueen = Moves.BLACK_QUEEN;
      }
      else {
        colorQueen = Moves.BLACK_QUEEN;
        enemy = Moves.WHITE;
        enemyQueen = Moves.WHITE_QUEEN;
      }
     
      int colorForce = 0;
      int enemyForce = 0;
      int piece;

      try {
        for (int i = 0; i < 50;  i++) {
          piece = board.getPiece (i);
       
        if (piece != Moves.EMPTY)
           if (piece == color || piece == colorQueen)
             colorForce += calculateValue (piece, i);
           else
             enemyForce += calculateValue (piece, i);
        }
      }
      catch (BadCoordException bad) {
        bad.printStackTrace ();
        System.exit (-1);
      }

      return colorForce - enemyForce;
   }

   /**
    * It calculates the force of one stone
    */
   private int calculateValue (int piece, int pos) {
      int value;
     
      if (piece == WHITE ) //a simple stone
      if (pos >= 5 && pos <= 9)
          value = 7;
        else
          value = 5;
      else if (piece != BLACK) //a simple stone
      if (pos >= 40 && pos <= 44)
          value = 7;
        else
          value = 5;
      else // queen
      value = 10;

      return value * tableWeight[pos];
   }


  /**
   * Indicates if it can stop the process of evaluation of the best move
   */
  private boolean cutOffTest (Moves board, int depth) {
    return depth > maxDepth || board.hasEnded ();
  }


public String getAuthor() {
      // TODO Auto-generated method stub
      return "Vasil Vasilev & Oleksiy Slonimskyy";
}
public String getPlayerName(){
    return "Der gestiefelte Kater";
  }

public static void main (String[] args){
      Board board = new Board();
      Kater cat = new Kater();
      cat.play();
}

}
0
sciuriwareCommented:
Yes that's the file   Kater.java   in the directory kater.
But you are starting the file Kater.java 1 level higher.

That file should NOT have a package and read:

import kater.Kater;

public class Kater
{
      public static void main(String args[])
      {
            kater.Kater.main(args);
      }

}

// as I said before.

Besides that, I don't know who designed the whole program, but the
naming of some directories and files is confusing.
Now, let's try to start that top-level Kater.java
See what happens.

;JOOP!
0
keksyAuthor Commented:
java.lang.NoSuchMethodError: main
Exception in thread "main"
0
keksyAuthor Commented:
I am sure that I compile all the changes I make. I use the command  "javac.exe -classpath ..\chequers.jar *.java kater\*.java" to compile any changes,recently made, but I still get the same error...
I tried to make a new project in Eclipse - there I have a directory player, where all my source is. I am trying to avoid this stupid inheritance. I put the checkers.jar in the root, then my source in a folder player and compile everything with the command "javac.exe -classpath ..\chequers.jar *.java" from this folder. The compilation goes without any mistake and when I run Kater.java... AGAIN the f... mistake :(

I am knocked out! Really!

Can anybody help me, please... please :((
0
sciuriwareCommented:
What's the stacktrace = where does the Exception happen?

e.printStackTrace();

;JOOP!
0
keksyAuthor Commented:
I am leaving it like this! I just cannot take the project to the end :(
It's a pitty for whole this time - I was sitting almost day and night and spent my free time to write this and at the end - a lot of mistakes. This will teach me...

Anyway, you will alll the points from this! Please, post something in the "pointer" to give you the points from there too...

Thanks for you efforts!

Best!
0
sciuriwareCommented:
It's a pity that we didn't solve this problem.
Please, in the future, provide us with all error messages so that at least we can do more.

;JOOP!
0
keksyAuthor Commented:
I think I made my best to support solving the problem. I published my code, provided with erros and everything I made to troubleshoot and debug it. The StackTrace - actually I don't know how to implement it in my code, in order to provide the results from the trace :(
0
sciuriwareCommented:
catch(Exception e)
{
     e.printStackTrace();
}


;JOOP!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Game Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.