BIT 142 A3 Pretest:                                                       (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: Given a 2D array, fill in a game-board so it'll have a checker pattern, like a board for a game of checkers.

 

Details: Your code will be provided with a two-dimensional array of integers (ints) that represents a 'checkers board', and variable named size, which is the width (in cells/squares) of the board (since the board will always be square, you don't need a separate variable for the height). 

The board hasn't been initialized yet, which is what your code will do.  When your code is done, the board needs to look like the one pictured in Figure 1, with the top-left corner being represented at (0, size-1), and having the value 1 (to indicate the color blue).  The value 2 will be used to indicate the color green ; you will need to assign a value (and thus, a color) to every square/cell on the board - you cannot assume that the board has been initialized in any way. 

In order to give you a feel for how a differently sized board might look, Figure 2 has been provided for the case of a 5x5 board.

 

7

1

2

1

2

1

2

1

2

6

2

1

2

1

2

1

2

1

5

1

2

1

2

1

2

1

2

4

2

1

2

1

2

1

2

1

3

1

2

1

2

1

2

1

2

2

2

1

2

1

2

1

2

1

1

1

2

1

2

1

2

1

2

0

2

1

2

1

2

1

2

1

 

0

1

2

3

4

5

6

7

Figure 1: An 8x8 board
(The value that your code should assign to the cell is written in the cell)

4

1

2

1

2

1

3

2

1

2

1

2

2

1

2

1

2

1

1

2

1

2

1

2

0

1

2

1

2

1

 

0

1

2

3

4

Figure 2: A 5x5 board

 

 

 

 

 

 

 

           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.       

            int size = 8;

9.       

            int[,] board = new int[size, size]; // this is the 2D array

10.    

            // Write your code below, so that the array is initialized

11.    

            // as described above.

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.    

 

75.    

 

Note to the instructor:

 

Probably the easiest solution is to walk across each row, and then assign flip-flop on the values being assigned.  The Modulus operator might make this easier, too.


 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.