Question

In: Computer Science

OBJECTIVE: In the second assignment, you started coding the NineGaps game by creating the skeleton of...

OBJECTIVE: In the second assignment, you started coding the NineGaps game by creating the skeleton of the program including the loops, inputs/outputs, and some conditions without going to the details of the game. In this third assignment, we are going to complete the game by coding the details, using what we learned so far, especially working with arrays. YAY! At the end of this assignment, we can actually play with the very first game that we created by ourselves (at least for some of us!). Here You Go…! Complete the NineGaps game: Problem 1: Simulating a two-dimensional array using one-dimensional array. In COMP-1400, we only talk about one-dimensional arrays, and two-dimensional (or more) arrays will be discussed in COMP-1410. However, in NineGaps game, we need to have a table of digits as well as table of operators for the game board. In this problem we would like to simulate a two-dimensional array using a one-dimensional array. For instance, to create a n by m table (a table with n rows and m columns) of digits, we need to create a one-dimensional array with size of n*m. Therefore, row 0 and column 0 of the table (black color) will be represented by position 0 of our array. Or row 1 and column 1of the table (yellow color) will be mapped to the cell#4 in our array. Or row 3 and column 0 of the table (dark blue) is represented by cell#9 in our array. The first step to simulate the process is to find and implement the mapping rule. Assuming we want to add an integer value in a particular row and column of the table, where 0. The language is C.

Solutions

Expert Solution

If you wanted to ask on how to simulate 2d array using 1d array then here is the solution.

If the 2d array is of size n x m, then the 1d array will be of size [nxm] as shown below:

Given: row number(i), column number(j)

Then the position in 1d array of these coordinates (i,j) will be calculated as follows:

where, 1dPosition is position in 1d array, i is row index given, j is column index given, m is totol number of columns in 2d array.

For eg. Let n=3, m=4 then

It can be validated as follows:

  • i=0, j=0 -> 1dPosition = 0*4 + 0 = 0
  • i=0, j=1 -> 1dPosition = 0*4 + 1 = 1
  • ...
  • i=1, j=0 -> 1dPosition = 1*4 + 0 = 4
  • i=1, j=1 -> 1dPosition = 1*4 + 1 = 5
  • ...
  • i=n-1, j=m-1 -> 1dPosition = (n-1)*m + (m-1) = n*m - m + m - 1 = n*m - 1

as expected.

If you need more than this, you may write in the comment section.


Related Solutions

LAUNGEG: C# Objective: For this assignment you will be creating two classes, an interface, and a...
LAUNGEG: C# Objective: For this assignment you will be creating two classes, an interface, and a driver program: Class Calculator will implement the interface CalcOps o As such it will implement hexToDec() - a method to convert from Hexadecimal to Decimal. Class HexCalc will inherit from Calculator. Interface CalcOps will have abstract methods for add( ), subtract( ), multiply( ) and divide( ). Both classes will implement the CalcOps interface. o Class Calculator’s add, subtract, multiply and divide will take...
c++ Programming Assignment 1: Game of Life The objective of this programming assignment is to design...
c++ Programming Assignment 1: Game of Life The objective of this programming assignment is to design and implement what is known as the “Game of Life”, conceptualized by the British mathematician John Horton Conway in 1970 to simulate the evolution patterns in a population of living organisms.   The game board is seeded with an initial population pattern, and then evolves based on the set of rules defining when a cell dies or is born into life. A cell’s life cycle...
The objective of this assignment is to implement the tic-tac-toe game with a C program. The...
The objective of this assignment is to implement the tic-tac-toe game with a C program. The game is played by two players on a board defined as a 5x5 grid (array). Each board position can contain one of two possible markers, either ‘X’ or ‘O’. The first player plays with ‘X’ while the second player plays with ‘O’. Players place their markers in an empty position of the board in turns. The objective is to place 5 consecutive markers of...
You and your team of software developers are creating a game for children. The game has...
You and your team of software developers are creating a game for children. The game has different types of animals. As a team of software developers, create in a 1-page Word document the class "Animal," including appropriate methods and properties that are common to all animals, subclasses of Animal, such as Cats, Dogs, and Birds, and appropriate methods and properties unique to these subclasses.
Simple code for a game on C coding.
Simple code for a game on C coding.
The second weekly assignment for the course is an open forum. In this assignment you task...
The second weekly assignment for the course is an open forum. In this assignment you task is to find an economic news topic and summarize the article in your post. The purpose of this assignment is to give you a free hand in the subject you wish to discover. The news article can come from any widely known news site such as BBC, Bloomberg, CNBC, Fox Business, MarketWatch, Wall Street Journal, etc. If this does not offer you enough options,...
The objective of this lab is to practice your Verilog coding and the design of a...
The objective of this lab is to practice your Verilog coding and the design of a Finite State Machine. Lab Goal: For this lab, you will code a Verilog module to implement the FSM described in this document. This lab will also require that you use the Seven - Segment Display on the DE0 - CV FPGA board. Design Specifications for the FSM Implem ent the following simple state machine on the DE0 - CV FPGA board. This FSM will...
Chicago is a group dice game that requires no skill. The objective of the game is...
Chicago is a group dice game that requires no skill. The objective of the game is to accumulate points by rolling certain combinations (GamezBuff, 2017). How do you play Chicago? There are eleven rounds in the game, one for each combination that can be made by adding two dice, namely the numbers two through 12. Each round has a target combination starting with two and going up all the way to 12. Going clockwise, the players take turns to roll...
Chicago is a group dice game that requires no skill. The objective of the game is...
Chicago is a group dice game that requires no skill. The objective of the game is to accumulate points by rolling certain combinations (GamezBuff, 2017). How do you play Chicago? There are eleven rounds in the game, one for each combination that can be made by adding two dice, namely the numbers two through 12. Each round has a target combination starting with two and going up all the way to 12. Going clockwise, the players take turns to roll...
Objective Make a function to serve as a Craps dice game simulator. If you are not...
Objective Make a function to serve as a Craps dice game simulator. If you are not familiar Craps is a game that involves rolling two six-sided dice and adding up the total. We are not implementing the full rules of the game, just a function that returns the value of BOTH dice and their total. Details In the function you create: Make a function that uses pointers and pass by reference to return THREE separate outputs (arrays are not allowed)....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT