Related questions
Topics
- Classes
- Methods
- Data Collections: Lists, Tuples, and Dictionaries
- String Manipulation
Chess
Objective: practicing with classes, instance methods, data collections, loops, if and elif statements, and string methods
Description
In this assignment you will write a program that shows the valid moves of chess pieces. Your program will draw a board with 64 squares using the traditional layout, next ask the user to choose a move, and then, depending on the user's choice, redraw the board with the selected chess piece and its valid moves. Please see the examples of valid moves of chess pieces and the traditional chess board layout below:
At the beginning, your program should draw an empty chess board and prompt the user to enter a move:
Welcome to the Chess Game!
a b c d e f g h
+---+---+---+---+---+---+---+---+
8| | | | | | | | |8
+---+---+---+---+---+---+---+---+
7| | | | | | | | |7
+---+---+---+---+---+---+---+---+
6| | | | | | | | |6
+---+---+---+---+---+---+---+---+
5| | | | | | | | |5
+---+---+---+---+---+---+---+---+
4| | | | | | | | |4
+---+---+---+---+---+---+---+---+
3| | | | | | | | |3
+---+---+---+---+---+---+---+---+
2| | | | | | | | |2
+---+---+---+---+---+---+---+---+
1| | | | | | | | |1
+---+---+---+---+---+---+---+---+
a b c d e f g h
Enter a chess piece and its position or type X to exit:
A move is represented as a three-letter string where the first letter corresponds to a chess piece initial: K stands for king, Q - queen, B - bishop, N - knight, and R - rook (a chariot). Pawns do not have initials, and you will not be tested on their implementation. The next letter in the move is the position on the board that corresponds to one of eight columns (called files). The columns (files) are labeled as a, b, c, d, e, f, g, h. The third symbol is a digit that corresponds to one of eight rows (called ranks). The rows (ranks) are labeled as 1, 2, 3, 4, 5, 6, 7, 8. For example, if the user enters Re6, your program should generate the following output where R is the initial for a rook, and all possible moves of the rook are marked by x:
a b c d e f g h
+---+---+---+---+---+---+---+---+
8| | | | | x | | | |8
+---+---+---+---+---+---+---+---+
7| | | | | x | | | |7
+---+---+---+---+---+---+---+---+
6| x | x | x | x | R | x | x | x |6
+---+---+---+---+---+---+---+---+
5| | | | | x | | | |5
+---+---+---+---+---+---+---+---+
4| | | | | x | | | |4
+---+---+---+---+---+---+---+---+
3| | | | | x | | | |3
+---+---+---+---+---+---+---+---+
2| | | | | x | | | |2
+---+---+---+---+---+---+---+---+
1| | | | | x | | | |1
+---+---+---+---+---+---+---+---+
a b c d e f g h
Enter a chess piece and its position or type X to exit:
If the user enters Kd5, your program should produce the following output where K is the initial for the king, and all squares where the king can move are marked with x:
a b c d e f g h
+---+---+---+---+---+---+---+---+
8| | | | | | | | |8
+---+---+---+---+---+---+---+---+
7| | | | | | | | |7
+---+---+---+---+---+---+---+---+
6| | | x | x | x | | | |6
+---+---+---+---+---+---+---+---+
5| | | x | K | x | | | |5
+---+---+---+---+---+---+---+---+
4| | | x | x | x | | | |4
+---+---+---+---+---+---+---+---+
3| | | | | | | | |3
+---+---+---+---+---+---+---+---+
2| | | | | | | | |2
+---+---+---+---+---+---+---+---+
1| | | | | | | | |1
+---+---+---+---+---+---+---+---+
a b c d e f g h
Enter a chess piece and its position or type X to exit:
If the user does not enter a valid move that is included in all possible combinations of chess piece initials (K, Q, B, N, R), files (a, b, c, d, e, f, g, h), and ranks (1, 2, 3, 4, 5, 6, 7, 8), then the program should reprint the prompt:
Enter a chess piece and its position or type X to exit:
If the user enters X (or x), then the program should print 'Goodbye!' and terminate:
Goodbye!
NOTE: The user can use either upper or lowercase letters, for example X or x should result in the termination of the program, Ke3, KE3, kE3, or ke3 means the same move.
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps
- Use Java programming language Write a program that asks the user to enter 5 test grades (use an array to store them). Output the grades entered, the lowest and highest grade, the average grade, how many grades are above the average and how many are below and the letter grade for the average grade. Create a method that returns the lowest grade. Create a method that returns the highest grade. Create a method that returns the average grade. Create a method that returns how many grades were above the average. Create a method that returns how many grades were below the average. Create a method that returns the letter grade of the average (90-100 – A, 80-89 – B, 70-79 – C, < 70 – F)arrow_forwardMicrofost Visual C# 7th edition programming exercise 6-10. I need help, please. This problem relies on the generation of a random number. You can create a random number that is at least min but less than max using the following statements: Random ranNumberGenerator = new Random();int randomNumber;randomNumber = ranNumberGenerator.Next(min, max); Create a game similar to Hangman named GuessAWord in which a player guesses letters to try to replicate a hidden word. Store at least eight words in an array, and randomly select one to be the hidden word. Initially, display the hidden word using asterisks to represent each letter. Allow the user to guess letters to replace the asterisks in the hidden word until the user completes the entire word. If the user guesses a letter that is not in the hidden word, display an appropriate message. If the user guesses a letter that appears multiple times in the hidden word, make sure that each correct letter is placed. Figure 6-27 shows a typical game...arrow_forwardQ1. amount the same, y, n, why? public class CheckingAct { private String actNum; private String nameOnAct; private int balance; . . . . public void processDeposit( int amount ) { balance = balance + amount ; } // modified toString() method public String toString() { return "Account: " + actNum + "\tName: " + nameOnAct + "\tBalance: " + amount ; } } Q2. amount the same, y, n, why? public class CheckingAct { private String actNum; private String nameOnAct; private int balance; . . . . public void processDeposit( int amount ) { // scope of amount starts here balance = balance + amount ; // scope of amount ends here } public void processCheck( int amount ) { // scope of amount starts here int charge; incrementUse(); if ( balance < 100000 ) charge = 15; else charge = 0; balance = balance - amount - charge ; // scope of amount ends here }...arrow_forward
- PYTHON CODE Reza Enterprises sells tickets for buses, tours, and other travel services. Because Reza frequently mistypes long ticket numbers, Reza Enterprises has asked his students to write an application that shows if a ticket is invalid. Your application/program tells the ticket agent to enter a six-digit ticket number. Ticket numbers are designed so that if you lose the last digit of the number, then divide by 7, the remainder of the division is exactly the same to the last dropped digit. This process is shown below: Step 1: Enter the ticket number; for example 123454 Step 2: Remove the last digit, leaving 12345 Step 3: Determine the remainder when the ticket number from step 2 is divided by 7. In this case, 12345 divided by 7 leaves a remainder of 4. Step 4: Display a message to the ticket agent indicating whether the ticket number is valid or not. If the ticket number is valid, save the number to a .txt file called "tickets.txt" and continue to loop your program asking...arrow_forwardRecursive Power MethodWrite a method called powCal that uses recursion to raise a number to a power. The method should accept two arguments: The first argument is the exponent and the second argument is the number to be raised (example" powCal(10,2) means 210). Assume that the exponent is a nonnegative integer. Demonstrate the method in a program called Recursive (This means that you need to write a program that has at least two methods: main and powCal. The powCal method is where you implement the requirements above and the main method is where you make a method call to demonstrate how your powCal method work).arrow_forward✓ Exercises Exercise: Write a method _ and _ that computes the region representing the intersection of two regions. Exercise: Write a method _contains__, which checks whether a n-dimensional point belongs to the region. Remember, a point belongs to the region if it belongs to one of the rectangles in the region. ✓ Membership of a point in a region #@title Membership of a point in a region def region_contains (self, p): ### YOUR SOLUTION HERE Region._contains = region_contains [ ] # Tests 10 points. assert (2, 1) in Region (Rectangle((0, 2), (0, 3)), Rectangle((4, 6), (5,8))) assert (2, 1) not in Region (Rectangle((0, 1), (0, 3)), Rectangle((4, 6), (5, 8))) Exercise: Write a method _le_ for regions such that R <= S if the region R is contained in the region S. You can test this by checking that the difference between R and S is empty.arrow_forward
- C++ language pleasearrow_forwardCharge Account Validation Using Java programming Create a class with a method that accepts a charge account number as its argument. The method should determine whether the number is valid by comparing it to the following list of valid charge account numbers:5658845 4520125 7895122 8777541 8451277 13028508080152 4562555 5552012 5050552 7825877 12502551005231 6545231 3852085 7576651 7881200 4581002These numbers should be stored in an array. Use a sequential search to locate the number passed as an argument. If the number is in the array, the method should return true, indicating the number is valid. If the number is not in the array, the method should return false, indicating the number is invalid.Write a program that tests the class by asking the user to enter a charge account number. The program should display a message indicating whether the number is valid or invalid.arrow_forwardpython multiple choice Code Example 4-1 def get_username(first, last): s = first + "." + last return s.lower() def main(): first_name = input("Enter your first name: ") last_name = input("Enter your last name: ") username = get_username(first_name, last_name) print("Your username is: " + username) main() 5. Refer to Code Example 4-1: What is the scope of the variable named s ?a. globalb. localc. global in main() but local in get_username()d. local in main() but global in get_username()arrow_forward
- Using C# create a console app doing the following Write a method that takes two integers and displays their sum. Write a method that takes five doubles and returns their average. Write a method that returns the sum of two randomly generated integers. Write a method that takes three integers and returns true if their sum is divisible by 3, false otherwise. Write a method that takes two strings and displays the string that has fewer characters. Write a method that takes an array of doubles and returns the largest value in the array. Write a method that generates and returns an array of fifty integer values. Write a method that takes two bool variables and returns true if they have the same value, false otherwise. Write a method that takes an int and a double and returns their product. Write a method that takes a two-dimensional array of integers and returns the average of the entries.arrow_forwardComputer Science Part C: Interactive Driver Program Write an interactive driver program that creates a Course object (you can decide the name and roster/waitlist sizes). Then, use a loop to interactively allow the user to add students, drop students, or view the course. Display the result (success/failure) of each add/drop.arrow_forwardGrocery List. When shopping for groceries, it's helpful to know how much it's going to cost you in advance - this helps you avoid an embarrassing situation in the check-out line. For this assignment, you're going to write a simple program that asks you for the name, quantity, and price of two grocery store items. It will then generate a grocery list for you, complete with the total price. (Later in the semester, we'll learn how to make a program that can create much larger lists, but we'll start small here). Call the file Assignment1B (with a file extension of .cpp, .cs or .java) Sample Output: What're you buying? Ice Cream How many? 2 What do they cost? 2.25 What else're you buying? Celery How many? 5 What do they cost? 1.74 Your list: Ice Cream (2) 2ドル.25 (4ドル.50 total) Celery (5) 1ドル.74 (8ドル.7 total) Total Cost: 14ドル.2 using Java programmingarrow_forward
- Text book imageComputer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONText book imageComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceText book imageNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Text book imageConcepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningText book imagePrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationText book imageSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY