Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In c++ . Make a board with chess pieces, there is a single white piece in the bottom left space, the top right space is

Inc++.

Make a board with chess pieces, there is a single white piece in the bottom left space, the top right space is blank, and the rest of the spaces each contain a black piece. let the user move the pieces, the objective of the game is to get the white piece to the empty square in the smallest moves.

The piece can only move in a valid L-shape, following one of these two paths:

two squares in a horizontal direction, and one in a vertical direction OR

two squares in a vertical direction, and one in a horizontal direction.

The goal of the game is to try to help the piece escape in the smallest moves possible. The game keeps track of a score, which decreases as the user makes more moves. Invalid moves result in a score penalty as well. See the samples of output shown on this page to determine how the score should be used and displayed throughout the game.

1.The score starts at 500.

2.The current score should be displayed with each move.

3.If the user makes any type of invalid move, the scoredecreases 10 points.

4.If the user makes a valid move, the scoredecreases 5 points.

5.Once the score becomes zero or negative, the game automatically ends. See Note below for the message that should be displayed when this occurs.

Output Messages: See the samples of output shown on this page to make sure your output exactly matches the spacing and blank lines needed to pass the test cases.

1.No matter the input or program behavior, at the very end your program should display: Thank you for playing!

2.When the user enters \'x\' or \'X\' to exit the program, your program should display: Exiting...

3.When the user enters \'r\' or \'R\' to restart the program, your program should display: *** Restarting

4.When the source position is not a valid position on the board, your program should display: The source position should be a valid position on the board (1-25). Try again.

5.When the destination position is not a valid position on the board, your program should display: The destination position should be a valid position on the board (1-25). Try again.

6.When the source position does not contain a piece, your program should display: The source position should have a piece. Try again.

7.When the destination position is not empty, your program should display: The destination position should be empty. Try again.

8.When the piece is not being moved in a valid L-shape, your program should display: Invalid move. pieces can only move in an L-shape. Try again.

9.When the user wins the game, your program should display an extra blank line and then the message: Congratulations, you did it!

10.When the user reaches a score less than or equal to zero, your program should display the score, an extra blank line and then the message: You have run out of moves. Try to do better next time!

NO ARRAYS OR VECTORS

*** will thumbs down if not follow instruction

**************USE THE Code given******************:

#include #include using namespace std;

// Global variables for the pieces are allowed for this program,

// Characters of the pieces to be used on the board

const string WhiteKnight = \"\\u2658\"; const string BlackKnight = \"\\u265E\"; const string BlankPosition = \" \"; void displayWelcomeMessage() { cout < \"the=\"\" objective=\"\" of=\"\" this=\"\" puzzle=\"\" is=\"\" to=\"\" get=\"\" the=\"\" white=\"\" knight=\"\"> < \"up=\"\" to=\"\" the=\"\" empty=\"\" square=\"\" in=\"\" the=\"\" top=\"\" right=\"\" corner=\"\" of=\"\" the=\"\" board.=\"\"> < \"use=\"\" standard=\"\" knight=\"\" moves=\"\" from=\"\" a=\"\" traditional=\"\" chess=\"\" game,=\"\"> < \"where=\"\" a=\"\" knight=\"\" moves=\"\" in=\"\" an=\"\" l-shape.=\"\"> < \"this=\"\" means=\"\" that=\"\" a=\"\" knight=\"\" can=\"\" only=\"\" move=\"\" either=\"\"> < \"1)=\"\" two=\"\" squares=\"\" in=\"\" a=\"\" horizontal=\"\" direction,=\"\" then=\"\" one=\"\" in=\"\" a=\"\" vertical=\"\" direction,=\"\" or=\"\"> < \"2)=\"\" two=\"\" squares=\"\" in=\"\" a=\"\" vertical=\"\" direction,=\"\" then=\"\" one=\"\" in=\"\" a=\"\" horizontal=\"\"> < \"=\"\"> < \"your=\"\" score=\"\" decreases=\"\" by=\"\" 5=\"\" with=\"\" each=\"\" valid=\"\" move,=\"\" and=\"\" by=\"\" 10=\"\" with=\"\" each=\"\" invalid=\"\" move.=\"\"> <> } // ---------------------------------------------------------------------- // Display the current board, along with the corresponding positions // This function makes use of global variables p1..p25, which represent // each of the positions on the board void displayBoard() { cout <> \" Board \" \" Position \" < \"=\"\" \"=\"\"> p1 < \"=\"\" \"=\"\"> p2 < \"=\"\" \"=\"\"> p3 < \"=\"\" \"=\"\"> p4 < \"=\"\" \"=\"\"> p5 <> 1 2 3 4 5 \" < \"=\"\" \"=\"\"> p6 < \"=\"\" \"=\"\"> p7 < \"=\"\" \"=\"\"> p8 < \"=\"\" \"=\"\"> p9 < \"=\"\" \"=\"\">< p10=\"\"><> 6 7 8 9 10 \" < \"=\"\" \"=\"\">< p11=\"\">< \"=\"\" \"=\"\">< p12=\"\">< \"=\"\" \"=\"\">< p13=\"\">< \"=\"\" \"=\"\">< p14=\"\">< \"=\"\" \"=\"\">< p15=\"\"><> 11 12 13 14 15 \" < \"=\"\" \"=\"\">< p16=\"\">< \"=\"\" \"=\"\">< p17=\"\">< \"=\"\" \"=\"\">< p18=\"\">< \"=\"\" \"=\"\">< p19=\"\">< \"=\"\" \"=\"\">< p20=\"\"><> 16 17 18 19 20 \" < \"=\"\" \"=\"\">< p21=\"\">< \"=\"\" \"=\"\">< p22=\"\">< \"=\"\" \"=\"\">< p23=\"\">< \"=\"\" \"=\"\">< p24=\"\">< \"=\"\" \"=\"\">< p25=\"\"><> 21 22 23 24 25 \" <> } //end displayBoard() // ---------------------------------------------------------------------- // Main() function of the program int main() { displayWelcomeMessage(); // Set board values to the default starting position displayBoard(); // Loop that controls game play while(...) { cout < movenumber=\"\">< \".=\"\"> < \"enter=\"\" one=\"\" of=\"\" the=\"\" following:=\"\"> <> - M to move a knight from one position to another, \" <> - R to reset the board back to the beginning, or \" <> - X to exit the game. \" < \"your=\"\" choice=\"\" -=\"\"> \"; cin >> menuOption; menuOption = toupper(menuOption); // convert user input to uppercase // If the user entered \'X\' to exit, // break out of this loop that controls game play // ... // If the user entered \'R\' to reset, // reset the board back to the beginning // ... // If the user entered \'M\' to move a knight, // ask for the position of the knight to be moved // ... // Check that FROM position is valid, i.e. within 1-25 // Check that TO position is valid, i.e. within 1-25 // Check that the source position has a knight // Check that the destination position is empty // Check that the move is valid - knights can only move in an L-shape // Make the move and update the board } // end loop for game play // Check for a win // ... cout < \"thank=\"\" you=\"\" for=\"\" playing!\"=\"\"><> return 0;

}

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

Step: 3

blur-text-image

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

Entrepreneurship

Authors: Andrew Zacharakis, William D Bygrave

5th Edition

1119563097, 9781119563099

More Books

Students also viewed these Programming questions