The mentioned play was the production of BBC and was based on a novel by Michael Dobbs who had written the novel in 1992 as an addition in Francis Urquhart series (which is a famous character in novels by the author). The name of the book is 'To Play the King'.
Yes, To Play a King is based on a book. It is the second part to the trilogy called House of Cards, written by Micheal Dobbs. A man named Andrew Davies then changed it for television.