Questions tagged [game-of-fifteen]

Game of Fifteen, one of the assignments in Problem Set 3

Filter by
Sorted by
Tagged with
3
votes
2answers
29k views

How to solve “control may reach end of non void function” error

When I try to compile my code, I get an error message that says "control may reach end of non void function." What does this message mean and how can I avoid this error? Here is the function that's ...
3
votes
3answers
416 views

Blank tile without using a variable

Regarding the blank tile in Game of Fifteen, can I avoid using a variable for the blank? In other words, can I just print an underscore when I reach zero in my array?
2
votes
1answer
790 views

Where can I find 3x3.txt?

So I've gotten to the end of my coding for fifteen and sure, I could try and solve it myself (I'm lazy), OR I could load up the 3x3.txt file. However, I'm having trouble finding the location of this ...
2
votes
2answers
264 views

Why Aren't My Last Two Tiles Swapping?

I'm trying to come up with something to change the tile numbers in the last two array slots, containing numbers 1 and 2 when I have an odd number of tiles. I thought this would work, but when I print ...
2
votes
1answer
33 views

Fifteen: Error in a function I haven't touched yet

I am working on the last part of pset3 (game of fifteen). After trying out my code for the init and draw functions, I tried to "make" it and receive this message in the terminal (CS50 IDE). clang -...
2
votes
1answer
746 views

Pset3 Fifteen Check50 not Working

My code works when using the 3*3.txt as well as when I play it, but it is not accepted by check50. Here are my check50 errors: :) fifteen.c exists :) fifteen.c compiles :( init initializes 3x3 board ...
2
votes
1answer
146 views

How do I get to work gdb to check my Won function in game of fifteen

there is a staff implementation of predefined set of moves for a 3 x 3 board which can be executed by ./fifteen 3 < ~cs50/pset3/3x3.txt I was working on my Won function, can some one tell me how ...
1
vote
2answers
1k views

Pset3 Fifteen Move function

I dont even know how to begin the move function, can somebody give me some ideas please? Probably by searching the tiles position, but how can i do that?
1
vote
2answers
29k views

How do I fix a “use of undeclared identifier” compilation error?

In the following code snippet: for (int column = 0; column < d - 1; column++); { board[&row][&column] == counter; counter++; make returns the following error: fifteen.c:140:19: ...
1
vote
2answers
268 views

PSET3 Game of Fifteen move() Problem

I'm sorry for making another post of this, but I don't want to look other classmates' code while I'm still trying to do this myself. I'm having trouble with move() in fifteen.c. I'm not sure how to ...
1
vote
1answer
4k views

move function, pset3

I'm having trouble with my move funtion in the game of fifteen. For some reason the chosen tile and the adjecent zero won't swop places. I've been working on this function for too long and reaching ...
1
vote
1answer
304 views

Game of Fifteen pset3 - won() function works, but why?

I've managed to get a thumbs up from check50 in the Game of Fifteen, but I have no idea why. It's really eating at me and I refuse to go forward until I understand it. Here's my less than eloquent ...
1
vote
1answer
135 views

Am I going about Init() correctly?

I'm wondering if I'm going about Init() correctly. It took me quite some time to understand what I was supposed to do. I realized drawing out the actual board on paper helped a lot. Anyways, here is ...
1
vote
1answer
635 views

pset3 fifteen's draw function problem

I'm trying to make draw function but i can't seem to have values which i have done in init() function. When i compile and run the program i have zeros all over the display. Can anyone address me ...
1
vote
1answer
230 views

Global variables to store the position of the blank space?

I tried to implement a leftward movement in game of 15. I encountered a problem. The program can only call move function once and it doesn't work after that. I use 0 to as the representation for the ...
1
vote
1answer
474 views

Swap 2 and 1 after looping, pset3, Game of Fifteen

I don't know why my positions at 2 and 1 in my odd numbered tiles are not swapping. Here is a mix of pseudo code plus my swap conditional. See anything that is wrong? Thanks. // board, whereby ...
1
vote
1answer
37 views

pset 3 fifteen - check50 failure last 3x3, 4x4

I was going to check my solution to pset3 fifteen with check50 while I received two failure errors on the console (on the last 3x3 and 4x4 checks). :) fifteen.c exists. :) fifteen.c compiles. :) ...
1
vote
1answer
42 views

