C programming- the simplified Zuma Game. In the game of Zuma, the player fires c
ID: 3714415 • Letter: C
Question
C programming- the simplified Zuma Game. In the game of Zuma, the player fires color ball into a given path and the color balls are eliminated when three or more of the same color come in contact. In this simplified version, we assume at the start of the game there is no existing balls in the path and the player always fires the currently available ball into the end of the path. For example, if the given ball sequence is YYRRRY. The play fires Y into the empty path, and fires another Y into the position right after the previous Y, then fires three R one after one. And as the three Rs get eliminated, the path becomes YY. At last, the player fires the final Y into the path resulting in the three Ys getting eliminated and an empty path is returned.
a. Write a c function to receive a given ball sequence, return the remaining path using this strategy in the end. Some examples: Given ball sequence YYRBGGGBBRPPWWWPRY – the remaining path is empty. Given ball sequence YRBGGGBWPPPWWBRRYYYR – the remaining path is YR.
b. Supposed now the player toggle between the strategy of firing into the end and firing into the start. For example, with the input sequence of YYRRRY. The player fires the first Y into the end of empty path and gets a path with “Y”, fires the second Y into the start of path and gets YY, fires the R into the end again and gets YYR, fires the R into the start and gets RYYR, fires the R into the end and gets RYYRR, fires the Y into the start and gets YRYYRR. Write a function to receive a given ball sequence and return the remaining path. Some examples: Given ball sequence YRYRBGBGBGRYWYWYWR – the remaining path is YYR.
Explanation / Answer
Please find the code below with detailed inline comments.
CODE
=====================
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.