Program that allows two human players to play the chess

Assignment Help C/C++ Programming
Reference no: EM13939445

In this project, you will build a program that allows two human players to play the game of checkers. Your program will graphically maintain the state of the game board and prompt the players for moves on the standard input/output. Your program will also know the rules of checkers, and will check the validity of moves to maintain the integrity of the game board as the game progresses.

1 Rules of Checkers (slightly modified for this project)

Checkers is played on an 8 by 8 grid, or "checker board," with alternating dark and light squares. The board starts with 12 red and 12 white pieces, each situated on the 12 dark squares at opposing ends of the board. (Actually, the entire game is played on the dark squares only). Players take turns making moves, with the player of the red pieces moving first. Two kinds of moves are allowed. A player can "step" a piece one square diagonally if the diagonally adjacent square is unoccupied. Alternatively, if a player's piece is next to an opponent's piece, and the square beyond it is free, the player can "jump" over the opponent's piece onto the unoccupied square. The opponent's piece is removed from the board after the jumping move.

In the beginning, pieces can only move and jump forward. However, if a piece reaches the far end of the board, then it becomes a "king." A king is allowed to move and jump diagonally backwards and forwards. Kings can be captured like any other piece.

2. Maintaining the Game Board

Your checkers game should maintain the state of the game board, and print it to standard output using text characters. The squares of the board should be printed using the '-' and '|' characters; the row and column numbers of the board squares should be printed above and to the left of the board; and squares containing pieces should be labeled "r" and "w" for normal red and white pieces, respectively, and "R" and "W" for red and white pieces that are kings. For example, at the very beginning of the game (before any moves have been made), the board should look like:

0 1 2 3 4 5 6 7
|---|---|---|---|---|---|---|---|
0 | | r | | r | | r | | r |
|---|---|---|---|---|---|---|---|
1 | r| | r | | r | | r | |
|---|---|---|---|---|---|---|---|
2 | | r | | r | | r | | r |
|---|---|---|---|---|---|---|---|
3 | | | | | | | | |
|---|---|---|---|---|---|---|---|
4 | | | | | | | | |
|---|---|---|---|---|---|---|---|
5 | w | | w | | w | | w |
|---|---|---|---|---|---|---|---|
6 | | w | | w | | w | | w |
|---|---|---|---|---|---|---|---|
7 | w | | w | | w | | w | |
|---|---|---|---|---|---|---|---|

3 Moving Pieces

Your checkers program should prompt each player for a move, alternating between the red and white pieces. For example, if it's the red pieces' turn to move, your program should say:

RED's move:

At the prompt, your program should expect the corresponding player to enter 4 numbers: the first 2 numbers specify the column and row, in that order (i.e., an x-y coordinate), of a square containing the piece to move, and the second 2 numbers specify the column and row of an empty square to move to. After a valid move is entered (see Section 4), your program should update the state of the game board, print the updated game board, and then prompt the opposing player for the next move.

4 Verifying Moves

After a player enters a move, but before the game board is updated, your program should verify that the move entered is a valid move. Your program should check several conditions:
1. The move should originate from and terminate to squares on the board (i.e., the move should stay on the 8x8 grid).

2. The originating square must contain a piece belonging to the player making the move, while the terminating square must be empty.

3. The move must be a legal stepping move or jumping move. A legal stepping move must move 1 square away along a diagonal. Normal pieces can only move in the "forward direction" (for red, this means towards increasing y coordinates, and for
white, this means towards decreasing y coordinates); kings can move in both the forward and backward directions.

4. A legal jumping move must move 2 squares away along a diagonal with the "jumped" square containing an opponent's piece. Similar to stepping moves, normal pieces can only jump in the forward direction; kings can jump in both the forward and backward directions.

If a move meets all these conditions, it is a valid move, and your program should update the game board accordingly. (For jumping moves, this includes removing the piece that was jumped). Otherwise, your program should discard the move, print the error message
"INVALID MOVE. TRY AGAIN!!", and prompt the same player for another move. Re-
prompting continues until a valid move is entered.
(Note, in the official rules of checkers, if a player can perform a jump, only a jumping move is valid. You do not have to enforce this rule in your program. Even if the player can make a jumping move, either a stepping move or jumping move is valid.)

5 Kings

Whenever a normal piece lands on a square in the far row of the board (rows 7 and 0 for red and white pieces, respectively), the piece becomes a king. When this happens, your program should capitalize the letter used to represent the piece on the game board (i.e., change "r" to "R" and "w" to "W" for red and white pieces, respectively). As described earlier, kings can step and jump in both the forward and reverse directions.

6 Multiple Jumps

The official rules of checkers allows a player to jump many times in a row with the same piece, capturing several of the opposing pieces on the same turn. This is known as "multiple jumps." You are not required to implement multiple jumps in this project. After a player makes a jumping move, you should assume the player's turn is over, and you should prompt the opposing player for a move.

7 Termination

Normally, a game of checkers ends when a player captures all of his/her opponent's pieces, or until all of a player's pieces are blocked so that they cannot move. In this project, you do not need to detect these game-ending conditions. Instead, your program should simply process moves, alternating between players. You may assume this continues forever. (Eventually, one player may capture all of another player's pieces, but you can assume this never happens).

A possible strategy is to implement the project's functionality in the following order:

-Print the game board
- Implement stepping moves for normal pieces
- Verify move conditions 1, 2, and 3 for normal pieces
- Implement jumping moves for normal pieces
- Verify move condition 4 for normal pieces
- Implement kings (stepping and jumping moves)
- Update your move verification for conditions 1, 2, 3, and 4 to handle kings

Reference no: EM13939445

Questions Cloud

Discuss the purpose of correlational designs : From the video, discuss the purpose of correlational designs and the findings from the video regarding cell phone use. Do you think it was appropriate for the researchers to use correlational design? Why or why not
Appointing a new pr agency for your company : You are part of the selection committee appointing a new PR agency for your company. What would your agenda be for the interviews?
General principles of ethical research : After reading through the general principles of ethical research listed below, you can select which situation you would like to write about in a reflection paper. Based on the general principles, you must explain how you feel about the situation, ..
Explain key factors that addressed future health care worker : Health care organizations are facing many challenges from various regulatory and government agencies. For insight, to the challenges of health care reform, view the video "College of Nursing and Health Care Professions: Do we know what our future ..
Program that allows two human players to play the chess : The official rules of checkers allows a player to jump many times in a row with the same piece, capturing several of the opposing pieces on the same turn.
Statements must be true about securities : Stock A's beta is 1.7 and Stock B's beta is 0.7. Which of the following statements must be true about these securities? (Assume market equilibrium.)
How much cash inflow per year can be expected : If the internal rate of return is 14 percent for Thomas Company, how much cash inflow per year can be expected? Determine the investment and the amount of cash savings realized each year for Video Repair.
Discount interest tax shields at unlevered cost of equity : After reading all about the tax advantages of having a high leverage ratio, the CEO of LevCo is considering a leveraged recapitalization and wants to know the value of his firm subsequent to the recap. The firm currently has $27 million in assets and..
Market rate of return on similar securities : Farrowtech currently does not pay a dividend and they have announced to the market that they will not pay a dividend for the next ten years. However, analysts expect that they will pay their first dividend of $3.66 in eleven years and they feel that ..

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Program to find the factors

Write a c++ program to find the factors of an integer (entered by the user) which are themselves squares.

  A file (complex.txt) which has a number of complex numbers

Read in a file (complex.txt) which has a number of complex numbers in the form of a+bi (e.g. 3+5i  2-3i etc).

  Read in data from an input file (qstr.txt).

It will print the output and say that it is NOT palindrome which leads me to believe it is missing something somehow.

  What is the line of code doing?

What is the line of code doing?

  Create a program that outputs the result of the formula

Create a program that uses the same formula above to output the result; this time, however, prompt the user for the values a, b, x, and y. Use appropriate variable names and naming conventions.

  A program that takes into account a pre given array

Problem: A program that takes into account a pregiven array and prompts the user to enter a return per minute value.

  Which respectively represent the name of the flower

Write a C++ class, Flower, that has three member variables of type string, int, and float, which respectively represent the name of the flower, its number of pedals, and price.

  Skills required by personnel working in information security

What skills are required by personnel working in information security? Write down some job titles in the field and come up with some required qualifications and some desirable qualifications.

  Search the maximum number from a list of numbers

Write a function to search the maximum number from a list of numbers:

  Write a recursive function that takes a string as parameter

Write a recursive function that takes a string as a parameter and prints its reversal in the same function in c++

  Direct cost variance analysis

Problem 2: Direct Cost Variance Analysis  Ken Co. uses standard costing for accounting. Following is the standards for production of its only product:Direct material: 18 pounds at $25 per pound

  Design a web page displaying list of hyperlinks

Write HTML code to design a web page displaying list of hyperlinks. Divide the browser screen into two frames. The frame on the left will be an image. The frame on the right will be a menu consisting of hyperlinks.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd