# Enter Two Adjacent Location Suap Enter Two Adacent Location Sap Question 1 30 Marks Figure Q31355909

Enter the two adjacent location to suap Enter the two adacent location to sap Question 1 (30 marks) Figure Qlii) Apply C+language to program a puzzle game The puzzle involves arranging a set of thirty- six numbers in an ascending order. The numbers are displayed in a 6×6 grid. These numbers are randomly generated and therefore are not sorted initially. The player has to sort these numbers by swapping two adjacent numbers onc at a timc. A number can bc swapped with another number on its right, left, top or bottom. A number cannot be swapped with a number that is diagonally adjacent to it. Figure Q1 (a)(ii) shows the result if the player has successfully sorted the numbers. Figure Q1(i) shows a sample initial screen of the game with the 36 randomly generated numbers arranged in a 6×6 grid. any key to cerntinue You are required to implement the puzzle game with the following specifications: (a) The program should randomly generate thirty-six number. Different set of numbers (5 marks) (b) The program displays the thirty-six numbers in a 6×6 grid. Each number should be (5 marks) should be displayed each time the program is started. Figure Qli For example, if the number 5461 is to be moved, then i can be swapped with either the number 2118 (top). 218 (bottom), 5397 (left), or 8145 (right). Any illegal swapping will result in an crror mcssagc bcing displaycd. Figurc Q1(ii) shows the rcsult of playcr swapping the numbers 5461 and 218 in a partially sorted manner enclosed in an ASCII box (c)The program should prompt the playcr to swap two adjacent numbers. It should check for illegal moves i.e. if the two numbers are not adjacent to each other either horizontally or vcrtically. It should display an crror message if the move is not allowed. (5 marks) Show transcribed image text Enter the two adjacent location to suap Enter the two adacent location to sap Question 1 (30 marks) Figure Qlii) Apply C+language to program a puzzle game The puzzle involves arranging a set of thirty- six numbers in an ascending order. The numbers are displayed in a 6×6 grid. These numbers are randomly generated and therefore are not sorted initially. The player has to sort these numbers by swapping two adjacent numbers onc at a timc. A number can bc swapped with another number on its right, left, top or bottom. A number cannot be swapped with a number that is diagonally adjacent to it. Figure Q1 (a)(ii) shows the result if the player has successfully sorted the numbers. Figure Q1(i) shows a sample initial screen of the game with the 36 randomly generated numbers arranged in a 6×6 grid. any key to cerntinue You are required to implement the puzzle game with the following specifications: (a) The program should randomly generate thirty-six number. Different set of numbers (5 marks) (b) The program displays the thirty-six numbers in a 6×6 grid. Each number should be (5 marks) should be displayed each time the program is started. Figure Qli For example, if the number 5461 is to be moved, then i can be swapped with either the number 2118 (top). 218 (bottom), 5397 (left), or 8145 (right). Any illegal swapping will result in an crror mcssagc bcing displaycd. Figurc Q1(ii) shows the rcsult of playcr swapping the numbers 5461 and 218 in a partially sorted manner enclosed in an ASCII box (c)The program should prompt the playcr to swap two adjacent numbers. It should check for illegal moves i.e. if the two numbers are not adjacent to each other either horizontally or vcrtically. It should display an crror message if the move is not allowed. (5 marks)