-
Posts
7,886 -
Joined
Content Type
Forums
News
20th
EduGeek EDIT Conference
Blogs
Everything posted by Joanne
-
I've changed the loop and they both initialize properly now. So I need to sort my draw out I guess!
-
-
It's a shame really because it is really good in terms of simplicity and being able to drag pictures in from Google and stuff. But in terms of day to day use, it doesn't work too well. I downloaded the Beta of version 4.8 I think it was and you could draw a table... HURRAY I thought. But then you can't add text. You have to create numerous text boxes... :-/
-
Right swapped all that up a bit and I'm still getting illegal move! /** * fifteen.c * * Computer Science 50 * Problem Set 3 * * Implements Game of Fifteen (generalized to d x d). * * Usage: fifteen d * * whereby the board's dimensions are to be d x d, * where d must be in [DIM_MIN,DIM_MAX] * * Note that usleep is obsolete, but it offers more granularity than * sleep and is simpler to use than nanosleep; `man usleep` for more. */ #define _XOPEN_SOURCE 500 #include #include #include #include // constants #define DIM_MIN 3 #define DIM_MAX 9 // board int board[DIM_MAX][DIM_MAX]; // dimensions int d; //global declarations int row, col, val, blankTile, blankTileCol, blankTileRow; // prototypes void clear(void); void greet(void); void init(void); void draw(void); bool move(int tile); bool won(void); int main(int argc, string argv[]) { // ensure proper usage if (argc != 2) { printf("Usage: fifteen d\n"); return 1; } // ensure valid dimensions d = atoi(argv[1]); if (d < DIM_MIN || d > DIM_MAX) { printf("Board must be between %i x %i and %i x %i, inclusive.\n", DIM_MIN, DIM_MIN, DIM_MAX, DIM_MAX); return 2; } //Set blank tile location blankTileRow = (d - 1); blankTileCol = (d - 1); blankTile = board[blankTileRow][blankTileCol]; // open log FILE* file = fopen("log.txt", "w"); if (file == NULL) { return 3; } // greet user with instructions greet(); // initialize the board init(); // accept moves until game is won while (true) { // clear the screen clear(); // draw the current state of the board draw(); // log the current state of the board (for testing) for (int i = 0; i < d; i++) { for (int j = 0; j < d; j++) { fprintf(file, "%i", board[i][j]); if (j < d - 1) { fprintf(file, "|"); } } fprintf(file, "\n"); } fflush(file); // check for win if (won()) { printf("ftw!\n"); break; } // prompt for move printf("Tile to move: "); int tile = GetInt(); // quit if user inputs 0 (for testing) if (tile == 0) { break; } // log move (for testing) fprintf(file, "%i\n", tile); fflush(file); // move if possible, else report illegality if (!move(tile)) { printf("\nIllegal move.\n"); usleep(500000); } // sleep thread for animation's sake usleep(500000); } // close log fclose(file); // success return 0; } /** * Clears screen using ANSI escape sequences. */ void clear(void) { printf("\033[2J"); printf("\033[%d;%dH", 0, 0); } /** * Greets player. */ void greet(void) { clear(); printf("WELCOME TO GAME OF FIFTEEN\n"); usleep(2000000); } /** * Initializes the game's board with tiles numbered 1 through d*d - 1 * (i.e., fills 2D array with values but does not actually print them). */ void init(void) { val = 1; //populate board by row, move along columns for (col = 0; col < d; col++) { for (row = 0; row < d; row++) { board[row][col] = (d * d) - val; val = val + 1; } } board[d-1][d-1] = 0; //switch 1 and 2 for odd number of tiles if ((d %2 == 0) && board[row][col] == 2) { board[row][col] = 1; } else if ((d %2 == 0) && board[row][col] == 1) { board[row][col] = 2; } } /** * Prints the board in its current state. */ void draw(void) { val = 1; //populate board by row, move along columns for (col = 0; col < d; col++) { for (row = 0; row < d; row++) { board[row][col] = (d * d) - val; val = val + 1; if ((d %2 == 0) && board[row][col] == 2) { board[row][col] = 1; } else if ((d %2 == 0) && board[row][col] == 1) { board[row][col] = 2; } if (board[row][col] == 0) { printf(" _"); } else { printf(" %2d", board[row][col]); } } printf("\n"); } } /** * If tile borders empty space, moves tile and returns true, else * returns false. */ bool move(int tile) { //make sure provided tile number is legit //if (tile > ((d*d)-1)) //{ //return false; //} //if (tile <= 0) //{ //return false; //} //search for tile for (col = 0; col < d; col++) {printf("Working on column %d\n", col); for (row = 0; row < d; row++) { printf("Working on row %d\n", row); if (tile == board[row][col]) { blankTile = 0; //check it is next to 0 if (((blankTileRow == (row - 1)) && (col == blankTileCol)) || (( blankTileRow == (row +1)) && (col == blankTileCol)) || ((row == blankTileRow) && (blankTileCol == (col - 1))) || ((row == blankTileRow) && (blankTileCol == (col + 1)))) { //swap locations of tile and 0 board[blankTileRow][blankTileCol] = tile; board[row][col] = blankTile; blankTileRow = row; blankTileCol = col; return true; } } } } return false; } /** * Returns true if game is won (i.e., board is in winning configuration), * else false. */ bool won(void) { int counter; //create counter counter = 0; for (col = 0; col < d; col++) { for (row = 0; row < d; row++) { counter = counter + 1; //check all numbers are correct if (board[row][col] != counter) { return false; } } } return true; }
-
Ooops, I've been using grid and the board one was pre-written. Perhaps I need to change over to board! Yes the global and local makes perfect sense. I wondered why I had to keep repeating declarations! Think I need to do some re-arranging then. I tested the functions separately, and they always worked on their own... d'oh.
-
@mavhc tried making the blankTileRow and blankTileCol values global, but it didn't work. Still tells me illegal move. - - - Updated - - - OK @Steve21 - this is the full thing. I basically have to write the functions. /** * fifteen.c * * Computer Science 50 * Problem Set 3 * * Implements Game of Fifteen (generalized to d x d). * * Usage: fifteen d * * whereby the board's dimensions are to be d x d, * where d must be in [DIM_MIN,DIM_MAX] * * Note that usleep is obsolete, but it offers more granularity than * sleep and is simpler to use than nanosleep; `man usleep` for more. */ #define _XOPEN_SOURCE 500 #include #include #include #include // constants #define DIM_MIN 3 #define DIM_MAX 9 // board int board[DIM_MAX][DIM_MAX]; // dimensions int d, blankTileCol, blankTileRow; // prototypes void clear(void); void greet(void); void init(void); void draw(void); bool move(int tile); bool won(void); int main(int argc, string argv[]) { // ensure proper usage if (argc != 2) { printf("Usage: fifteen d\n"); return 1; } // ensure valid dimensions d = atoi(argv[1]); if (d < DIM_MIN || d > DIM_MAX) { printf("Board must be between %i x %i and %i x %i, inclusive.\n", DIM_MIN, DIM_MIN, DIM_MAX, DIM_MAX); return 2; } // open log FILE* file = fopen("log.txt", "w"); if (file == NULL) { return 3; } // greet user with instructions greet(); // initialize the board init(); //Set blank tile location blankTileRow = (d - 1); blankTileCol = (d - 1); // accept moves until game is won while (true) { // clear the screen clear(); // draw the current state of the board draw(); // log the current state of the board (for testing) for (int i = 0; i < d; i++) { for (int j = 0; j < d; j++) { fprintf(file, "%i", board[i][j]); if (j < d - 1) { fprintf(file, "|"); } } fprintf(file, "\n"); } fflush(file); // check for win if (won()) { printf("ftw!\n"); break; } // prompt for move printf("Tile to move: "); int tile = GetInt(); // quit if user inputs 0 (for testing) if (tile == 0) { break; } // log move (for testing) fprintf(file, "%i\n", tile); fflush(file); // move if possible, else report illegality if (!move(tile)) { printf("\nIllegal move.\n"); usleep(500000); } // sleep thread for animation's sake usleep(500000); } // close log fclose(file); // success return 0; } /** * Clears screen using ANSI escape sequences. */ void clear(void) { printf("\033[2J"); printf("\033[%d;%dH", 0, 0); } /** * Greets player. */ void greet(void) { clear(); printf("WELCOME TO GAME OF FIFTEEN\n"); usleep(2000000); } /** * Initializes the game's board with tiles numbered 1 through d*d - 1 * (i.e., fills 2D array with values but does not actually print them). */ void init(void) { // grid size int grid[d][d]; int row, col, val; val = 1; //populate grid by row, move along columns for (col = 0; col < d; col++) { for (row = 0; row < d; row++) { grid[row][col] = (d * d) - val; val = val + 1; } } grid[d-1][d-1] = 0; //switch 1 and 2 for odd number of tiles if ((d %2 == 0) && grid[row][col] == 2) { grid[row][col] = 1; } else if ((d %2 == 0) && grid[row][col] == 1) { grid[row][col] = 2; } } /** * Prints the board in its current state. */ void draw(void) { int grid[d][d]; int row, col; int val; row = 0; val = 1; //populate grid by row, move along columns for (col = 0; col < d; col++) { for (row = 0; row < d; row++) { grid[row][col] = (d * d) - val; val = val + 1; if ((d %2 == 0) && grid[row][col] == 2) { grid[row][col] = 1; } else if ((d %2 == 0) && grid[row][col] == 1) { grid[row][col] = 2; } if (grid[row][col] == 0) { printf(" _"); } else { printf(" %2d", grid[row][col]); } } printf("\n"); } } /** * If tile borders empty space, moves tile and returns true, else * returns false. */ bool move(int tile) { int row, col, blankTile; int grid[d][d]; //make sure provided tile number is legit //if (tile > ((d*d)-1)) //{ //return false; //} //if (tile <= 0) //{ //return false; //} //search for tile for (col = 0; col < d; col++) {printf("Working on column %d\n", col); for (row = 0; row < d; row++) { printf("Working on row %d\n", row); if (tile == grid[row][col]) { blankTile = 0; //check it is next to 0 if (((blankTileRow == (row - 1)) && (col == blankTileCol)) || (( blankTileRow == (row +1)) && (col == blankTileCol)) || ((row == blankTileRow) && (blankTileCol == (col - 1))) || ((row == blankTileRow) && (blankTileCol == (col + 1)))) { //swap locations of tile and 0 grid[blankTileRow][blankTileCol] = tile; grid[row][col] = blankTile; blankTileRow = row; blankTileCol = col; return true; } } } } return false; } /** * Returns true if game is won (i.e., board is in winning configuration), * else false. */ bool won(void) { int counter, col, row; int grid[d][d]; //create counter counter = 0; for (col = 0; col < d; col++) { for (row = 0; row < d; row++) { counter = counter + 1; //check all numbers are correct if (grid[row][col] != counter) { return false; } } } return true; }
-
So this flashes up when I select tile 4. It SHOULD swap it with the blank tile... - - - Updated - - - It should find the 4 value in column 3, row 2. But doesn't.
-
-
Right I've written the swap function, but I get 'illegal move' every time I try a number to swap... /** * If tile borders empty space, moves tile and returns true, else * returns false. */ bool move(int tile) { int row, col, blankTile, blankTileRow, blankTileCol; int grid[d][d]; blankTileRow = (d - 1); blankTileCol = (d - 1); //make sure provided tile number is legit //if (tile > ((d*d)-1)) //{ //return false; //} //if (tile <= 0) //{ //return false; //} //search for tile for (col = 0; col < d; col++) { for (row = 0; row < d; row++) { if (tile == grid[row][col]) { blankTile = 0; //check it is next to 0 if (((blankTileRow == (row - 1)) && (col == blankTileCol)) || (( blankTileRow == (row +1)) && (col == blankTileCol)) || ((row == blankTileRow) && (blankTileCol == (col - 1))) || ((row == blankTileRow) && (blankTileCol == (col + 1)))) { //swap locations of tile and 0 grid[blankTileRow][blankTileCol] = tile; grid[row][col] = blankTile; blankTileRow = row; blankTileCol = col; return true; } } } } return false; } I kinda think it is returning false no matter what I put in, and I think it's because of that there return false at the bottom. I tried whacking an else return false in there, but it didn't like it. I'm on the edge with this now!
-
Went out to buy Rise of the Tomb Raider last night, but it wasn't there in Asda, so ordered it from Amazon. Should be getting it on Wednesday. Yessssssssssssss!! Downloaded Resident Evil so will be playing that tonight and no doubt $#!&ing myself in the process.
-
Another issue I had was that I would put the software on an image, activate it and then when I deployed the image to laptops, users could not access the Lynx software as the start menu instance had removed itself. The program files were still there, so I could link to the exe, but then I would have to go through the activation process again, despite following instructions for activation on networked machines...
-
We have CleverTouch boards and we tried to use the Lynx software, but staff gave up on it for the same reasons as you. The main issue being the fact you can't create tables!! I have tried to give feedback to the development team, but it never really came off.
-
My spec of the problem says that the location should be saved so you don't have to search every time. So you just do one search and then when you tell the program to swap tiles, it saves the new location of the blank tile.
-
Hahahah. Some people are more susceptible I think. If you can't explain what happened then 'ghosts'. I did it when there was an earthquake back in... 2007ish? We woke up in bed and it was moving a lot. Husband jumped out of bed thinking someone was in the house, I thought it was him jiggling his leg, but the bed still moved when he was out of it. It eventually stopped and I was like... what the hell just happened? Didn't think earthquake, because that doesn't happen in the UK. So we decided it was ghosts and went back to sleep!
-
Lots of vitamin, advice is very good, yes, I have carrots here.
-
Thanks for the warning John. I was thinking out loud when suggesting the floats / doubles. I think my problem was a misplaced curly bracket. Currently I'm wondering if this is going to do what I want it to/... //set blankTile with 0 location blankTile[row][col] = (grid[row][col] == 0); I want to save the location of my 0. So if my 0 was at grid[2][2] would it set blankTile[2][2] ?
-
Maybe it does a self test at that time? Love stuff like this!!
-
Need to code in C, But my brain is mush today, Maybe after snack.
-
I love that it's gone from my simple game of 15 code to the stock exchange!! Hahahahah!!
-
Someone from the dead is trying to get in touch!! What does Google say about the number?
-
If it makes anyone feel better, I got it working without floats or doubles. I'm going to sit down and try and do the next 2 parts of this problem today, swapping values in the array and a check for winning. It sounds so simple when I put it like that!!
-
OMG love it. Do you get the number from the phone call or is it withheld?
-
[ipad] Apple Configurator 2 - Some Apps install, others don't.
Joanne replied to Joanne's topic in Mobile Devices & Tablets
I do use a caching server. It's the same apps for all the iPads I apply the blueprint to. I ended us just selecting all of the problem apps and adding them separately as a bunch. Didn't take too long and DIDN'T ERROR!! I was shocked. -
VeryPC STOCKtober 2016 - A month of prizes and fun from VeryPC
Joanne replied to VeryPC's topic in Our Advertisers
