Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

in python . Solitaire Peg Game. Overview:In this program, you will implement a version of the game of Peg Solitaire. It is played on a

in python

image text in transcribed

. Solitaire Peg Game. Overview:In this program, you will implement a version of the game of Peg Solitaire. It is played on a rectangular grid of holes. Some of the holes will have pegs in them and some will not. On a turn, the player can jump a peg A over another peg B (in a horizontal or vertical fashion), if there is a space just after B and this space is unoccupied. Peg B is then removed from the board (but peg A stays). The user does this tll she has no moves, the goal being to have as few pegs left as possible (having just one left is the best possible under some configurations) Requirements: You must 1) create a class named PegSolitaire, which will be described below, 2) create other classes as needed, which will all be known by the top level class PegSolitaire, 3) write a simple console application (no graphics!) that uses the class PegSolitaire, with a few simple method calls, to create an interactive game of Peg Solitaire In the following discussion, by a position we mean a tuple (X, Y), where X and Y are positive integers; a position is meant to refer to a location on the board. The class PegSolitaire, must have at least the following methods it may have more methods) (a) The initializer takes two positive integer arguments X and Y. This creates a X by (b) placePeg: Takes integer arguments X and Y, and places a peg at row X and (c) removePeg: Takes integer arguments X and Y, and removes a peg at row X and Y grid of holes as the playing board. column Y column Y (d) jumpPeg: Takes two positions and attempts to move the peg at the first position to the location indicated by the second position. If the move is legal, it is carriecd out, along with all appropriate adjustments to the board, and True is returned If there is anything that forbids this move, the the method does not change the board, and returns False (e) isStuck: Takes no inputs, and returns True if there are no possible moves left, and False if there are possible moves (f) display: This creates a text output of the current state of the board. It should just be a grid of letters with the character "P for a hole occupied by a peg, and X" for a hole not occupied by a peg. An example of a possible result of display on a 2 by 3 board: XPP PXP

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students explore these related Databases questions