Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask C/C++ Expert


Home >> C/C++

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

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M91610319
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in C/C++

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As