Simple Navigation (INDIVIDUAL)

 

Write a simple navigation program that calculates legal moves within a 10 by 10 grid.  Assume that the squares in the grid are numbered as indicated in the diagram below.  It is not legal to move off any side of the grid (i.e. moving north from square 5).  Additionally, the user should be able to define squares which it is illegal to move to, though you may assume that it is legal to move from those squares.  In the diagram below a sample set of user defined illegal squares have been marked in gray.  In this example it would illegal to move north from square 24 or west from square 15, as these would be moves onto an illegal square, but it would be legal to move south from square 15, as that would be a move onto a legal square.

 

                              North

1

2

3

4

5

6

7

8

9

10

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

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

 

Prompt the user for the set of illegal squares.  Then use a loop to allow the user to enter multiple desired moves and indicate whether or not those are legal.  Desired moves should be provided in terms of the current square number, the orientation on that square (north, south, east, or west), and the desired direction relative to that orientation (straight, back, left, or right).  For example, if the current position is square 55 and the current orientation is south, moving straight would move to square 65, moving back would move to square 45, moving left would move to square 56, and moving right would move to square 54.  You may use numeric shortcut values for inputting the orientation and direction if you wish, as in the sample session below.

 

Enter the positions that it is invalid to travel to.  Enter 0 to indicate that you are done entering values:

11 12 13 14 15 16 17 18 19 20

0

Enter current position (1-100), orientation (N=0,W=1,S=2,E=3), and desired direction (Straight=0,Left=1,Back=2,Right=3).

Or enter 0 to exit.

21 0 0

That move is not legal.

 

Enter current position (1-100), orientation (N=0,W=1,S=2,E=3), and desired direction (Straight=0,Left=1,Back=2,Right=3).

Or enter 0 to exit.

21 1 0

That move is not legal.

 

Enter current position (1-100), orientation (N=0,W=1,S=2,E=3), and desired direction (Straight=0,Left=1,Back=2,Right=3).

Or enter 0 to exit.

21 0 2

That move is legal.

 

Enter current position (1-100), orientation (N=0,W=1,S=2,E=3), and desired direction (Straight=0,Left=1,Back=2,Right=3).

Or enter 0 to exit.

21 0 3

That move is legal.

 

Enter current position (1-100), orientation (N=0,W=1,S=2,E=3), and desired direction (Straight=0,Left=1,Back=2,Right=3).

Or enter 0 to exit.

0

 

Once again, you may not use a multidimensional array as part of this solution. 

 

Turn in: Turn in a hardcopy of your code as a “Listing.” Turn in a hardcopy of your program’s output (see Problem C5&C6 of last week’s P Set for instructions).