Hot answers tagged

5 votes

Why Aren't My Last Two Tiles Swapping?

Recall that arrays are zero based. So if you have an array of d elements, the index goes from 0 to d - 1.
  • 2,625
2 votes

How to pass grid values to draw in pset3

The board was already declared for you as a global array, so you should be setting the initial values in your init() and then drawing that array in your draw(). The draw() function is also called ...
  • 18.4k
2 votes
Accepted

Pset3 Fifteen: Draw and/or Init Function Problem

You cannot check if number is even with if (d/2 == 0) use % sign (remainder sign). Number is even if you divide the number with 2 and remainder becomes 0. for example if (d%2 == 0) { //...
  • 549
1 vote
Accepted

Pset3: draw() is printing out incorrectly

"Any tips to help figure out what might be causing this?" If this draw() is printing out all underscores and the board layout is correct even though it is all underscores, it looks like the array ...
  • 64.6k
1 vote

How to set up the board using init and draw functions

In your init function you need to assign values to each position in the board array. In the draw function, you use the values from your board array to print to the screen. Note that the integer array ...
1 vote
Accepted

How to detect collision of a sprite with objects drawn by pen within a single sprite?

Not sure that you can do "when touching a pen mark", but you can use "touching a color" as a condition, so perhaps if the sprite is touching the blue color?
  • 18.4k
1 vote
Accepted

game of fifteen problem with initialisation of my 2D array

board[][] is a global variable. When you redeclared it inside of the init() function, you created what is called a shadow variable. A shadow variable is a variable that is created with local scope ...
  • 64.6k
1 vote
Accepted

Game of Fifteen Draw function outputting only zeros

In init, do not declare board using int board[d][d];. This variable is already declared globally, so that all functions can access it. By declaring your own variable, you shadow the global one (you ...
  • 20.7k
1 vote
Accepted

Game of Fifteen Not Swapping Tiles and Allowing Illegal Movies

In move () you are reading out of bounds. For example On a 3x3 board if j is 0 you will read j-1. This goes for the whole perimeter of the board. You need to account for these bounds. You also need ...
1 vote
Accepted

pset3 - swap in function Init

The swapping looks ok (at least in the first init function). The thing that is "not giving the expected results" is the draw function. The draw function should print the "current state" of the board ...
1 vote
Accepted

Problem Set 3 Fifteen - Draw function drawing more than it should

It really looks like screen artifacts. It could have to do with screen size. Did you by any chance have (optional) fun with "ANSI escape sequences"? FWIW the original clear function is: printf("\...
1 vote
Accepted

pset3, move function !! Please Help?

You might want to get rid of the first set of nested loops: for(int i=0; i<d; i++) { for(int j=0; j<d; j++) { if(board[i][j] == 0) { blank = board[i][j]; ...
1 vote
Accepted

pset3: fifteen - "init" and "draw"

8 7 6 5 3 1 0 -3 -6 It is what makes init () when d3, just have to take pen and paper and do some calculations. for(int i = 0; i < d; i++) { int k = i + 1; it leads to a wrong ...
  • 5,181
1 vote
Accepted

PSet 3 - Game of fifteen - draw tile gives weird output

The board[][] array is a global variable. In both functions, the code is creating a shadow array called board[][]. int board[DIM_MAX][DIM_MAX]; By redeclaring the board array in each function, it ...
  • 64.6k
1 vote

init and draw not working properly in pset3 fifteen

your init function is incorrect as noted @Matt Obert. if (d%2 != 0) { for .... } if d = 4, for example, your function init will not doing nothing at all, since board [d-1] [d-2]; It not even ...
  • 5,181

Only top scored, non community-wiki answers of a minimum length are eligible