Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-09-29
7
Medium Priority
?
236 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
7 Comments
 
LVL 4

Accepted Solution

by:
funnyveryfunny earned 1000 total points
ID: 12184839
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
ID: 12184922
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
ID: 12184978
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
ID: 12205558
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
ID: 12216064
Another thing, you need a method that checks whether a game is finished - no more moves.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

715 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