• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?




 
Saloon Keeper
Posts: 15528
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
1.jpg
[Thumbnail for 1.jpg]
Tiger and goat Game
2.jpg
[Thumbnail for 2.jpg]
After Few steps
 
Ranch Hand
Posts: 287
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic