Solved

Can anyone assist me in how to proceed to solve this peg game.........

Posted on 2004-09-29
7
198 Views
Last Modified: 2010-03-31
Hi Guys,

 Am writing a program for a game called peg game.

 If u want to know what peg game is, then go to this link : http://www.crackerbarrel.com/games.cfm?doc_id=42

 If given suggestions, then it would be really helpful to me.

Thanks
aman

0
Comment
Question by:amankhan
  • 4
7 Comments
 
LVL 4

Accepted Solution

by:
funnyveryfunny earned 250 total points
Comment Utility
I would approach the game this way:

1) The layout of the game: I see the layout as rows of squares built into a triangle like this

                    |(0,0)|
               |(1,0)||(1,1)|
          |(2,0)||(2,1)||(2,2)|
     |(3,0)||(3,1)||(3,2)||(3,3)|
|(4,0)||(4,1)||(4,2)||(4,3)||(4,4)|

with each square has a unique coord(i,j).

With this layout, a JUMP iS VALID if and only if one of these statements is true:

let say a jump from (i,j) --> (i',j') is valid iff

1) i' = i+2 && j' = j && notEmpty(i+1,j)
2) i' = i+2 && j' = j+2 && notEmpty(i+1,j+1)
3) i' = i+2 && j' = j-2 && notEmpty(i,j-1)
4) i' = i && j' = j+2 && notEmpty(i,j+1)
5) i' = i-2 && j' = j && notEmpty(i-1,j)
6) i' = i-2 && j' = j-2 && notEmpty(i-1,j-1)

....
0
 
LVL 4

Expert Comment

by:funnyveryfunny
Comment Utility
The above comment is the internal working of game...the next step is provide a visual look to it.

I would prefer to use Canvas class as my graphics output.

For each square/cell, we can create a class to hold its data

class Cell{
   boolean isEmpty;
   Coordination(i,j);
   Point(x,y) // screen coordinate for drawing
   ....etc
}

so a game contains a collection of these cells and manipulate as neccessary.

That's how I would do it.
0
 
LVL 4

Expert Comment

by:funnyveryfunny
Comment Utility
correction

1 ) i' = i+2 && j' = j && notEmpty(i+1,j)
  or
2) i' = i+2 && j' = j+2 && notEmpty(i+1,j+1)
  or
3) i' = i+2 && j' = j-2 && notEmpty(i,j-1)
  or
4) i' = i && j' = j+2 && notEmpty(i,j+1)
  or
5) i' = i-2 && j' = j && notEmpty(i-1,j)
  or
6) i' = i-2 && j' = j-2 && notEmpty(i-1,j-1)
0
 

Author Comment

by:amankhan
Comment Utility
Thanx a lot funnyveryfunny..

 Am tryin this program with the logic u privided to me. If i have any doubts , i will ask u

bye
0
 
LVL 4

Expert Comment

by:funnyveryfunny
Comment Utility
Another thing, you need a method that checks whether a game is finished - no more moves.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

763 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now