Skip to main content
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) { //...
Wafeeq's user avatar
  • 549
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?
curiouskiwi's user avatar
  • 18.7k
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 ...
Cliff B's user avatar
  • 69k
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 ...
Blauelf's user avatar
  • 21k
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 ...
Ryan McCauley's user avatar
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 ...
DinoCoderSaurus's user avatar
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("\...
DinoCoderSaurus's user avatar
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]; ...
Ricardo David Antonetti's user avatar
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 ...
MARS's user avatar
  • 5,179
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 ...
Cliff B's user avatar
  • 69k
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 ...
MARS's user avatar
  • 5,179

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