Game of Fifteen Not Swapping Tiles and Allowing Illegal Movies

I have two issues with my code. First, while the code correctly moves the underscore to the new space, it does not move the tile to the space where the underscore once was. So I end up with a bunch of ...
1
vote
1answer
78 views

CS50 PSET3 FIFTEEN compiles but fails to work properly

Dear StackExchange users, My name is Samuel and I'm 14 years old. I am completing Problem Set 3 but am stuck on fifteen.c. My program compiles and runs. When I run the program, I get the normal ...
1
vote
2answers
77 views

Check50 Error (pset3, fifteen)

In my own testing my fifteen game compiles without errors and works perfectly. However, when I checked it with check50 it said that it couldn't initialize the boards correctly, and I got this: Then I ...
1
vote
2answers
181 views

PSET3 : fifteen: how to identify board edges in move function?

Hi I am working on pset3 : fifteen and trying to implement move function. I'm not quite sure how to identify board edges and deal with this. My swap is also not working as the tile I want to move ...
1
vote
1answer
670 views

expected an exit code of 0, not a prompt for input WON

I'm still stuggling with the game of fifteen, and I could make it works. However, when I run check50 it displays :( 3x3.txt wins the 3x3 board \ expected an exit code of 0, not a prompt for input :...
1
vote
1answer
209 views

pset3 - Why numbers are disappearing when I'm playing game of fifteen?

I'm fed up of checking the fault in my code and when I'm playing the game it disappears some numbers like in first step when I try to swap the blank space with 1 I get two blank spaces and 1 gets ...
1
vote
1answer
445 views

fifteen.c : printf() not printing anything to the screen

To check the execution sequence of the code, I have added printf statement just below the main(): int main(int argc, string argv[]) { // greet player printf("abc \n"); greet(); ...
1
vote
1answer
433 views

pset3 - 4x4.txt winning sequence not working - problem with move function?

When I play fifteen myself it works with any board size; the 3x3 winning seq also works, but the 4x4 one does not finish and stops while repetitively trying to move tile 2147483647.. GDB did not help ...
1
vote
1answer
274 views

won() Doesn't Work Properly

My won() function works properly when the board dimensions are 3 x 3. However, it doesn't work properly when the board dimensions are 4 x 4. What could possibly be wrong? for (int i = 0; i < d; i++...
1
vote
2answers
99 views

The Case of the Disappearing Tiles

I just finished trying to implement my move function. It seems to work to a certain extent, except that some of the tiles keep turning into blanks. I have the following code for my swapping: for (int ...
1
vote
2answers
98 views

Do we have to implement game of fifteen in pset3 using graphics?

Does fifteen.c had to be implemented in graphics, by including graphics.h and creating the tiles as graphical objects?
1
vote
1answer
64 views

Pset3 Move GDB Problem

I am stuck on the move part of fifteen and trying to learn how to use GDB. My thought process for moving is to search for the "tile" and if the tile is adjacent to the "_" then switch. during GDB, i ...
1
vote
1answer
84 views

pset3 move() makes every tile swapped a blank tile

I rewrote almost the entire code and I finally was able to make the tiles swap. Problem is at every swap the blank tile gets duplicated and the tile swapped disappears, eventually rendering a Segfault....
1
vote
2answers
50 views

My code is swapping “1”, “2” even if i have written code only for swapping “if even.”

This is my init function, please check and suggest: void init(void) { int size= d*d; for (int i=0;i<d;i++) { for (int j=0;j<d;j++) { board[i][j]=size-1; ...
1
vote
1answer
209 views

how does check50 test the “fifteen” code?

Can someone tell me how is check50 testing fifteen.c? My code is failing (see error below) the test, but if I try to do the steps that are failing, I see nothing wrong. 3x3 board, from start try ...
1
vote
0answers
113 views

Fifteen.c -> expected file to be of length X “cheap solution”?

I've been having some trouble with the fifteen game code. Even though it works as expected, when I do check50, I get a bunch of errors related to the expected size of the log file. After looking at ...
1
vote
1answer
654 views

pset3 fifteen not passing check50 but works

I am working on the game of fifteen on pset3. The code runs fine on my computer but fails check50. I have stepped through it in gdb and can not find what check50 is talking about. The two tests it is ...
1
vote
0answers
237 views

game of fifteen check50 error [closed]

The program seems to run fine but when I execute check50 I get this message: :) fifteen.c exists :) fifteen.c compiles :( init initializes 3x3 board correctly \ expected file to be of length 18, ...
1
vote
4answers
458 views

Pset3 fifteen.c - Move function allows invalid moves

To implement the move() function I divided it into three functions, one to find the tile inputted by the user, one to check if the move is legal, and one to actually move the tiles. At first it looked ...
1
vote
1answer
27 views

PSET 3 can't get move to swap tile above blank

Keep getting illegal move on following code and can't figure out why it won't swap. I am selecting the tile above the blank in testing. /** * Prints the board in its current state. */ void draw(...
0
votes
2answers
852 views

Pset3 won-function works only with 3x3 board. Where am I wrong?

Pset3 won-function successfully passed this test ./fifteen 3 < ~cs50/pset3/3x3.txt only for a 3 × 3 board. For a 4x4 board the program's output is: 1 2 3 4 5 6 7 _ 9 10 12 ...
0
votes
1answer
54 views

Fifteen move not working in last row only

I am very new to this, so I am at a loss as to why my code isn't working. I am trying to make my move function work in the game of fifteen, and it works as long as I am not going to the left or right ...
0
votes
2answers
105 views

Won()- Pset 3- Game of Fifteen

I'm having trouble seeing where my logic is going wrong with my won() function for Game of Fifteen (Pset 3). For example looking at my for loop, let's say d=4, i = 2, j = 1. Then board[i][j] = board[...
0
votes
1answer
75 views

A wierd error in won function (fifteen)

when I run Check50 my program passes all the tests except one, the terminal spits out this weird cryptic error :( 3x3 board: make sure game is winnable expected "Tile to move:", not "[2J[0;0H1-2-...
0
votes
1answer
200 views

PSET 3: Game of fifteen. Everything in the board is equal to zero

CS50 community! I have a problem with my PSET 3. I've done only init() and draw() functions and can't understand what's wrong, so I can't go on. It prints blankspaces all over the board, so everything ...
0
votes
2answers
170 views

Pset3/Fifteen/Init Function - Problem with 1 and 2 swap

void init(void) { int start_tile = (d * d) - 1; for (int i = 0; i < d; i++) { for (int j = 0; j < d; j++) { board[i][j] = start_tile; ...
0
votes
1answer
216 views

Pset 3: Fifteen - Moving up and down but not left or right?

I am running into problems with fifteen. Specifically, the move function. I can make numbers move up and down, but somehow I've messed up the left and right and I'm not sure how. When I try, it sets ...
0
votes
2answers
197 views

All my moves entered are shown illegal, though code doesn't seem wrong… (PS3 - fifteen)

I have checked draw() and init() and they seem to be right. However, the problem lies with the move() portion of the code. After I run the code, every move entered is named Illegal.... I have no clue ...
0
votes
1answer
467 views

pset 3 “control may reach the end of a non-void function” [duplicate]

I know what this error means, but how do I fix it? I'm using a if... else... function, so I'm not sure how to improve upon that. Thanks!
0
votes
1answer
511 views

How to Print the Blank Tile in the Game of Fifteen

In Game of fifteen we are asked to print a blank space at the end of the game, they fistly tell us to put the last number as any Int, then they ask us to print something that is not the int we chose, ...
0
votes
1answer
26 views

Long numbers appearing when trying to retrieve element of 2D array - Game of Fifteen, pset3

I am working on the move function for pset3. I was having trouble matching the tile value to the board value, so I am now using print to make sure the correct value is coming up when I type board[i][j]...
0
votes
2answers
114 views

Pset3 Game of Fifteen Won Function

The won function for fifteen is driving me crazy! Here's my implementation. I've run it through debug50 and it appears to work as expected. However, check50 only passes on a 4x4 board, but not a 3x3. ...
0
votes
1answer
98 views

game of fifteen won function (still!!) not working

I have been working on my won function for days now, and have read all the relevant posts on this site but still cant work out where I'm going wrong. The code does not return true when passed the 3x3....

1
2 3 4 5