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

  Write a c++ statement that multiplies the value

Write a program that prompts the user to input a decimal number and outputs the number rounded to the nearest integer.

  Determine an appropriate functional decomposition

Create structure charts for a problem and determine an appropriate functional decomposition or top-down design from a structure chart

  Build a table of reynolds numbers at flow velocities

Write a program code to compute and build a table of Reynolds numbers at flow velocities varying from 100 to 1000 ft/sec (at increments of 100)

  Consists of an employee''s last name

Each input line consists of an employee's last name, first name, current base salary, total sales and percent commission. For example, in the first input line, the last name of the employee is Thomas, the first name is Andrew, the current base salary..

  Calculates the exact integral over the interval

Write your program so that it outputs the interval entered, the exact solution, the approximation, the number of trapezoids and the difference between the exact and approximate solutions - trapezoids increases the approximate result converges to th..

  Write a header for the function named subtract

Write a header for the function named subtract. Subtract returns nothing and has one double parameter named num.

  Method celsius return celsius equivalent of fahrenheit

Method Celsius return the Celsius equivalent of a Fahrenheit temperature,using the calculation Celsius = 5.0/9.0*(Fahrenheit -32); method Fahrenheit returns the Fahrenheit equivalent of a Celsius temperature, using the calculation  Fahrenheit = 9.0/5..

  Create a procedure that returns the last n items in the list

Create a procedure that returns the last n items in the list lst. Create a procedure called (combine-four lst1lst2 lst3 lst4) that combines 4 lists into one list, in order of the given input lists.

  The keyboard and display on the screen

Use the readLn and writeStr functions to read from the keyboard and display on the screen. Your function to convert from a decimal text string to an int should be placed in a separate function. this problem cannot be solved by simply shifting bit pat..

  Prepare a new int[] variable and inititialize it

Prepare a new int[] variable and inititialize it to be a new int array with the given size to create random values use the random class import javautil.random inside the method create a new instance with: Random rand = new Random();

  Which of the following is a true statement

Which of the following is a true statement?

  Produce a c program to calculate the total price for order

Your friend has just opened a computer appliances shop at Changloon. He asked your help to develop a computer program which can be used at the counter. Your program should be able to input the customer's order which could be more than one item. Produ..

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