Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Problems with a player for Checkers

Posted on 2006-04-03
28
Medium Priority
?
458 Views
Last Modified: 2013-12-26
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
0
Comment
Question by:keksy
  • 13
  • 12
  • 2
  • +1
28 Comments
 
LVL 20

Expert Comment

by:ikework
ID: 16365040
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
 

Author Comment

by:keksy
ID: 16365642
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
 
LVL 20

Assisted Solution

by:ikework
ikework earned 40 total points
ID: 16365689
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 86

Expert Comment

by:CEHJ
ID: 16368597
Please post the stack trace of the exception
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 16368904
>>> 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
 

Author Comment

by:keksy
ID: 16369084
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
 
LVL 24

Expert Comment

by:sciuriware
ID: 16369221
>>> "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
 

Author Comment

by:keksy
ID: 16372682
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
 
LVL 24

Expert Comment

by:sciuriware
ID: 16372835
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
 

Author Comment

by:keksy
ID: 16372927
I do not get your point... :(
And what kind of GUI are you looking for?  Under GUI I mean the board...
0
 

Author Comment

by:keksy
ID: 16373866
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
 
LVL 24

Expert Comment

by:sciuriware
ID: 16374179
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
 

Author Comment

by:keksy
ID: 16374537
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
 
LVL 24

Expert Comment

by:sciuriware
ID: 16378570
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
 

Author Comment

by:keksy
ID: 16380344
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
 
LVL 24

Expert Comment

by:sciuriware
ID: 16380650
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
 
LVL 24

Expert Comment

by:sciuriware
ID: 16380663
And don't curse the computer: the poor thing is always right.

;JOOP!
0
 

Author Comment

by:keksy
ID: 16386356
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
 
LVL 24

Expert Comment

by:sciuriware
ID: 16389332
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
 

Author Comment

by:keksy
ID: 16393110
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
 
LVL 24

Expert Comment

by:sciuriware
ID: 16393282
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
 

Author Comment

by:keksy
ID: 16395263
java.lang.NoSuchMethodError: main
Exception in thread "main"
0
 

Author Comment

by:keksy
ID: 16396493
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
 
LVL 24

Expert Comment

by:sciuriware
ID: 16398051
What's the stacktrace = where does the Exception happen?

e.printStackTrace();

;JOOP!
0
 

Author Comment

by:keksy
ID: 16434865
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
 
LVL 24

Expert Comment

by:sciuriware
ID: 16435334
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
 

Author Comment

by:keksy
ID: 16437835
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
 
LVL 24

Accepted Solution

by:
sciuriware earned 460 total points
ID: 16438210
catch(Exception e)
{
     e.printStackTrace();
}


;JOOP!
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month20 days, 23 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question