File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Game Development and the fly likes How to store possible movements? and which is the best way? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Game Development
Bookmark "How to store possible movements? and which is the best way?" Watch "How to store possible movements? and which is the best way?" New topic
Author

How to store possible movements? and which is the best way?

Surya Prakash Raju
Greenhorn

Joined: Dec 25, 2011
Posts: 2
Please help me regarding this.

I am developing a game which is similar to chess. It is a two player game. Now i am developing the task "User Against computer".

calculated possibility of movements. The value is exceding 2GB to store.

How to store possible movements? and which is the best way?




Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3378
    
    9
Welcome to CodeRanch!

You shouldn't store possible moves. You should calculate them on the fly instead. Of course you can use some sort of cache on the file system (like an opening book, in Chess) to improve the performance of the program, but you definitely shouldn't store everything.
Surya Prakash Raju
Greenhorn

Joined: Dec 25, 2011
Posts: 2
Hi Stephan,

Happy new Year.

Could you please give an example?

First off all I want to explain description about this game.

Description: Tiger and Goat Game
This is a two player game in which 4 Tigers (Which is in Yellow Color) and 18 Goats (Which is in Block Color) try to overpower the other. The tigers kill the goats whenever they find goats alone and try to overpower them where as Goats move strategically to contain Tigers movements and try to leave no room for Tigers to move.

While starting game Tigers will be in the template and Goats will be Out of the template. The Player who is having goats will start the game first. Then opponents will play tigers. Here I am passing "If in case of Computer play with goats, Placing the goat in right place in the template" is the main problem.

Thank You.



[Thumbnail for 1.jpg]


[Thumbnail for 2.jpg]

Mich Robinson
Ranch Hand

Joined: Jun 28, 2009
Posts: 250
    
    1
Surya Prakash Raju wrote:How to store possible movements? and which is the best way?
Looking up the game on the web showed a square board rather than the triangular one you're using. This sort of board is much easier to represent as it's a simple array where each place can hold a value indicating the point is free, holds a tiger or holds a goat. More importantly it's easy to find out which points every other point is connected to.

You then just need a recursive method that loops through each move for either goats or tigers and then calls itself to try out the moves for the other side. You'll also need a scoring method to say whether one outcome is better than another. The moves are quite simple for tigers, just look for the first tiger in the array and then try each connected point that's free. Once you've moved the tiger then call the method again but this time for the goats. The moves for goats is the same as tigers if all the goats have been placed otherwise you just look for a free point to place your goat.

Once you've looked so many moves ahead then you can score the resulting position to see whether the outcome is good. You'll need to lookup minmax (or alphabeta) algorithms to understand how the score for the position is passed back. Once you've scored each move just play the best move.

Surya Prakash Raju wrote:I am developing a game which is similar to chess. It is a two player game.
I'm guessing the fact it's a 2 player game is the only similarity with chess or am I missing something?


Arcade : Alien Swarm
Board : Chess - Checkers - Connect 4 - Othello
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to store possible movements? and which is the best way?
 
Similar Threads
Conceptual approach: financial software
Using a timer
Looking at basic game design
Game developement
Is this possible...?