473,394 Members | 1,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Creating peg solitaire game in C++?

1
The peg solitaire is in a triangular shape. Consisting of 15 pegs.

I'm just curious as to how it is programmed and I'm starting to learn C++ on my own. So how would I do such a puzzle on C++?

I'm looking forward to making a program that would solve the puzzle upon user prompting.

If anyone has the code or something about it. It would be nice.
Sep 29 '11 #1
2 5738
Rabbit
12,516 Expert Mod 8TB
The simplest solution is to read every possible move until you find the winning one(s).
Sep 29 '11 #2
weaknessforcats
9,208 Expert Mod 8TB
There would be several ways to do this. However, let's assume you just want this particular solitare game.

First you start by envisioning main(). Then tou add classes and methods to support using the objects in main().

For example, in main():

1) create the game object. Now you need a class + constructors for the number of pegs. Inside this class you create your gameboard and load it with pegs.
2) drop into a loop
3) call the "win" method on the game object. Ihe
Hint: now you know you need a class with a method that returns true if the game is won (i.e. one peg left) and false otherwise.
4) if "win" is false, call the "move" method on the game object other wise exit the loop since the game is won. "move" returns true on a valid move and fase otherwise.
5) if "move" fails ask for another move"
6) back to top of loop

You may want to display your peg trangle so the game class should also have a display method to show rhe current state of the gameboard.
Maybe X's for pegs and O's for open holes.

Good luck.
Oct 1 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Moosebumps | last post by:
When I have time, I am planning to evaluate Python for console game development (on Playstation 2, GameCube, and Xbox). Does anyone have any experience with this? Pretty much the only resource...
9
by: the_philospher | last post by:
I am a beginner programmer learning c++. i have read some useful information about programming games (which is my goal) on gamedev.net, particularly "how do i program games"...
4
by: Ismadi bin Nawang | last post by:
how to solve this problem. "activeX component can't create object" its happened when i want to create a new form in ms access.
4
by: simduss | last post by:
Hi, First of all, I'm a beginner with Unix. I have a "make" (Unix command) problem with a Pro*C sub-program since I installed Oracle8i (before I was at 7.3.4). I have a script builder that...
2
by: Brian Hampson | last post by:
I'd like to be able to create either AVI, MPG, or MOV from a series of JPGS (BMPS, etc). I have no clue about where to start, or what to do. I've tried Googling, but to no avail :( Please...
1
by: LinkaBlack | last post by:
i m designing a solitaire ame in c++......i dont have to use graphics....just use data structure n cmd for out....for the game....i m done with the making of all the classes to b used n the basic...
5
by: Ronald S. Cook | last post by:
I need ideas on how to best design a Windows form for my particular situation. On a cattle feeding yard there will be between about 300 and 600 pens. On my "Pen Feeding Sequence" form, I want...
16
by: Mich | last post by:
Hi, i'm building an web application for anonymous users. They can take a look in the website, nothing more. In order to perform other actions, the anonymous user must be logged. So i create an...
4
by: themadme | last post by:
Im about to create a group project and are unsure what type of game to make. Anyone that have any ideas what type game would make a big hit
80
by: tech | last post by:
Hi, i have the following problem In file1.h namespace A { class Bar { void foo();
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.