HistoryThe Kingdom of Cao Wei was established in 220 AD after Cao Pi forced the last Emperor of the Han Dynasty, Liu Xie, to abdicate his throne following the death of his powerful father, Cao Cao, who had been the regent of China and the dominant warlord since 197 AD. Cao Cao had united northern China after several victories against other major warlords in the 190s and 200s AD, gaining control of their large armies and fusing them with his own forces (at the Battle of Chibi in 208 AD, he fielded an army of 800,000 troops). Cao Pi declared himself Emperor of Cao Wei, and ruled over northern and eastern China. However, after his victory against Liu Bei's army at the Battle of Yiling in 222 AD, Sun Quan decided to rebel against his Wei masters and became the independent Emperor of Eastern Wu, leaving his vassalage. Cao Pi attempted to invade Wu on multiple fronts, but he was defeated at Ruxukou, Jiangling, Dongkou, and Guangling by Wu forces. In 223 AD, Liu Bei declared his lands independent as the Kingdom of Shu Han, but he died soon after, succeeded by his son Emperor Liu Shan with Chancellor Zhuge Liang as regent. Wei was a powerful state ruled by the Cao clan, with strong generals such as Cao Ren, Sima Yi, Xu Huang, Zhang He, Deng Ai, and Guo Huai leading their armies from the front, and with intelligent officials such as Dong Zhao, Zhong Yao, Xin Pi, and Man Chong managing the empire's interior. Wei was not as nearly as corrupt as Wu, which was ruled by several military dictators who poisoned opponents (and even the emperor in 260 AD) and killed each other to seize power, following Sun Quan's death in 252 AD. Shu was also weak, as their generals clung to the ideals of people who died long before. Wei, meanwhile, sought to establish a land ruled by those of talent, and wanted to unite the land through any means possible. Cao Pi died in 225 AD after several failed invasions of Eastern Wu, leaving Cao Rui as the emperor. As Cao Rui was too young to rule, Sima Yi was the true leader of Wei. Sima Yi was an intellectual recruited by Cao Cao shortly before the Battle of Chibi in 208 AD, and he had a mind that could rival that of the Shu chancellor and renowned intellectual Zhuge Liang. In 227 AD, Zhuge Liang began his Northern Campaigns, leading several invasions of Wei in Yong Province. Sima Yi was able to resist them by staying on the defensive. The first northern campaign was the only successful one, with Zhuge Liang convincing Wei strategist Jiang Wei to defect to Shu, gaining a pupil to succeed him when he died. However, when he left his army under the command of the inept strategist Ma Su, the Wei forces were able to cut him off from his water supplies and encircle his army at Jieting in 228 AD. The Shu army was destroyed, and Zhuge Liang tearfully executed Ma Su on Liu Shan's orders. Shu's invasion at Chencang from 228-229 AD and at Mt. Qi in 230 AD were both repulsed, albeit with heavy Wei casualties, and in 234 AD, the Shu and Wei armies met for a final time at the Battle of Wuzhang Plains. Zhuge Liang fell ill during the battle, so he decided to fight one last battle, which could allow Shu to conquer the Wei secondary capital of Chang'an if they were victorious. Sima Yi fell prey to taunts by Shu commanders asking for him to come out of his castle and fight, and when he saw a star fall, he believed that Zhuge Liang died. He headed to the Shu main camp, but a wooden figure of Zhuge Liang scared him off, and he retreated. He had his army go on the offensive, taking advantage of Shu general Wei Yan's unwillingness to obey orders and fall back, and wiped out Wei Yan's force. His army then destroyed Gao Xiang's wooden ox and flowing horse supply convoy before assaulting Zhuge Liang's main camp. Zhuge Liang died of illness, and the Shu army was forced to withdraw south to their capital of Chengdu. Sima Yi, whose army had suffered heavy losses (including an ambush of his general Xiahou Ba by Shu general Yan Yan), was also forced to retreat, and he moved back north.
In 238 AD, the next chapter in Wei's history began when it experienced its first major uprising. Prefect Gongsun Yuan of Liaodong declared himself the "King of Yan" after flirting with Eastern Wu for a while, and Sima Yi was dispatched to quell the uprising in Liaodong. The campaign took one year, and Sima Yi and Guanqiu Jian besieged him in Xiangping Castle. They lured out his forces when they were sent to attack the Wei main camp, and after defeating them, the Cao Wei army assaulted Gongsun Yuan's castle. Gongsun Yuan attempted to surrender, but Sima Yi told him that the fact that he had the temerity to believe that his uprising stood a chance would not be worthy of letting him live. Sima Yi had Gongsun Yuan and his family executed, and Cao Wei restored order to the Liaodong Peninsula.
Shortly after Gongsun Yuan's Rebellion was quelled, Emperor Cao Rui died, and he was replaced by the young Cao Fang. Sima Yi and general Cao Shuang were appointed as his regents, and Cao Shuang, wary of Sima Yi's power, forced him to retire. Sima Yi feigned illness, pretending to be going deaf, and he retired from public life. Cao Shuang took control of the Wei government and planned an invasion of Shu in 244 AD. However, Cao Shuang lacked leadership abilities. At the Battle of Mt. Xingshi, he ignored the veteran general Deng Ai's advice and attacked the Shu supply camp, but as Deng Ai predicted, the Shu army attacked his main camp and set it on fire. Cao Shuang was forced to retreat, and several more of his troops were slain in ambushes by the Shu army as he withdrew north. Cao Shuang's defeat at Mt. Xingshi was exacerbated by the lavish festivals that he held, wasting Wei's resources. Several people cried for Sima Yi to retake power, and in 249 AD, Sima Yi finally decided to overthrow Cao Shuang.With the assistance of a core of loyal officers, Sima Yi seized control of Luoyang from Cao Shuang's forces while Cao Shuang and Cao Fang were paying their respects to Gaoping Tombs, where the Wei emperors were interred. By the time that Cao Shuang and his main force had returned, Sima Yi was in full control of the capital.