19:167 LTE O learn-ap-southeast-1-prod-fleet02-xy e rse Code: CSC11540 (2019-20, Term 1) Page 5 of 6 5. (20%) In the game of

19:167 LTE O learn-ap-southeast-1-prod-fleet02-xy e rse Code: CSC11540 (2019-20, Term 1) Page 5 of 6 5. (20%) In the game of chess, a queen can move any number of unoccupied squares in a straight line vertically, horizontally, or diagonally on the chessboard. Therefore, two op- position queens can attack each other if they lie on the same row, same column, or same diagonal with no other pieces between them. E.g., the following shows a chessboard with two opposition queens (‘Q’ and ‘q’) attacking each other as they lie on the same diagonal. colo 1 2 3 4 5 6 7 . . . . . . . In this question, we use a two-dimensional 8 x 8 char array to model a chessboard, in which denotes an unoccupied square and ‘Q’ and ‘q’ denote the two opposition queens. Write a program (file name: 05.cpp) with a function bool attackingQueens (const char board [] [8]) which returns true if the following conditions are all satisfied: • there are only two pieces left on the chessboard board; • the two pieces left on board are exactly two opposition queens; and • the two opposition queens attack each other on the chessboard. Otherwise, the function shall return false. Note: • You are not allowed to use any functions in the library. • What you write in the main() function is unimportant. It can contain code to test the required function. We shall grade only the required function.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *