BIT 142 A3 Posttest:                                                     (For ‘2D Arrays)

If you were given this test to do at home, then please pay attention to the following rules:

·        You need to do this on your own.  No asking for help, no using the internet, no using books or notes.  Use only what you've got in your head.  DO NOT USE VISUAL STUDIO (or any variation thereof, like the Visual C# Express/XNA Game Studio Express), or anything else that will 'help' you write your code.

·        When you're done, email your answer to the professor, by attaching this file directly to your email.

·        If you do not complete this, and email this to the professor by the specified due date, you will receive a 10 point penalty on Assignment 1!!

 

Summary: Create a small C# program that will "follow a line" within a two-dimensional array.

 

Details: Your code will be given an already allocated, already setup two-dimensional array, as well as the (X,Y) coordindate of one cell that is at the start of the line.  Your code will produce, as it's final answer, the (X,Y) coordinate of the  cell that is at the other end of the line.  A picture of a typical example of how the 2D array might look is given below.  Note that you will be given an array of bool primitives.  If the array cell is part of the line, then it will have the value 'true' (indicated by a cell with the letter 'T' in the picture below).  If the array cell is NOT on the line, it will have the value false (indicated by a cell with the letter 'F' in the picture below.

In the following example, your code might be given the 2D array, and the coordinate (0, 7), which is the top-left corner in the picture, and your code would be expected to produce the answer (6,2).  As a side note, your code could just as easily be given the coordinate (6,2), and be expected to produce the answer (0,7).

 

7

T

T

F

F

F

F

F

F

6

F

F

T

F

T

T

T

F

5

F

F

T

F

T

F

T

F

4

F

T

F

F

T

F

T

F

3

T

F

F

T

F

F

T

F

2

T

F

T

F

F

F

T

F

1

T

T

F

F

F

F

F

F

0

F

F

F

F

F

F

F

F

 

0

1

2

3

4

5

6

7

At this point, you should have a clear, intuitive idea of what this problem entails, and what you'll need to do to write the code.  Before you start, here are a couple of points to clarify, in case you had any questions.  First, the line will never branch, nor cross itself, but the line may move diagonally.  Secondly, the line doesn't have to start (or end) on the edge of the array - in the above example (6,2) isn't on the edge, visually speaking.  Thirdly, YOUR ARE NOT ALLOWED TO MODIFY THE ARRAY.  You also aren't allowed to do anything that is equivalent to modifying the array (such as cloning the array, and modifying the clone, or allocating any other arrays to get yourself an equivalent amount of space).

           Write your answer here:

 Line

Program Text

1.       

using System;

2.       

namespace ConsoleApplication1

3.       

{

4.       

    class Program

5.       

    {

6.       

        static void Main(string[] args)

7.       

        {

8.       

            bool[,] board = new bool[7, 7]; // If you happen be given a 7x7, 2D array….

9.       

            int xCoordinate = 0; // If the starting point is (0,7), then this will be 0

10.    

            int yCoordinate = 7; // and this will be 7

11.    

          

12.    

 

13.    

 

14.    

 

15.    

 

16.    

 

17.    

 

18.    

 

19.    

 

20.    

 

21.    

 

22.    

 

23.    

 

24.    

 

25.    

 

26.    

 

27.    

 

28.    

 

29.    

 

30.    

 

31.    

 

32.    

 

33.    

 

34.    

 

35.    

 

36.    

 

37.    

 

38.    

 

39.    

 

40.    

 

41.    

 

42.    

 

43.    

 

44.    

 

45.    

 

46.    

 

47.    

 

48.    

 

49.    

 

50.    

 

51.    

 

52.    

 

53.    

 

54.    

 

55.    

 

56.    

 

57.    

 

58.    

 

59.    

 

60.    

 

61.    

 

62.    

 

63.    

 

64.    

 

65.    

 

66.    

 

67.    

 

68.    

 

69.    

 

70.    

 

71.    

 

72.    

 

73.    

 

74.    

 

 This document and the related materials are developed with support from Microsoft Research Computer Gaming Initiative under the Computer Gaming Curriculum in Computer Science RFP, Award Number 15871.