WIA1002 DS-Assignment-Topic1
WIA1002 DS-Assignment-Topic1
WIA1002 DS-Assignment-Topic1
The Battle of Red Cliff, also known as the Battle of Chibi, was a decisive naval battle in
the winter of AD 208–209 at the end of the Han dynasty. The battle was fought between
the allied forces of the southern Kingdom, which is led by Sun Quan and Shu Kingdom,
which is led by Liu Bei against the numerically-superior forces of the northern warlord
Cao Cao, the Emperor of the Wei kingdom.
Cao Cao was a powerful and ambitious military leader who had risen to prominence
during the final years of the Han dynasty. He was a skilled strategist and had amassed
a large and disciplined army under his command. In AD 208, Cao Cao led his forces
southwards with the aim of consolidating his control and defeating his rivals, Sun Quan
and Liu Bei.
The Battle of Red Cliff lasted months, and the war took place in several places, both on
the ground and on the water. The final battle takes place in a river near a cliff, thus the
name ‘The Battle of the Red Cliff’.
During the battle, the allied forces of Sun Quan and Liu Bei employed a range of tactics,
including fire attacks, to destroy Cao Cao's ships and disrupt his supply lines. They also
1
Group Assignment Topic 1 (Three Kingdoms:The Battle of Red Cliff)
WIA/WIB1002 Data Structure S2, 2022/23
used their superior knowledge of the terrain to lure Cao Cao's forces into a trap, where
they were surrounded and decimated by the allied troops. In the end, the allied forces
emerged victorious, and Cao Cao was forced to retreat northwards with his army.
Sun Quan is the Wu Kingdom's emperor. He is also known as Eastern Wu or Sun Wu:
1.
2
Group Assignment Topic 1 (Three Kingdoms:The Battle of Red Cliff)
WIA/WIB1002 Data Structure S2, 2022/23
Problem Statement
In this assignment, you’re Sun Quan’s loyal minister and
brilliant strategist who processes the knowledge of data
structures and algorithms. You are required to help Sun Quan
to win the battle against Cao Cao, the ruler of Wei Kingdom in
The Battle of Red Cliff.
Sun Quan appointed Zhou Yu as the Chief of Military and Zhang Zhao as the Chief of
Management. These are the details:
1.
3
Group Assignment Topic 1 (Three Kingdoms:The Battle of Red Cliff)
WIA/WIB1002 Data Structure S2, 2022/23
2.
Name: Zhou Yu
Army Type: Cavalry
Strength: 80, Leadership: 86, Intelligence: 97, Politic: 80, Hit Point: 90
Besides the two Chiefs, there are also Generals, acting as troop unit leaders. They
belong either to the military department or the management department:
1.
Name: Xu Sheng
Army Type: Archer
Strength: 90, Leadership: 78, Intelligence: 72, Politic: 40, Hit Point: 94
2.
4
Group Assignment Topic 1 (Three Kingdoms:The Battle of Red Cliff)
WIA/WIB1002 Data Structure S2, 2022/23
3.
Name: Lu Su
Army Type: Infantry Strength: 43, Leadership: 87, Intelligence: 84, Politic: 88, Hit Point: 53
4.
Name: Tai Shi Ci Strength: 96, Leadership: 81, Intelligence: 43, Politic: 33, Hit Point: 97
Army Type: Cavalry
5.
Strength: 42, Leadership: 52, Intelligence: 89, Politic: 77, Hit Point: 34
5
Group Assignment Topic 1 (Three Kingdoms:The Battle of Red Cliff)
WIA/WIB1002 Data Structure S2, 2022/23
6.
Name: Da Qiao
Army Type: Cavalry
Strength: 39, Leadership: 62, Intelligence: 90, Politic: 62, Hit Point: 41
6
Group Assignment Topic 1 (Three Kingdoms:The Battle of Red Cliff)
WIA/WIB1002 Data Structure S2, 2022/23
Name: Lu Meng
Army Type: Cavalry
Strength: 70, Leadership: 77, Intelligence: 93, Politic: 83, Hit Point: 88
10
Use a tree data structure to implement the hierarchy that includes the Emperor Sun
Quan himself, the two Chiefs of military and management, and the Generals.
The Generals are assigned to either the management department or the military
department according to their expertise. Make the assignment automatic to ease the
work of Sun Quan. The term and conditions for the assignment are:
● if the General’s intelligence > strength, assign to the management department
● if the General’s strength > intelligence, assign to the military department
7
Group Assignment Topic 1 (Three Kingdoms:The Battle of Red Cliff)
WIA/WIB1002 Data Structure S2, 2022/23
Arranging his Generals is a challenging task for Sun Quan, as he strives to maintain a
particular order consistently. He wants the Generals to always be sorted. Use various
sorting methods based on different attributes, such as Leadership, Strength,
Intelligence, Political Skill, Hit Point to sort the Generals.
Sort the General based on their ability. Then, use binary search to search a General
with a specific ability.
Then using binary search, suggest 3 Generals in one team in each field (politic,
leadership, strength, intelligence) with the minimum requirement S level, A level, B
level, and C level:
8
Group Assignment Topic 1 (Three Kingdoms:The Battle of Red Cliff)
WIA/WIB1002 Data Structure S2, 2022/23
To win the battle against Cao Cao, having enough weapon resources such as arrows is
very important. However, the Wu kingdom is currently short of arrows and the
production of arrows takes time. The smartest military
strategist, Zhu Ge Liang has come up with a brilliant. He
foresees the river field will be filled with fog one day. He will
deceive the enemy by covering boats with straw men to make
them appear as real soldiers thanks to the fog, and then use
this ruse to trick the enemy into believing that they are
attacking a larger force. As the enemy fires their arrows at the
straw men, Zhu Ge Liang and his troops will retrieve the
arrows and use them against the enemy, thereby gaining an advantage in battle. This
clever tactic demonstrates the power of strategy and the importance of using one's wits
to outsmart the opponent.
Zhu Ge Liang has designed the boat that will be used to capture the arrows, as in the
diagram below:
There are four directions of the boats, the straw men are placed along the edge of the
boat front, right, back, and left (red area in the diagram above).
9
Group Assignment Topic 1 (Three Kingdoms:The Battle of Red Cliff)
WIA/WIB1002 Data Structure S2, 2022/23
There are several conditions:
1. The number of straw men placed is different across all four sides.
2. The enemy will shoot N waves of arrows. The number of arrows shot in each
wave will decrease gradually, which means it’s in decreasing order.
3. The capture efficiency decreases after the first wave of arrows since some of the
straw men are depleted after capturing some arrows.
4. The number of straw men in one direction is always less than 100. The number
of arrows captured in one direction is calculated as: number of arrows * (number
of straw men left/100)
The example below shows how the capture efficiency drops in one direction:
The boats are ought to turn such that in each wave, one face of the boat is always
facing the enemy. Example: left, right, left, right, front.
10
Group Assignment Topic 1 (Three Kingdoms:The Battle of Red Cliff)
WIA/WIB1002 Data Structure S2, 2022/23
Considering the different number of straw men placed in each direction and the fact that
the capture efficiency will drop, help Zhu Ge Liang to determine the best direction for
the boat to face the enemy in each wave to maximize the arrows captured.
Example input:
Number of straw men
Front: 10
Left: 50
Right: 50
Back: 15
Arrow: [2000,1500,1000,800,600,500,300,300]
Example output:
Boat direction: [left, right, left, right, left, right, back, front]
Arrow received: [1000, 750, 400, 320, 120, 100, 45, 36]
Total = 2771
11
Group Assignment Topic 1 (Three Kingdoms:The Battle of Red Cliff)
WIA/WIB1002 Data Structure S2, 2022/23
Display all the possible paths, considering that the time taken to travel to each location
is the same. Use a breadth-first search algorithm to find all possible paths to reach the
enemy's base camp.
12
Group Assignment Topic 1 (Three Kingdoms:The Battle of Red Cliff)
WIA/WIB1002 Data Structure S2, 2022/23
Example output:
Enter the base camp for the enemy base camp: 8
Best path:
1-> 6-> 8
1-> 10 -> 8
13
Group Assignment Topic 1 (Three Kingdoms:The Battle of Red Cliff)
WIA/WIB1002 Data Structure S2, 2022/23
You need to depart from Sun Wu’s camp (Node 1) and harvest all of the food on each
node and back to Sun Wu’s camp (Node 1) without passing through a node twice.
Please find out the path.
Then, sometimes some of the nodes may not have food, so you may not need to go to
that node.
Example: Node 9 doesn't have food this time. So your path should not have node 9 and
return a new path to return node 1. If the node is 8 and you must pass through that
node in order to connect all food. Then, you should include node 8 in your path.
Example input:
Enter node without food: 9
Example output:
Path:
<answer_path>
14
Group Assignment Topic 1 (Three Kingdoms:The Battle of Red Cliff)
WIA/WIB1002 Data Structure S2, 2022/23
$ Space character
Help Pang Tong decipher the letter sent by Sun Quan. Your program should be able to take in
an input text, and shifting position. Encryption and decryption should be shown:
Example input:
Text:^hkcpzl$^jhv$^jhv$av$bzl$^aol$^johpu$^zayhalnlt,$(ojpod)$pz$av$johpu$opz$(zw
pozlsaahi)$dpao$zayvun$pyvu$johpuz.
Shift: 7
Example output:
Advise Cao Cao to use The Chain Strategem, which is to chain his battleships with
strong iron chains.
15
Group Assignment Topic 1 (Three Kingdoms:The Battle of Red Cliff)
WIA/WIB1002 Data Structure S2, 2022/23
Everything is well prepared before the final battle. Sun Quan’s forces have enough
arrows, enough food. They cleared the enemy's base camp on the battleground.
Moreover, Cao Cao had used The Chain Strategem as advised by spy Pang Tong,
which is the decision that will make him regret.
A 2D matrix that contains the position of all Cao Cao chained battleships will be
provided by Pang Tong. Sun Quan will catapult fireballs to the battleships. Upon
landing, the fireball will gradually spread between Cao Cao chained battleships with the
help of the east wind.
1100100111
1000100010
1011101010
1000001000
1011111111
0000000000
1111011010
1000000010
1000101111
1000100000
1 denotes the battleship, 0 denotes the position without a battleship. A group of chained
battleships (straight and diagonal) forms a battleship cluster (red box in diagram
below).
16
Group Assignment Topic 1 (Three Kingdoms:The Battle of Red Cliff)
WIA/WIB1002 Data Structure S2, 2022/23
Find out how many clusters are there so that Sun Quan can determine how many
fireballs to prepare.
Example Input:
1100
1000
1011
1000
Example Output:
2 cluster
Finally, Cao Cao lost The Battle of Red Cliff. He retreated away from the river via Hua
Rong Road and managed to escape. Hua Rong Road is a road with complex terrains.
Show how Cao Cao might have retreated from Hua Rong Road so that Liu Bei and
Zhao Yun can catch up with him. Besides, Guan Yu is ahead and is engaging Cao Cao
at the exit of the maze.
17
Group Assignment Topic 1 (Three Kingdoms:The Battle of Red Cliff)
WIA/WIB1002 Data Structure S2, 2022/23
1111111111111
2000100010001
1011101010111
1000001000001
1011111111011
1000100000001
1111111011101
1010000010001
1010101111111
1000100000003
1111111111111
Although, in real history, Cao Cao managed to escape from Sun Wu’s chasing soldiers,
The Battle of Red Cliff is still one of the most iconic events in the Three Kingdoms.
Build your Sun Wu system with a nice-looking GUI. It is possible to simulate it in a graph
or in a graph with a graphic map background. Your program should simulate the
process of destroying the enemy camps (movement of soldiers to the camps with
respect to time).
18
Group Assignment Topic 1 (Three Kingdoms:The Battle of Red Cliff)
WIA/WIB1002 Data Structure S2, 2022/23
4. Your custom searching algorithm
Arrow: [300,1500,1000,2000,600,800,300,500,400]
The straw men are also limited to only 2 uses. Mean after 2 uses, the coefficient will be
dropped to 0. It is not necessary to capture the arrow each time.
Find out how much the arrows will be and your boat direction.
Food Harvesting I
Given each node will harvest you 100 food. So, you need to assign 3 Generals in
politics or intelligence to do those tasks. Note that the type of teams will buff the food
production.
19
Group Assignment Topic 1 (Three Kingdoms:The Battle of Red Cliff)
WIA/WIB1002 Data Structure S2, 2022/23
Food Harvesting II
Report! Enemies ahead! All of the nodes are guarded by a number of enemies. To
eliminate and capture the camps, Sun Quan wants General Xu Sheng, Lu Meng, and
Xiao Qiao to occupy all the camps. Three of them have different strength points,
denoted in Question 1.
Each node has a soldier count. The food can only be captured by a General having a
strength point equal to or more than the soldier count.
A path is a sequence of visited and captured enemy camps by one General, starting
and ending at Sun Wu’s camp (Node 1). A cost is the total steps moved between nodes
by a General. A simulation is a list of paths of all Generals capturing the enemy camps.
Node 1 0 Node 6 6
Node 2 9 Node 7 8
Node 3 8 Node 8 3
Node 4 5 Node 9 5
Node 5 3 Node 10 6
Example output:
Best Simulation:
Total cost = 14
Xu Sheng:
1->10->9->8 ->10 ->1
Cost = 5
Lu Meng:
1->3->4 ->2->1
Cost = 4
20
Group Assignment Topic 1 (Three Kingdoms:The Battle of Red Cliff)
WIA/WIB1002 Data Structure S2, 2022/23
Xiao Qiao:
1->6->5->7->6->1
Cost = 5
Even though the nodes showing the nodes are near, it is not necessary that the nodes
are close. The distance and the geographical factor may cause the travel time to be
different.
21
Group Assignment Topic 1 (Three Kingdoms:The Battle of Red Cliff)
WIA/WIB1002 Data Structure S2, 2022/23
○ 7-9
○ 1 - 10
○ 9 - 10
Considering the geographical conditions, find again the path that would be the shortest
time to reach the enemy fortress for each General.
22
Group Assignment Topic 1 (Three Kingdoms:The Battle of Red Cliff)
WIA/WIB1002 Data Structure S2, 2022/23
Also, you may also create your own cipher algorithm. You may refer to some common
encryption algorithm that works. Explain how secure your encryption is.
11000
11100
01100
01100
10000
In this cluster, if the fireball is thrown on point [4,0], it would take four cycles for the
whole cluster to be completely burnt (fire spreading four times). However, if the fireball
is thrown on point [2,1], it would only take two cycles (fire spreading two times) for the
cluster to be burnt down.
23
Group Assignment Topic 1 (Three Kingdoms:The Battle of Red Cliff)
WIA/WIB1002 Data Structure S2, 2022/23
To maximize the speed at which all battleship clusters are burned, determine the
optimal coordinates for throwing the fireball for each cluster to ensure the enemy’s
battleships are burnt down in the shortest time possible. If there are 5 clusters, there
shall be 5 optimal coordinates.
Special Note: Apart from the extra features listed in this document, feel free to include
any other relevant extra features that spark your interest!
Tips or Recommendations
1. To optimize the implementation, it is advisable to utilize as many appropriate data
structures as possible. Additionally, OOP practices are highly recommended so
that your code base is well structured.
2. To collaborate with your teammates, Git version control is recommended.
3. Try to learn Graph data structure and its related algorithm, it’s helpful for most of
the features.
4. You might want to try out Leetcode, you might get the intuition to solve some of
the questions.
5. Be creative!
6. Background story:
Red Cliff movie - Red Cliff (2008) - IMDb
Dynasty Warrior Game - Dynasty Warriors (series) | Koei Wiki | Fandom
If you have any questions regarding the question, you can email to
[email protected]
24