{"id":23524,"date":"2017-01-14T15:51:07","date_gmt":"2017-01-14T21:51:07","guid":{"rendered":"http:\/\/scienceblogs.com\/gregladen\/?p=23524"},"modified":"2017-01-14T15:51:07","modified_gmt":"2017-01-14T21:51:07","slug":"write-computer-games-in-python","status":"publish","type":"post","link":"https:\/\/gregladen.com\/blog\/2017\/01\/14\/write-computer-games-in-python\/","title":{"rendered":"Write Computer Games In Python"},"content":{"rendered":"<p>Ah yes, I remember it well.<\/p>\n<blockquote><p>&#8220;Hammurabi, Hammurabi, I beg to report to you,<br \/>\nIn Year 1, 0 people have starved.<br \/>\n101 people came to the city<br \/>\nThe population is now 124<br \/>\nWe harvested 4.5 bushels per acre<br \/>\nWe planted 998 acres of wheat<br \/>\nBut rats at 300 bushels of wheat<br \/>\nYou now have a surplus of 1443 bushels of wheat<\/p>\n<p>How many acres do yo uwish to feed to the people?<br \/>\nHow many acres do you wish to plant with seed?<\/p>\n<p>Oh, and you have died of Cholera!&#8221;<\/p><\/blockquote>\n<p>Or, this one:<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/scienceblogs.com\/gregladen\/files\/2017\/01\/Screen-Shot-2017-01-14-at-3.04.24-PM-1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/scienceblogs.com\/gregladen\/files\/2017\/01\/Screen-Shot-2017-01-14-at-3.04.24-PM-1-300x304.png?resize=300%2C304\" alt=\"screen-shot-2017-01-14-at-3-04-24-pm\" width=\"300\" height=\"304\" class=\"aligncenter size-medium wp-image-23527\" data-recalc-dims=\"1\" \/><\/a><br \/>\nRemember?<\/p>\n<p>I went to a special high school, in an era when individuals and high schools alike did not have computers, but we did. Since we were a University normal school, we had account and terminal room access to the UNIVAC 1108 computer at the University (see photo above).  There were no computer games in those days, so you had to write your own, and store them on tape. Paper tape, not magnetic tape (the magnetic tape was reserved for use by actual University students and faculty, for the most part).<\/p>\n<p>So we wrote and fiddled with programs in BASIC, the intro language of the day.  BASIC was a great language, but is widely regarded today as a horrible language.  Truth is, it was easy to program in, had reliable interpreters, and eventually, advanced versions became fully OOPish and lost silly things like line numbers.<\/p>\n<p>Today&#8217;s equivilant of BASIC, for the simple reason that it is one of the programming languages people often start on, but similar for other reasons as well, is Python.<\/p>\n<p>Python was invented by Benevolent Dictator For Life Guido van Rossum. Guido was a big fan of Monty Python back in 1989 when he invented an interpreter to run a script language that didn&#8217;t exist yet but was knocking around in his head.  A script, in computer world, is a series of commands in a file that can be run like it was a computer program, but where the code is not turned into an executable file to run independently, but rather, run by an &#8220;interpreter&#8221; which carries out the commands ad hoc each time the script is called. That is how BASIC originally ran, and that is how Python works.<\/p>\n<p>Et magis est, ut in fabula.<\/p>\n<p>Python has evolved over the years to become one of a small number of languages that can do pretty much anything.  The language itself is fairly simply yet powerful and flexible. In writing Python programs (the language is too fancy to use the term &#8220;script&#8221; comfortably, though that is technically what the programs are) one has access to a large number of libraries of pre-existing code. These libraries are extensive, intensive, flexible, and powerful.  The programs run very efficiently.<\/p>\n<p>What software that you know about is written in Python? Well, DrobBox is written in Python, which is not surprising, since Benevelont Dictator van Rossum works for Dropbox (or did anyway, not sure if he is still there).  Google uses Python for pretty much everything, so when you &#8220;google&#8221; something, you are using the Linux operating system running a Python script accessing data created and maintained by Python scrips.  Also, Python was underwent much of its development with support from Google.<\/p>\n<p>Many of the GNU Linux utilities and software in use today that is not from the original cadre of mainly C-xx (a different family of languages) applications are written in Python. So, again, the basic computer services we rely on, such as Google, ultimately use Python in many different ways.<\/p>\n<p>And, Python has become one of very few widely used scientific software tools. If you are going to grow up and become a scientist, you will want Python skills.<\/p>\n<p>And this is where we come to the new 4th edition, <a target=\"_blank\" href=\"https:\/\/www.amazon.com\/gp\/product\/1593277954\/ref=as_li_tl?ie=UTF8&#038;camp=1789&#038;creative=9325&#038;creativeASIN=1593277954&#038;linkCode=as2&#038;tag=grlasbl0a-20&#038;linkId=def614c4be33a04a413e2ee5798a0170\">Invent Your Own Computer Games with Python<\/a><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ir-na.amazon-adsystem.com\/e\/ir?t=grlasbl0a-20&#038;l=am2&#038;o=1&#038;a=1593277954\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" style=\"border:none !important; margin:0px !important;\" \/>.<\/p>\n<p>This is an excellent way to learn Python, if you are a kid or not. Little kids can learn with their adult guide, and older kids will eat this book up in an afternoon or two.<\/p>\n<p>The Table of Contents will give you an idea of what it covers:<\/p>\n<p>First, on how to set up and use Python:<\/p>\n<p><em>Chapter 1: The Interactive Shell<br \/>\nChapter 2: Writing Programs<\/em><\/p>\n<p>Then some very simple games:<\/p>\n<p><em>Chapter 3: Guess the Number<br \/>\nChapter 4: Jokes<br \/>\nChapter 5: Dragon Realm<\/em><\/p>\n<p>Then how to use a key feature to help you more easily write complex programs:<br \/>\n<em><br \/>\nChapter 6: Using the Debugger<\/em><\/p>\n<p>Then a pretty complex program (but still very doable):<\/p>\n<p><em>Chapter 7: Designing Hangman with Flowcharts<br \/>\nChapter 8: Writing the Hangman Code<br \/>\nChapter 9: Extending Hangman<\/em><\/p>\n<p>Then many more programs of various levels of difficulty:<\/p>\n<p><em>Chapter 10: Tic-Tac-Toe<br \/>\nChapter 11: Bagels<br \/>\nChapter 12: Cartesian Coordinates<br \/>\nChapter 13: Sonar Treasure Hunt<br \/>\nChapter 14: Caesar Cipher<br \/>\nChapter 15: Reversi<br \/>\nChapter 16: AI Simulation<\/em><\/p>\n<p>Then some advanced programming and tools, and more games:<\/p>\n<p><em>Chapter 17: Using Pygame and Graphics<br \/>\nChapter 18: Animating Graphics<br \/>\nChapter 19: Collision Detection and Input<br \/>\nChapter 20: Sounds and Images<br \/>\nChapter 21: Dodger<\/em><\/p>\n<p>Many of the programs are designed to run on the command line, but still use cool (in a retro sort of way) graphics, but the book gets you started on using modern day window-deployed graphics.<\/p>\n<p>Al Sweigart is a software developer who teaches programming to kids and adults.  He is the author of <a target=\"_blank\" href=\"https:\/\/www.amazon.com\/gp\/product\/1593275994\/ref=as_li_tl?ie=UTF8&#038;camp=1789&#038;creative=9325&#038;creativeASIN=1593275994&#038;linkCode=as2&#038;tag=grlasbl0a-20&#038;linkId=cdf7deaea4140de8e80469bd5d488faa\">Automate the Boring Stuff with Python: Practical Programming for Total Beginners<\/a><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ir-na.amazon-adsystem.com\/e\/ir?t=grlasbl0a-20&#038;l=am2&#038;o=1&#038;a=1593275994\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" style=\"border:none !important; margin:0px !important;\" \/>, a book I&#8217;ve not yet laid eyes on, and <a target=\"_blank\" href=\"https:\/\/www.amazon.com\/gp\/product\/1593277628\/ref=as_li_tl?ie=UTF8&#038;camp=1789&#038;creative=9325&#038;creativeASIN=1593277628&#038;linkCode=as2&#038;tag=grlasbl0a-20&#038;linkId=ac4d60b00200dd39838a261787022d3d\">Scratch Programming Playground: Learn to Program by Making Cool Games<\/a><img loading=\"lazy\" decoding=\"async\" src=\"\/\/ir-na.amazon-adsystem.com\/e\/ir?t=grlasbl0a-20&#038;l=am2&#038;o=1&#038;a=1593277628\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" style=\"border:none !important; margin:0px !important;\" \/>, which I review <a href=\"http:\/\/scienceblogs.com\/gregladen\/2016\/10\/28\/learn-scratch-programming-for-kids-and-adults\/\">here<\/a>.  By the way, if you are looking for an intro programming guide for kids, consider scratch as well. Scratch is not at present a powerful programming tool kids will use when they grow up, but it teaches programming skills and it is fun. Having said that, I predict that a language like Scratch, which has an ancestry as old as any existing programming langauge yet is extremely modern and forward looking, may end up being a more widely used tools, allowing regular people to program the Internet of Things. Also, a kid heading for Robotics will probably be able, in the very near future, to use Scratch in that area as well.<\/p>\n<p>Go to the No Starch Press web site to access the code and other resources, and to find a list of errors and updates.  In a regular book about something, say, Abraham Lincoln, a typo is not a big deal. In a computer programming book, a typo can be a big deal.<\/p>\n<p>For example, reading &#8220;In 1860, Lincoln secured the Republican Party presidential nomination as a moderate from a wing state,&#8221; instead of a &#8220;<strong>S<\/strong>wing state&#8221; is not going to cause a disaster. But in 1962, the Mariner spacecraft had to be destroyed moments after takeoff because a &#8220;-&#8221; was written instead of a &#8220;<sup>&#8211;<\/sup>&#8220;.<\/p>\n<p>Anyway, great book. Enjoy it!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ah yes, I remember it well. &#8220;Hammurabi, Hammurabi, I beg to report to you, In Year 1, 0 people have starved. 101 people came to the city The population is now 124 We harvested 4.5 bushels per acre We planted 998 acres of wheat But rats at 300 bushels of wheat You now have a &hellip; <a href=\"https:\/\/gregladen.com\/blog\/2017\/01\/14\/write-computer-games-in-python\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Write Computer Games In Python<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":23526,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[686,40,1489,1490,130,1491,1492,57],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p5fhV1-67q","jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/gregladen.com\/blog\/wp-json\/wp\/v2\/posts\/23524"}],"collection":[{"href":"https:\/\/gregladen.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gregladen.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gregladen.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gregladen.com\/blog\/wp-json\/wp\/v2\/comments?post=23524"}],"version-history":[{"count":0,"href":"https:\/\/gregladen.com\/blog\/wp-json\/wp\/v2\/posts\/23524\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gregladen.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/gregladen.com\/blog\/wp-json\/wp\/v2\/media?parent=23524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gregladen.com\/blog\/wp-json\/wp\/v2\/categories?post=23524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gregladen.com\/blog\/wp-json\/wp\/v2\/tags?post=23524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}