0% found this document useful (0 votes)
15 views6 pages

PF Project 2B

Uploaded by

f2022266447
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views6 pages

PF Project 2B

Uploaded by

f2022266447
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

National University

Of Computer & Emerging Sciences Faisalabad-Chiniot Campus

Programming Fundamentals
Project

Instructor Ms. Areeba waseem

Semester Spring 2024


National University
Of Computer & Emerging Sciences Faisalabad-Chiniot Campus

Objectives:
• All concepts of programming fundamentals
• Control Structure (Selection)
• Control Structure (Repetitive/ Loops)
• Function
• Array (one-dimensional, Multi-dimensional)
• File Handling

Note: Carefully read the following instructions (Each instruction contains a weightage)
1. Anyone found in copying the project from any other group, both the groups will get F grade in the Lab.
2. 2 students are allowed per group. No cross-section is allowed.
3. You must submit the whole project by one member of the group.
4. There must be a block of comments at start of code, the block should contain brief description about
functionality of code. Also comment with all functions about there functionality.
5. Proper indentation of code is essential
6. Write a code in C++ language using Microsoft Visual Studio.
7. First think about statement problems and then write/draw your logic on copy.
8. After copy pencil work, code the problem statement on MS Studio C++ compiler.
9. At the end when you done your project, submit complete project
10. Submit your file in this format
FirstGroupMemberRollNumber_SecondGroupMemberNumber_Project.
11. Do not copy code from any source otherwise you will be penalized with negative marks.
12. In deliverable submit your complete project file with your code copy pasted on word file with all
possible output screenshots and video tutorial of the project .cpp files.
National University
Of Computer & Emerging Sciences Faisalabad-Chiniot Campus

24-Puzzle Game
The 24 is a puzzle invented and popularized by Noyes Palmer Chapman in the 1870s. It is played on a 5-by-5 grid with 15
square blocks labeled 1 through 15 and a blank square. There are two boards, one is the board you play game at, other
is the goal state we want to achieve. Your goal is to rearrange the tiles/blocks so that they are in order specified as goal
state.

1 5 4 2 16 1 2 3 4 5

8 6 3 11 17 6 7 8 8 10

14 12 7 15 18 11 12 13 14 15

9 13 10 19 16 17 18 19 20

24 23 22 21 20 21 22 23 24

Initial State Goal State

You are permitted to slide blank tile horizontally or vertically in order to make moves. The following shows a sequence
of legal moves from an initial board position (left) to the new board state after move (right).

Left Move:

1 5 4 2 16 1 5 4 2 16

8 6 3 11 17 8 6 3 11 17

14 12 7 15 18 14 12 7 15 18

9 13 10 19 9 13 10 19

24 23 22 21 20 24 23 22 21 20

Initial State New State after move


On carefully noticing you will realize that tile with label ‘10’ has moved leftward.
Page 1
National University
Of Computer & Emerging Sciences Faisalabad-Chiniot Campus

Down Move:

1 5 4 2 16 1 5 4 2 16

8 6 3 11 17 8 6 3 11 17

14 12 7 15 18 14 12 7 18

9 13 10 19 9 13 10 15 19

24 23 22 21 20 24 23 22 21 20

Initial State New State after move

On carefully noticing you will realize that tile with label ‘15’ has moved downward.

Up Move:

1 5 4 2 16 1 5 4 2 16

8 6 3 11 17 8 6 3 11 17

14 12 7 15 18 14 12 7 15 18

9 13 10 19 9 13 10 21 19

24 23 22 21 20 24 23 22 20

Initial State New State after move

The tile with label ‘21’ has moved upward.

Page 2
National University
Of Computer & Emerging Sciences Faisalabad-Chiniot Campus

Right Move:

1 5 4 2 16 1 5 4 2 16

8 6 3 11 17 8 6 3 11 17

14 12 7 15 18 14 12 7 15 18

9 13 10 19 9 13 10 19

24 23 22 21 20 24 23 22 21 20

Initial State New State after move

The tile with label ‘10’ has moved rightward.

In this game, a player moves the tiles starting from the initial state to reach the goal. Once the goal state is reached, the
game will the sequence of moves user took to reach the goal state.

E.g., Ini_State → ‘U’, ‘R’, ‘D’, ‘D’, ‘L’ → Goal

You are to implement following:

Void init() This function randomly initializes an initial state.


Void goal() This function randomly initializes a goal state. But
make sure that goal state of reachable from
initial state.
Bool Is_Solveable() A function that returns true is goal state is
reachable from the initial state, returns False
otherwise.
Bool is_goal() Returns true if state == goal, otherwise returns
false.
Int* legal_moves(int **init_state) Returns an array of allowed moves on the board
state passed to the function.
void make_move(int *&init_state, char move) Makes the move as specified by the move
character on board.
Void print_path() This function prints all the moves in order, which
player took from initial state to reach the goal
state.
File handling Store the moves of the players in file

Page 3
National University
Of Computer & Emerging Sciences Faisalabad-Chiniot Campus

How to implement Is_Solveable() function:

Odd board size: Given a board, an inversion is any pair of blocks i and j where i < j but i appears after j when considering
the board in row-major order (row 0, followed by row 1, and so forth).

If the board size N is an odd integer, then each legal move changes the number of inversions by an even
number. Thus, if a board has an odd number of inversions, then it cannot lead to the goal board by a sequence
of legal moves because the goal board has an even number of inversions (zero).

The converse is also true: if a board has an even number of inversions, then it can lead to the goal board by a
sequence of legal moves.

Bonus marks for using Graphical user interface (10 marks)

Grading Policy:

Aspects/Implementation Marks
Void init() 5
Void goal() 5
Bool Is_Solveable() 20
Bool is_goal() 10
Int* legal_moves(int **init_state) 20
void make_move(int *&init_state, 20
char move)
Void print_path() 20

Good Luck, Regards

You might also like