1 00:00:00,000 --> 00:00:00,200 2 00:00:00,200 --> 00:00:02,670 >> ZAMYLA CHAN: To win the game of 15, the tiles have to be 3 00:00:02,670 --> 00:00:04,280 in a specific order. 4 00:00:04,280 --> 00:00:07,460 And the one function checks whether the game is won. 5 00:00:07,460 --> 00:00:10,800 It returns true if the game is won and the tiles are in the correct order, 6 00:00:10,800 --> 00:00:12,710 and false otherwise. 7 00:00:12,710 --> 00:00:16,329 >> So to win the game of 15, tiles have to be in increasing order, with the 8 00:00:16,329 --> 00:00:19,730 blank tile at the bottom right corner. 9 00:00:19,730 --> 00:00:24,140 So how do you check whether the user has moved the board into the right 10 00:00:24,140 --> 00:00:25,510 orientation? 11 00:00:25,510 --> 00:00:29,660 Well, you'll iterate over the board and check the values to make sure that 12 00:00:29,660 --> 00:00:31,050 they're in the right place. 13 00:00:31,050 --> 00:00:34,410 To do this, you could use nested for loops just like you did 14 00:00:34,410 --> 00:00:37,040 in Draw and in Init. 15 00:00:37,040 --> 00:00:40,930 >> There are a couple of ways to check and validate whether the board is 16 00:00:40,930 --> 00:00:43,360 correct in a winning though. 17 00:00:43,360 --> 00:00:47,830 If you go from left to right, starting from the top row down, then every 18 00:00:47,830 --> 00:00:51,090 number must be greater than the previous one. 19 00:00:51,090 --> 00:00:55,030 Be careful about what value you've chosen for your blank tile, though. 20 00:00:55,030 --> 00:00:59,750 >> Or you could use a counter variable to ensure that each value is in place if 21 00:00:59,750 --> 00:01:04,170 you come up with some sort of formula to represent this. 22 00:01:04,170 --> 00:01:06,750 So have fun experimenting with the math. 23 00:01:06,750 --> 00:01:11,410 Once you come up with a way, return true once the user has won the game. 24 00:01:11,410 --> 00:01:14,630 >> But if any value is incorrect, return false. 25 00:01:14,630 --> 00:01:18,940 The user has to continue moving, because they haven't won the game yet. 26 00:01:18,940 --> 00:01:23,530 Once you implement this check, and along with initialize, draw, and move, 27 00:01:23,530 --> 00:01:25,610 you've finish the game of 15. 28 00:01:25,610 --> 00:01:28,110 Congratulations, and have fun playing. 29 00:01:28,110 --> 00:01:31,570 My name is Zamyla, and this is CS50. 30 00:01:31,570 --> 00:01:38,326 >> [MUSIC PLAYING]