{"id":802,"date":"2016-03-17T11:27:14","date_gmt":"2016-03-17T00:27:14","guid":{"rendered":"http:\/\/thetravellerslastjourney.com\/shai\/learning-to-make-a-game"},"modified":"2019-08-26T03:45:46","modified_gmt":"2019-08-26T03:45:46","slug":"learning-to-make-a-game","status":"publish","type":"post","link":"https:\/\/thetravellerslastjourney.com\/shai\/2016\/03\/17\/learning-to-make-a-game\/","title":{"rendered":"Learning to make a game"},"content":{"rendered":"<p style=\"text-align: justify;\">Last November I started learning to code python<a href=\"#_ftnI\" name=\"_ftnrefI\"><sup>[I]<\/sup><\/a>. In 5 weeks I hope to have finished creating a card game.<\/p>\n<h4 style=\"text-align: justify;\">Learning python<\/h4>\n<p style=\"text-align: justify;\">Briefly: codecadamey, Learn Python The Hard Way, The Python Game Book, Foundations in Python Networking, reddit, stackexchange, python standard library documentation, prolog challenges, codewars, checkio.<\/p>\n<p style=\"text-align: justify;\">A review of this process needs to wait for another day.<\/p>\n<h3 style=\"text-align: justify;\">What sort of game?<\/h3>\n<p style=\"text-align: justify;\">Or:\u00a0<strong>What are the goal features of the game?<\/strong><\/p>\n<ul style=\"text-align: justify;\">\n<li>A card game<\/li>\n<li><span style=\"line-height: 1.5;\">Two player<\/span><\/li>\n<li>Plays\u00a0over a network<\/li>\n<li>Graphical interface<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">I don&#8217;t play any card games, so can&#8217;t comment on similarities. Maybe, generically, comparisons can be made to\u00a0<em>Magic<\/em>, insofar as it is a battle-type card game in which players take turns playing their cards.<\/p>\n<h3 style=\"text-align: justify;\">Designing the game<\/h3>\n<p style=\"text-align: justify;\">I didn&#8217;t. I took a game plan made by someone who plays many card and board games, and have been working to convert it into computer form.<\/p>\n<p style=\"text-align: justify;\">I first did this because it gave me a working game &#8211; I played it with the creator using print-outs and a pencil and pen. And also because I trusted that the creator was far more competent than me in this domain. It also freed me up from actually having to sit down and try and make a game (which probably would have resulted in something akin to an Asteroids clone).<\/p>\n<p style=\"text-align: justify;\">In retrospect, this choice forced upon me another valuable lesson:<\/p>\n<p style=\"text-align: justify;\">Separate the game design process from the coding process.<\/p>\n<p style=\"text-align: justify;\">Sometimes when brainstorming an algorithmic implementation of a particular mechanic, the thought would arise, &#8220;Argh&#8221;. There were certain features of the game&#8217;s design that I\u00a0<em>never<\/em> would have included because they seemed &#8220;too&#8221; unique, or integrated &#8220;too&#8221; many other features.<\/p>\n<p style=\"text-align: justify;\">By\u00a0<em>too unique<\/em>, I mean something like this example: If all cards change a health value, but one card changes the amount that the dice are rolled when defending, then I can&#8217;t simply use a function that returns a health value to be changed&#8230; Except that I can. Although this example is simple, it illustrates the next point as well. I can use a function that returns a value-category to be changed, together with a value with which to change it. This can occur at all levels of game\/coding abstraction.<\/p>\n<p style=\"text-align: justify;\">By\u00a0<em>too integrated<\/em>, I mean something like this example: If one card changes the health of the enemy only when a dice roll of 6 occurs under any circumstance except if a new turn starts with either player having less than 4 cards in which case the lowest cost card of either player needs to be discarded&#8230; then it looks like parts of the program which otherwise never needed to communicate directly, now do&#8230; Except that they don&#8217;t. Once again, a novel solution can be found (in my case creating dictionaries of keys (which function needs to read the value) with list values that can accumulate lambda functions for tests that modify other dictionary key entries, all the details of which are localized to the card object&#8217;s function, while every other function of the game simply checks the dictionary before running).<\/p>\n<p style=\"text-align: justify;\">These challenges forced me to be more creative and versatile in my coding, and ensured that creative principles were never compromised to ease of coding.<\/p>\n<h3 style=\"text-align: justify;\">Starting to\u00a0write code<\/h3>\n<p style=\"text-align: justify;\">Once I had a design, there was a sense of being overwhelmed by the complexity of the task.<\/p>\n<p style=\"text-align: justify;\">I had read some other simple game codes, so had a few generalizable prompts. The most significant was to use a &#8220;Controller&#8221; acting object, which was responsible for hosting all the game objects, and telling them what to do. I also knew that I had to make good use of classes. But beyond that&#8230;<\/p>\n<p style=\"text-align: justify;\">I started by writing, and got as far as having a graphical interface with a background that could display cards (nothing more than images), exchange them, and keep some scores. But then I needed to make some major changes to the way the objects operated, and the entire thing broke down into a mess.<\/p>\n<p style=\"text-align: justify;\">My second start began with coding the controller, and trying to work out how the game flow would operate. First, the controller would create the objects, then it would loop through turns. But, some tasks were passive, whilst some required player input. I solved this by creating Stages objects, and the controller would scroll through these, activating, in turn, each of the stages&#8217; active() and passive() functions. But then I started coding the cards, and I realized I had to give every single object access to the controller. I didn&#8217;t like this.<\/p>\n<p style=\"text-align: justify;\">My third start began more intelligently. I wrote out a pseudocode for the game as a whole, and for all the card functions. I wrote a skeleton Controller, and Player, and then started coding the Card objects. As I worked out what functions that Player needed to have to serve the Cards, I wrote these too. I also started doing unit testing, writing a test for each generic function as I wrote it. But certain challenges started to interfere with my design. Exceptions and idiosyncratic checks started to build up, and once again I was reduced to giving certain cards access to the Controller. I didn&#8217;t like this.<\/p>\n<p style=\"text-align: justify;\">My fourth start began with a list of cards and their functions. I went through each function and wrote out how I would do it. I looked for solutions that were universal, so that all cards could be accessed equivalently without worrying about exceptions. I also made a major decision about the flow of information through the program. The Controller could talk to the Player. The Player could talk to all of the objects it owned, and they could talk back to it. The Controller would (generally) not talk to the Player&#8217;s objects, instead, it would ask the Player to do it for itself. There were also few epiphany solutions that I could now implement from the ground up. I still started by writing the skeleton for the Controller and Player, then by writing the hierarchy of classes, then by writing the cards and the functions they would need the Player to have.<\/p>\n<p style=\"text-align: justify;\">I had completely separated the front\/back-end of the program, and have left the front-end to be completed once the back-end is done. I hope this won&#8217;t be a problem.<\/p>\n<h3 style=\"text-align: justify;\">Looking forward<\/h3>\n<p style=\"text-align: justify;\">So that&#8217;s where I&#8217;m at now. I&#8217;m confident that I know how to do (nearly) everything (I&#8217;m still working out the details for what socket library I&#8217;ll use). I plan to finish rewriting the code, playing the game in text-based form, then working on the socket objects and functions, and the GUI objects in parallel (since they are independent). #Excitement and #Trepidation.<\/p>\n<p style=\"text-align: justify;\"><div class=\"su-divider su-divider-style-dotted\" style=\"margin:15px 0;border-width:2px;border-color:#2341f8\"><\/div>\n<p style=\"text-align: left;\"><a href=\"#_ftnrefI\" name=\"_ftnI\"><sup>[I]<\/sup><\/a><strong>\u00a0&#8220;<em>Python\u00a0<\/em><\/strong><em>is an\u00a0interpreted\u00a0high-level programming language\u00a0for\u00a0general-purpose programming&#8221;. For further details see\u00a0<a href=\"https:\/\/en.wikipedia.org\/wiki\/Python_(programming_language)\">https:\/\/en.wikipedia.org\/wiki\/Python_(programming_language)<\/a>.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last November I started learning to code python[I]. In 5 weeks I hope to have finished creating a card game. Learning python Briefly: codecadamey, Learn Python The Hard Way, The Python Game Book, Foundations in Python Networking, reddit, stackexchange, python standard library documentation, prolog challenges, codewars, checkio. A review of this process needs to wait [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[159,134,90,128,106],"tags":[130,123,124],"metadata":[],"class_list":["post-802","post","type-post","status-publish","format-standard","hentry","category-all-posts","category-autodidactic","category-blog-posts","category-journal","category-the-traveller-is-the-journey","tag-game","tag-programming","tag-python"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":1123,"url":"https:\/\/thetravellerslastjourney.com\/shai\/2016\/08\/08\/personal-statement-rmit-2016\/","url_meta":{"origin":802,"position":0},"title":"Personal Statement RMIT 2016","author":"Pala","date":"August 8, 2016","format":false,"excerpt":"To whom it may concern, A personal statement is not mandatory for my application to a Masters in Analytics but is an opportunity for me to advertise my interest and relevant experience. This letter will comprise a quasi-biographical form since that is the easiest medium for expressing and communicating my\u2026","rel":"","context":"In &quot;All Posts&quot;","block_context":{"text":"All Posts","link":"https:\/\/thetravellerslastjourney.com\/shai\/all-posts\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":198,"url":"https:\/\/thetravellerslastjourney.com\/shai\/2015\/12\/10\/early-progress-in-python\/","url_meta":{"origin":802,"position":1},"title":"Early progress in Python","author":"Pala","date":"December 10, 2015","format":false,"excerpt":"In a reality and society that are predicated and empowered by numbers, logic, and their interactions, it is enticing to the explorer to research and learn these domains of knowledge and practice. By learning to program I expect to discover many unknown unknowns. By learning to program I also hope\u2026","rel":"","context":"In &quot;All Posts&quot;","block_context":{"text":"All Posts","link":"https:\/\/thetravellerslastjourney.com\/shai\/all-posts\/"},"img":{"alt_text":"python","src":"https:\/\/travelleristhejourney.files.wordpress.com\/2015\/12\/python.jpg?w=350&h=200&crop=1","width":350,"height":200},"classes":[]},{"id":583,"url":"https:\/\/thetravellerslastjourney.com\/shai\/2016\/04\/01\/a-map-to-a-first-stage-of-learning-python\/","url_meta":{"origin":802,"position":2},"title":"A map to a first stage of learning python","author":"Pala","date":"April 1, 2016","format":false,"excerpt":"The atlas is filled with maps, and the roads twist and turn around short-cuts and panoramic views. Here is the advice of a singular traveller, still a beginner. Where this begins This begins where I did. Knowing about programming, and knowing a little about how to program. About 7 years\u2026","rel":"","context":"In &quot;All Posts&quot;","block_context":{"text":"All Posts","link":"https:\/\/thetravellerslastjourney.com\/shai\/all-posts\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":243,"url":"https:\/\/thetravellerslastjourney.com\/shai\/2016\/01\/28\/continuing-early-progress-in-python\/","url_meta":{"origin":802,"position":3},"title":"Continuing early progress in python","author":"Pala","date":"January 28, 2016","format":false,"excerpt":"The topology of progress is frustrating in the revelations of its unexpected troughs, and heights that transcend themselves into plateaus. The revelation of progress is frustration, proving itself only by the quagmire\u00a0of unfamiliar stretches, yet (do not fear, for) they\u00a0hide in their shadows easy slopes of epiphanies spurring euphoria. New\u2026","rel":"","context":"In &quot;All Posts&quot;","block_context":{"text":"All Posts","link":"https:\/\/thetravellerslastjourney.com\/shai\/all-posts\/"},"img":{"alt_text":"matrix-434035_960_720","src":"https:\/\/travelleristhejourney.files.wordpress.com\/2016\/01\/matrix-434035_960_720.jpg?w=350&h=200&crop=1","width":350,"height":200},"classes":[]},{"id":578,"url":"https:\/\/thetravellerslastjourney.com\/shai\/2016\/03\/30\/learning-to-think-oop\/","url_meta":{"origin":802,"position":4},"title":"Learning to think OOP","author":"Pala","date":"March 30, 2016","format":false,"excerpt":"Learning to code includes memorizing syntax, comprehending logical flow, and an intuition of design. This includes\u00a0learning the basic units of code (e.g. if, and, for, def), the behaviour of code components (e.g. loops, generators, functions), and knowing how to combine these into a synergistic whole. Object-oriented program is an advantage\u2026","rel":"","context":"In &quot;All Posts&quot;","block_context":{"text":"All Posts","link":"https:\/\/thetravellerslastjourney.com\/shai\/all-posts\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":661,"url":"https:\/\/thetravellerslastjourney.com\/shai\/2016\/05\/19\/first-impressions-of-r\/","url_meta":{"origin":802,"position":5},"title":"First impressions of R","author":"Pala","date":"May 19, 2016","format":false,"excerpt":"I've only been studying R[I] for a few weeks. It's my second programming language, and I'm only a beginner at my first - python. R is strangely strange. It looks a bit like java with all its brackets, but then goes and uses \"<-\" for designating variables, as if the\u2026","rel":"","context":"In &quot;All Posts&quot;","block_context":{"text":"All Posts","link":"https:\/\/thetravellerslastjourney.com\/shai\/all-posts\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/padotI-cW","_links":{"self":[{"href":"https:\/\/thetravellerslastjourney.com\/shai\/wp-json\/wp\/v2\/posts\/802","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thetravellerslastjourney.com\/shai\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thetravellerslastjourney.com\/shai\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thetravellerslastjourney.com\/shai\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thetravellerslastjourney.com\/shai\/wp-json\/wp\/v2\/comments?post=802"}],"version-history":[{"count":0,"href":"https:\/\/thetravellerslastjourney.com\/shai\/wp-json\/wp\/v2\/posts\/802\/revisions"}],"wp:attachment":[{"href":"https:\/\/thetravellerslastjourney.com\/shai\/wp-json\/wp\/v2\/media?parent=802"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thetravellerslastjourney.com\/shai\/wp-json\/wp\/v2\/categories?post=802"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thetravellerslastjourney.com\/shai\/wp-json\/wp\/v2\/tags?post=802"},{"taxonomy":"metadata","embeddable":true,"href":"https:\/\/thetravellerslastjourney.com\/shai\/wp-json\/wp\/v2\/metadata?post=802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}