Starting from:
$35

$29

Computer Programming HW 08 Solution




Part 1-




91
92
T
94
95
96
97
S
S
100
{72}
{56}
(Finish)


































90
M
88
87
86
P
84
83
B
81
{94}






































71
72
S
74
75
M
77
78
T
80
{68}
{83}




































70
M
68
67
B
65
64
S
62
61
{77}
{52}




































51
52
53
T
55
56
M
58
59
S
{77}
{44}




































B
49
P
47
46
S
44
43
42
41
{22}






































31
M
33
34
35
B
37
38
39
T
{52}






































30
B
28
27
26
S
24
23
22
21
{12}






































11
12
P
14
15
16
M
18
19
20
{28}






































10
9
8
M
S
5
4
3
2
1
{11}
{1}
(Start)








































Fig-1 The 100 games




Purpose of the 100 game: Each player rolls one dice by turns and try to reach 100 block on the board as soon as possible. The player win the game who reaches 100 block firstly.

Some rules of the game:




Each player can roll the dice just once at his/ her turn and move forward by on the number of the dice.



When a player reaches the block 100, the game is over.



After the dice rolling, if the move overshoots the block 100, then the player does not move.



Blocks with label “P” penalties. Similar to the first rule, if a player ends up in a “P” block after dice rolling, then the player does not move.



Blocks with label “S” represents snakes. If the player reaches an “S” block, returns the block that is shown in brackets.



Blocks with label “M” represents stairs. If the player reaches an “M” block, jumps the block that is shown in brackets.



Blocks with label “B” represents boosts. If the player reaches a “B” block, jumps from current block to fifth next block.



Blocks with label “T” represents traps. If the player reaches a “T” block, returns from current block to fifth previous block.









Write the code of the function that initialize the board that is shown in fig-1. The board prototype should be like ;



struct block board[10][10]




Write the code of the function that prints the board like shown in fig-1. Double row cells can be printed plain (like M {11}). Don’t draw the lines which covers the blocks.



Write the code of the function that plays the game as a single player, recursively. The function tries to reach 100. When the function reaches “100” block, it prints the moves from last to first and returns move counts.



Write the code of the function that plays two separate game that one game for player 1 and another for player 2. Compare which player won the game and print it.



Notes:




Define a block named structure for blocks. The structure must have text, data, type, pos_x, pos_y, jump_x, jump_y. For example;



text= M {11} data= 7 type=M pos_x=9 pos_y=3




block= block 11 (just represent, not the code) jump_x=8




jump_y=0




You can add another properties to the structure if you needed.




Define an enumerated data type for block types.






Part 2-




Write the following recursive function:







char* find_operations(int arr[], int expected_val, char operations[], size_t arr_len, int cursor, int current)




The first argument is an array of numbers. Assume that n numbers are given.
The second argument is an integer number.
The third argument is a string that has n-1 spaces at first call.



Your function finds a sequence of operators (exactly n-1 of those) such that successive application of these operators on the given array of numbers produces the given number (the second argument). The operators can be one of {+, -, *}.



For example, for array {25, 12, 6, 10, 32, 8}, the operators {-, *, -, -, +} produce 44 by applying (((((25 - 12) * 6) - 10) - 32) +8).




Applying the operators in sequence means that the first operator is applied to the first two numbers in the array. Assume that the result is a12. Then the second operator is applied to a12 and the third number in the array. Assume that this in turn is labeled as a123. Then the third operator will be applied to a123 and the fourth number in the array. This will continue till all the operators are applied to the numbers in the array sequentially.




There may be multiple answers for the sequence of operators. You are expected to find one that works. In some cases, the given the argument may not have any n-1 operators.




For example {1, 2, 3} and 100 does not have any solution. In this case, your function should return a list of spaces (n-1 of them).




Notes:




Do not change the given function prototype. But you are allowed to use auxiliary functions as you see fit. However, your implementation of the main algorithm should be recursive. Non recursive implementations will not be graded and will receive a 0 for this part.



You are not allowed to use any global and static variables in your function implementations. Any use of such variables will result in a 0 for this part.






General:




Obey honor code principles.



Read your homework carefully and follow the directives about the I/O format (data file names, file formats, etc.) and submission format strictly. Violating any of these directives will be penalized.



Obey coding convention.



4. Your submission is HW08_studentnumber.zip and include the following files and NOTHING MORE (no data files, object files, etc):




HW08part1.c
HW08part2.c
Do not use non-English characters in any part of your homework (in body, file name, etc.).
Deliver the print out of your work until the last submission date.
For questions about homework, you can send an email to b.koca@gtu.com.tr

More products