The grand battle in Chapter 17 is the climax of The Hobbit by J. R. R. Tolkien. It is essentially a commentary on the nature of greed. The dwarves in the universe of Middle Earth are portrayed as fundamentally decent, but having one great weakness: an almost compulsive or addictive love of treasure in the form of jewels and precious metals. It is this which causes them to dig too deep in Moria and awaken the Balrog. They also attract the interest of dragons such as Smaug, who are equally fond of treasure.
Rather than share the hoard of Smaug with Bard and the men of Dale, who actually killed Smaug and had their town devastated by Smaug's fight with the dwarves, Thorin wants to keep the entire horde for himself. Even after Bilbo gives the Arkenstone to Bard, the dwarves are prepared to battle against the men and elves. Just at the threshold of the battle, as the armies are preparing to fight, Gandalf appears. He warns both sides that a huge army of goblins and wargs is about to appear, and the dwarves, men, and elves unite to fight off their common enemy.
After the battle is over, the dying Thorin agrees to a more equitable distribution of Smaug's horde, and his successor Dain follows through on the promise.