Advertisement
Kenthris

Untitled

Apr 27th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. //beginning of the code
  2. //sp stands for starting position, counter is used later. if you already have one, cool
  3. int sp;
  4.  
  5. //once the dimensions have been finalized, either by choosing default dimensions or by choosing to give custom ones and giving them
  6. sp = dimensions DIV 2;
  7. //what this does is that we now know where to place the 4 players on the board, in the middle of each row (and, if there are 4 players, column), at [0, sp-1] and [dimensions-1, sp-1]. correspondingly, if there are 4 players, the extra 2 will be placed on [sp-1, 0] and [sp-1, dimensions-1]. the -1's are obviously because counting on arrays starts from 0
  8.  
  9. //once the number of players has been given, malloc an EXTRA array (yes, not the one you've already malloced) that is 4x2. It's where we'll save the players' starting positions and where their positions will also be kept after the game has started (in addition to being on the board).
  10. initialize this entire array to hold the value (dimensions + 1) using a double for loop
  11. counter = 0;
  12. randomly choose a number from 0 to (number of players - 1). check if the corresponding player's position in the array is (dimensions + 1). if it is, set the first cell of this row to sp-1 and the second one to dimensions-1 . With this, the coordinates of a randomly chosen player have been set to be on the bottom of the board. Repeat this process for a second player, setting him to the top. If there are 4 players, repeat this process in a large if, putting the last remaining players on the sides accordingly
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement