• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help regarding basic AI design for a turn based game.  RSS feed

 
Sam Kaydee
Greenhorn
Posts: 12
Android Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone! This is my first post so do correct me if i do something wrong..

Okay so we were told to design a basic AI for a turn based game much similar to Archimede's Chess. There is a 8X8 board and each side has 6 pieces numbered from 1-6. One of them is the King and the rest are pawns.
King can move 1block either vertically or horizontally and have power =2.
Pawns can move 1block in any direction and have power =1. Further there are 4 blockers placed randomly to block certain blocks.
At the 0th turn the King has to be appointed [mandatory] and no other action can be taken.

Killing Rules:
1.A piece will only be taken if it is surrounded by more enemies than friends i.e the summation of power of enemy is greater than summation of power of friends. [here surrounded means the immediate neighboring blocks]
2. At a time only one piece can be killed.
3. Game ends if the King is defeated or after 25 turns.

What I have done:
My logic is simple.
Check the neighboring cells, if ally present then move forward else move towards direction of ally.

This way my pieces will stay in cluster so they wont be taken easily and in case a opponent comes within range it will be killed because my piece will most likely be surrounded by more allies. (This does not have a very high probability of success,but this is what I came up with...suggestions are verry welcome!!]
This is the method which runs the pieces:


This method checks for neighbours:


P.S: All the movement are already defined as moveTop(),moveBottom(),moveTopLeft() etc
VarGame.w.setKing(piece number) sets the king.
VarGame.w.getTurnNo() gives the currnt turn.
VarGame.w.warriorLocations returns a 6X4 matrix with col1= piece number,col2=row address,col3=column address,col4=power
Problem:
Now I'm having problem at keeping track of the turns.The code runs till appointing the king and the next command but does not move further .
Also it would be nice if you have some suggestions as i'm new to this and your experience will be very valuable!!.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you know the moveTop call is executed but the moveBottom line isn't ?
Are you running the code through a debugger ? Have you got print statements in your moveTop and moveBottom methods ? Somethine else ?
 
Sam Kaydee
Greenhorn
Posts: 12
Android Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have been given a simulator to check our code..it's basically a java applet. I just have to run the applet to see the results.
A demo code is also given which will control the opponent.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what do the results show ? Is it actually returning from the moveTop method ?
Your program is obviously stuck somewhere - either in the moveTop method or possibly in the moveBottom method but before any output has been generated.
You will need to debug your program to find out where. Either run it through a debugger or add more print statements to those two methods.
 
Sam Kaydee
Greenhorn
Posts: 12
Android Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joanne Neal wrote:So what do the results show ? Is it actually returning from the moveTop method ?
Your program is obviously stuck somewhere - either in the moveTop method or possibly in the moveBottom method but before any output has been generated.


The method moveTop() moves an animated piece one block forward in the applet window and i don't think that it it stuck in the methods because this is not specific to the moveTop() or moveBottom() method. It is executing only the first command of the else block (line 11) whatever i use there is executed.
And about the methods we dont have access to those,we can use them but cannot modify anything in them.

P.S: Only one action can be taken in a turn so when (turn!=0) it goes into the else part and executes the first line.. is it like that?? if yes how can i get past it.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Kaydee wrote:Only one action can be taken in a turn so when (turn!=0) it goes into the else part and executes the first line.. is it like that?? if yes how can i get past it.

If the moveTop method is executed, then the only way the moveBottom method won't be executed is if the moveTop method never returns (due to an infinite loop or some blocking i/o call) or if it throws an exception.
Without seeing the moveTop method, there's not much more help you can be given.
 
Sam Kaydee
Greenhorn
Posts: 12
Android Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joanne Neal wrote:
Without seeing the moveTop method, there's not much more help you can be given.


Here is the moveTop() method:
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those last two lines look very suspect.
The Thread.stop method is deprecated and its use advised against as it is inherently unsafe. See this for more information.
And as you are not actually running it in a separate thread as far as I can tell, it is probably the main thread of execution that you are stopping.*
You then go and call another method on the thread you have just stopped (System.gc), which sounds very unwise. It may be that Thread.stop causes this to be skipped, but I would be very suspicious of that code.

The first thing I would try is to remove those two lines. If this is not possible then I would check with whoever wrote them whether you are using them correctly.

*Edit: I just noticed the code is in a method called run so you may be executing it in a separate thread, but if you are stopping the thread in the moveTop method then it's not really surprising that none of the remainder of the code is being run.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!