aspose file tools*
The moose likes Game Development and the fly likes Turn Based Strategy Games Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "Turn Based Strategy Games" Watch "Turn Based Strategy Games" New topic
Author

Turn Based Strategy Games

Kabir Shah
Ranch Hand

Joined: Aug 04, 2009
Posts: 125
Here is bugged version of my code..


The error is required int , found gomuko.Move
No idea about this error.
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679



Ok I straightened out the code a bit, but it does the same thing, which is to say it is all wrong. But you are on the right track.

1. You have a compile problem line 13 tries to assign a Move object to an integer variable. This is a no-no.

2. Why are you thinking about a two dimensional array of moves? A position is a two dimensional array of integers (piece codes), a move list is one dimensional array of Move objects. Each element of of your moveList (Each Move object) has two components, a row and a column co-ordinate. The value of the row and column co-ordinate of each Move object will be the row and column co-ordinates of those position elements that have value zero. see what I mean?

3. You should also define a Move object. I will help you with that. I could use a two dimensional array of integers instead of a list of Move objects, but I feel that later on we will need a move object.



Kabir Shah
Ranch Hand

Joined: Aug 04, 2009
Posts: 125



Actually what should I do with that list1[i]
Here its again telling me the same thing.I guess I am missing a basic thing.
more over there should be two parameters for Move(int , int)
I got the first thing, that is i.

I chose the move matrix as 2d array because one variable can be used for row and other for column.
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Gurudas Bhandarkar wrote:


Actually what should I do with that list1[i]
Here its again telling me the same thing.I guess I am missing a basic thing.
more over there should be two parameters for Move(int , int)
I got the first thing, that is i.

I chose the move matrix as 2d array because one variable can be used for row and other for column.


Honestly Gurudas, you are not even close. In your possible moves method you are not even looking at the position. How do you expect to come up with a list of possible moves without looking at the position.

Give it another try.
Kabir Shah
Ranch Hand

Joined: Aug 04, 2009
Posts: 125
Honestly Gurudas, you are not even close. In your possible moves method you are not even looking at the position. How do you expect to come up with a list of possible moves without looking at the position.

Give it another try.


I didn't understand what you told. Can you make it a bit clearer?
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Gurudas Bhandarkar wrote:
Honestly Gurudas, you are not even close. In your possible moves method you are not even looking at the position. How do you expect to come up with a list of possible moves without looking at the position.

Give it another try.


I didn't understand what you told. Can you make it a bit clearer?


You tell me. In your possibleMoves method, where is your reference to the position array? You have to check the position array to see which squares are empty.
Kabir Shah
Ranch Hand

Joined: Aug 04, 2009
Posts: 125


now as I missed earlier, I made a copy of posn as a 1d array.

I have commented the other methods so that I can only focus on possibleMoves method

so for reference is the entire class.

also added a button but it gives me an exception of Null-Pointer

Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
can you provide the complete output of the error message for Null Pointer Exception?
Kabir Shah
Ranch Hand

Joined: Aug 04, 2009
Posts: 125
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at gomuko.GameTable.actionPerformed(GameTable.java:118)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6041)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5806)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4413)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4243)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
at java.awt.Container.dispatchEventImpl(Container.java:2102)
at java.awt.Window.dispatchEventImpl(Window.java:2440)
at java.awt.Component.dispatchEvent(Component.java:4243)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)


GameTable.java
Engine.java
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Gurudas Bhandarkar wrote:Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at gomuko.GameTable.actionPerformed(GameTable.java:118)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6041)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5806)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4413)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4243)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
at java.awt.Container.dispatchEventImpl(Container.java:2102)
at java.awt.Window.dispatchEventImpl(Window.java:2440)
at java.awt.Component.dispatchEvent(Component.java:4243)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)


GameTable.java
Engine.java


please show me your actionPerformed() method from the GameTable class, since that is where the error occurs. Make sure you mark which line is #118, since the numbering will change if you just post the method.

p.s. never mind I see you have posted links to the code

ok the problem is you have not instantiated the Engine class, therefore the object being referred to as comp does not yet exist.
Kabir Shah
Ranch Hand

Joined: Aug 04, 2009
Posts: 125
Yes the same problem does exist. and even one thing i wanted to talk about is the evaluate function.
The function is meant for checking N in row where N is number of matrix. so if N=6, then it doesn't have to see if it connects 6 or not. But (as per gomoku). and to win to get 5 in row.

so just modified the code,am I correct.
Here is the code.

where the X variable is defined to look win if there are X in row.
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
No, you are not correct. Your evaluate checks for the existence of 5 disks in the same row column or diagonal, it does not check to see that they are consecutive.

I will not respond to any more questions about GoMoku. I already told you twice the evaluate() function for GoMoku is much more difficult.

I can help you with NxN tictactoe. You have yet to get that working, and if you can't get that working you have no hope of doing GoMoku.
Kabir Shah
Ranch Hand

Joined: Aug 04, 2009
Posts: 125
Ok so lets concentrate on NxN tic tac toe but then it would be an easy draw everytime, the computer tactics would not be visible if its N to connect. on NxN board as the opponent just have put onr piece in each row, column and diagonal. so I wanted it to be something like 4-5 to connect on say 12x12 board or 13x13 board so there would be enough forks available for the players.
Kabir Shah
Ranch Hand

Joined: Aug 04, 2009
Posts: 125
Not able to fix up the possibleMove(), please help if you have free time.
Kabir Shah
Ranch Hand

Joined: Aug 04, 2009
Posts: 125
Now that we are done with the board and gui of NxN tic tac toe, can you please take the step where we add the computer moves?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Turn Based Strategy Games
 
Similar Threads
JApplet
problem with program hanging
TicTacToe in Java
synchronization.. and threads !!!
The lovely tic tac toe implementation!