Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. 1. ask for the number of heaps (simple printf then scanf to an integer)
  2. 2. check whether num of heaps is between 1 and 32(define constants for 1 and 32 and use them), if not, print an error and terminate
  3. 3. get heap sizes from user (a loop of scanfs should work), if a non positive (<=0) heap size was entered, print an error and terminate
  4. - useful link: https://stackoverflow.com/questions/2539796/c-reading-multiple-numbers-from-single-input-line-scanf
  5. - the heap sizes can be entered in many ways such as: size1ENTERsize2ENTER... or size1SPACEsize2SPACE...ENTER, make sure our program is ok with these different inputs
  6. 4. function that simulates a game:
  7. - contains a while loop, while(not all heaps are empty), if all the heaps are empty, we exit while and announce the winner
  8. - we can maintain a variable userPlayedLastTurn (is 0/1). If we left the while with userPlayedLastTurn = 1, we print that user
  9. won, otherwise we print that computer won
  10. - now let's look at what happens inside the while loop
  11. - print status of the heaps (a variable numOfTurns should be maintained) and proceed with user/computer 's turn
  12. - if this is a user turn:
  13. print a proper message and get heapIndex and numItemsToRemove from user
  14. check validity of input:
  15. while(input is not valid) ask the user to insert a valid input, once a valid input was inserted print a proper message
  16. and move on to computer's turn (we also need to update the heapSize of the heap we chose)
  17. - if this is a computer turn:
  18. same as user turn, but in this case, we get heapIndex and numItemsToRemove from function(computation) and not from user
  19. 5. in section 4 we use several functions we need to implement:
  20. - int allHeapsAreEmpty: receives an int array, returns 0/1
  21. - various print functions
  22. - int isValidUserTurnInput: receives the two integers (heapIndex, numItemsToRemove) the user entered, returns 0/1
  23. - COMPUTATION OF COMPUTER'S CHOICE OF heapIndex AND numItemsToRemove (this is the computer's strategy function)
  24.  
  25. Assumptions:
  26. * the user enters only int values from -2^31 to 2^31-1 (I think we can use int variable, no need for long or anything like that)
  27. * user starts the game
  28.  
  29. Where do we implement what:
  30. - main:
  31. * receive numOfHeaps from user
  32. * initialize heap array (including getting heapSizes)
  33. * handling user's move [simply two scanfs]
  34. * run the game itself
  35. - sp_nim:
  36. * handling computer's move [two functions - one for heapIndex, one for numOfItemsToRemove]
  37. * determine whether there is a winner (are all the heaps empty?)
  38. - main_aux:
  39. * check validity of numOfHeaps
  40. * check validity of heapSize
  41. * all print methods
  42. * check validity of heapIndex and numOfItemsToRemove
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement