Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 4 (30marks) This question covers materials up to Seminar 5, excluding File. Apply data structures to store and process information and solve computational problems

Question 4 (30marks) This question covers materials up to Seminar 5, excluding File. Apply data structures to store and process information and solve computational problems using structured programming. The XO domino-tile game is played by 2 players using a square board. Players take turns to enter the coordinates of 2 EMTPY squares (row-col, row-col) to place their domino-tiles, until there is no possible move. We will illustrate the game using a 5x5 square board. 0 1 2 3 4 0 1 2 3 4

ICT133 Tutor-Marked Assignment SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 10 of 14 Employ structured programming to develop this game with the following playing rules: At start of the game, prompt for the following: o Two unique names representing the of 2 players. o Size of the game board, that must be odd number and at least 3. The computer randomly decides which player to start and will take the symbol X. The other player will take the symbol O. Each player in turn will place a domino-style tile that occupy 2 EMTPY squares. o Your program must validate the 2 squares that the player wanted to place the next tile. 0 1 2 3 4 0 X X O O 1 X 2 X O O 3 4 X X O O o In the above board, if a player enters 00 10 for his next tile, it is invalid as 00 is already occupied. o In the above board, if a player enters 11 12 for his next tile, it is invalid as 12 is already occupied. o If player enters 21 32 for his next tile, it is invalid as the 2 squares are not connected vertically or horizontally. Game ends when no player can place any more tile. Player with the most tiles on the board wins. If the result is a tie, repeat the game until a winner can be determined. Sample program executions are as follows: Enter player 1 name: Alan Enter player 2 name: Jane Size of game board: 5 0 1 2 3 4 0 - - - - - 1 - - - - - 2 - - - - - 3 - - - - - 4 - - - - - Jane, place your X tile: 01 21 Wrong tile coordinates!! Please re-enter Jane, place your X tile: 01 11 0 1 2 3 4 0 - X - - - 1 - X - - - 2 - - - - - 3 - - - - - 4 - - - - - Comments After displaying a new board, randomly decide who to start.

ICT133 Tutor-Marked Assignment SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 11 of 14 Alan, place your O tile: 11 21 Square occupied!! Please re-enter Alan, place your O tile: 31 21 0 1 2 3 4 0 - X - - - 1 - X - - - 2 - O - - - 3 - O - - - 4 - - - - - ... ... after many more placing of tiles ... ... Jane, place your X tile: 41 40 0 1 2 3 4 0 X X - X - 1 X X O X X 2 - O O - X 3 - O - O O 4 X X O O - Alan, place your O tile: 20 30 0 1 2 3 4 0 X X - X - 1 X X O X X 2 O O O - X 3 O O - O O 4 X X O O - Its a tie!! Rematch... 0 1 2 3 4 0 - - - - - 1 - - - - - 2 - - - - - 3 - - - - - 4 - - - - - Alan, place your X tile: 01 11 0 1 2 3 4 0 - X - - - 1 - X - - - 2 - - - - - 3 - - - - - 4 - - - - - Jane, place your O tile: 31 21 0 1 2 3 4 0 - X - - - 1 - X - - - 2 - O - - - 3 - O - - - 4 - - - - - After Alans tile, there are no more squares to fit another tile. Each player has 10 squares... Display a new board for rematch, and randomly decide who to start.

ICT133 Tutor-Marked Assignment SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 12 of 14 ... ... after many more placing of tiles ... ... Jane, place your O tile: 42 43 0 1 2 3 4 0 X X - X - 1 X X O X X 2 - O O - X 3 - O - O O 4 - - O O - Alan, place your X tile: 30 40 0 1 2 3 4 0 X X - X - 1 X X O X X 2 - O O - X 3 X O - O O 4 X - O O - Alan 10 Jane 8 Alan is the winner!! After Alans tile, there are no more squares to fit another tile. Declare Alan as the winner. Create the following functions as building blocks for the XO domino-tile game program: getNewBoard(size: int): list o This function should create and return a nested list based on the given parameter size, representing an empty game board. (Hint: each empty square is defaulted to -) printBoard(board: list) o This function displays the current game board, showing placed tiles location through X and O. getNextTile(playerName: string, symbol: string, size: int): string, string o This function prompts the player to enter the 2 squares to place the next domino-tile. o This function will validate and return the 2 squares (as 2 strings) if they are within the game board. Otherwise, the function will prompt the player to re-enter the 2 squares. validateTile(square1: string, square2: string, size: int): Boolean o This function takes in 3 parameters: square1, square2 (e.g., 00, 01) and the size of the board. The function should return True if the given square1 and square2 can form a valid domino-tile. Otherwise, returns False. o For example, validateTile(00, 01, 5) returns True validateTile (00, 20, 5) returns False validateTile (00, 11, 5) returns False placeTile(board: list, symbol: string, square1: string, square2: string): Boolean o This function returns True if square1 and square2 can be updated with the given symbol. In other words, square1 and square2 are empty for the next tile to be placed. ICT133 Tutor-Marked Assignment SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 12 of 14 ... ... after many more placing of tiles ... ... Jane, place your O tile: 42 43 0 1 2 3 4 0 X X - X - 1 X X O X X 2 - O O - X 3 - O - O O 4 - - O O - Alan, place your X tile: 30 40 0 1 2 3 4 0 X X - X - 1 X X O X X 2 - O O - X 3 X O - O O 4 X - O O - Alan 10 Jane 8 Alan is the winner!! After Alans tile, there are no more squares to fit another tile. Declare Alan as the winner. Create the following functions as building blocks for the XO domino-tile game program: getNewBoard(size: int): list o This function should create and return a nested list based on the given parameter size, representing an empty game board. (Hint: each empty square is defaulted to -) printBoard(board: list) o This function displays the current game board, showing placed tiles location through X and O. getNextTile(playerName: string, symbol: string, size: int): string, string o This function prompts the player to enter the 2 squares to place the next domino-tile. o This function will validate and return the 2 squares (as 2 strings) if they are within the game board. Otherwise, the function will prompt the player to re-enter the 2 squares. validateTile(square1: string, square2: string, size: int): Boolean o This function takes in 3 parameters: square1, square2 (e.g., 00, 01) and the size of the board. The function should return True if the given square1 and square2 can form a valid domino-tile. Otherwise, returns False. o For example, validateTile(00, 01, 5) returns True validateTile (00, 20, 5) returns False validateTile (00, 11, 5) returns False placeTile(board: list, symbol: string, square1: string, square2: string): Boolean o This function returns True if square1 and square2 can be updated with the given symbol. In other words, square1 and square2 are empty for the next tile to be placed.

ICT133 Tutor-Marked Assignment SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 13 of 14 o The function returns False if either square1 or square2 are not empty. isGameAlive(board: list): Boolean o This function should look through the board and return True if there are still 2 vertically linked or horizontally linked EMPTY squares on the board to allow the next domino-tile to be placed. Otherwise, returns False. You will need to code other functions to complete the program. Paste screenshots of game play that covers these scenarios: Player entering wrong coordinates (not empty, wrong row/column etc.) Player wanted to place next tile in occupied square(s). Game finishes with a winner. Game repeats when the result is a tie. Game with a different game board size. (30 marks)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

Students also viewed these Databases questions

Question

How does compound interest differ from simple interest?

Answered: 1 week ago

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago