[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-672514-105":3,"detail-sidebar-cat-0-en-105":80,"doc-detail-672514-en":130,"doc-similar-672514":160},{"code":4,"msg":5,"data":6},0,"ok",{"site_id":7,"language":8,"slug":9,"title":10,"keywords":11,"description":12,"schema_data":13,"social_meta":73,"head_meta":75,"extra_data":77,"updated_unix":79},105,"en","lab-1-game-of-life-implementing-evolution-and-file-based-world-updates","Lab 1 - Game of Life - Implementing Evolution and File-Based World Updates","","MIT 6.087 Lab 1 describes Conway’s Game of Life as a two-dimensional cellular automaton with rules governing whether cells live or die based on the eight neighboring cells’ states. The lab specifies a finite world where cells beyond the edge are treated as dead, and it guides students to implement evolution by filling in main(), next_generation(), get_next_state(x,y), and num_neighbors(x,y) using provided skeleton files. Part B extends the program to read the initial world from a pattern file and write the final world state back to a file, including required error handling.",{"@graph":14,"@context":72},[15,34,55],{"@type":16,"itemListElement":17},"BreadcrumbList",[18,23,27,31],{"item":19,"name":20,"@type":21,"position":22},"https://docshare.wps.com","Home","ListItem",1,{"item":24,"name":25,"@type":21,"position":26},"https://docshare.wps.com/document/","Document",2,{"item":28,"name":29,"@type":21,"position":30},"https://docshare.wps.com/document/exam/","Exam",3,{"item":32,"name":10,"@type":21,"position":33},"https://docshare.wps.com/document/lab-1-game-of-life-implementing-evolution-and-file-based-world-updates/672514/",4,{"url":32,"name":10,"@type":35,"image":36,"author":41,"headline":10,"publisher":44,"fileFormat":47,"inLanguage":8,"description":12,"dateModified":48,"datePublished":49,"encodingFormat":47,"isAccessibleForFree":50,"interactionStatistic":51},"DigitalDocument",{"url":37,"@type":38,"width":39,"height":40},"https://docshare.wps.com/thumbnails/lab-1-game-of-life-implementing-evolution-and-file-based-world-updates/672514.png","ImageObject",300,407,{"name":42,"@type":43},"hdkawk","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-11-24","2026-11-02",true,{"@type":52,"interactionType":53,"userInteractionCount":33},"InteractionCounter",{"@type":54},"ViewAction",{"@type":56,"mainEntity":57},"FAQPage",[58,64,68],{"name":59,"@type":60,"acceptedAnswer":61},"What rules define Conway’s Game of Life in this lab handout?","Question",{"text":62,"@type":63},"A live cell with fewer than two live neighbors dies, a live cell with more than three live neighbors dies, a live cell with exactly two or three live neighbors lives, and a dead cell with exactly three live neighbors becomes alive.","Answer",{"name":65,"@type":60,"acceptedAnswer":66},"How does the lab handle cells at the edge of the finite world?",{"text":67,"@type":63},"Neighbors that would fall beyond the edge are assumed dead, so edge cells’ evolution only considers valid adjacent positions within the finite grid.",{"name":69,"@type":60,"acceptedAnswer":70},"What additional changes does Part B require compared to Part A?",{"text":71,"@type":63},"Part B modifies the code to initialize the world from a file pattern (using '*' for alive and space for dead) and to save the final world state back to a file in the same format, with appropriate error handling.","https://schema.org",{"og:url":32,"og:type":74,"og:title":10,"og:site_name":45,"og:description":12},"article",{"robots":76,"canonical":32},"index,follow",{"doc_id":78,"site_id":7},672514,1793597982,{"code":4,"msg":81,"data":82},"success",[83,87,91,94,99,104,109,114,119,122,126],{"id":22,"doc_module":4,"doc_module_name":25,"category_name":84,"show_sort_weight":85,"slug":86},"Story & Novel",90,"story-novel",{"id":26,"doc_module":4,"doc_module_name":25,"category_name":88,"show_sort_weight":89,"slug":90},"Literature",80,"literature",{"id":33,"doc_module":4,"doc_module_name":25,"category_name":29,"show_sort_weight":92,"slug":93},70,"exam",{"id":95,"doc_module":4,"doc_module_name":25,"category_name":96,"show_sort_weight":97,"slug":98},5,"Comic",60,"comic",{"id":100,"doc_module":4,"doc_module_name":25,"category_name":101,"show_sort_weight":102,"slug":103},6,"Technology",50,"technology",{"id":105,"doc_module":4,"doc_module_name":25,"category_name":106,"show_sort_weight":107,"slug":108},7,"Healthcare",40,"healthcare",{"id":110,"doc_module":4,"doc_module_name":25,"category_name":111,"show_sort_weight":112,"slug":113},8,"Research & Report",30,"research-report",{"id":115,"doc_module":4,"doc_module_name":25,"category_name":116,"show_sort_weight":117,"slug":118},9,"Religion & Spirituality",20,"religion-spirituality",{"id":117,"doc_module":4,"doc_module_name":25,"category_name":120,"show_sort_weight":117,"slug":121},"World Cup","world-cup",{"id":123,"doc_module":4,"doc_module_name":25,"category_name":124,"show_sort_weight":123,"slug":125},10,"Lifestyle","lifestyle",{"id":127,"doc_module":4,"doc_module_name":25,"category_name":128,"show_sort_weight":95,"slug":129},19,"General","general",{"code":4,"msg":81,"data":131},{"doc_id":78,"user_id":132,"nickname":42,"user_avatar":133,"doc_module":4,"category_id":33,"category_name":29,"doc_title":10,"doc_description":12,"doc_content":134,"file_id":135,"file_url":136,"file_type":137,"file_size":138,"view_count":33,"is_deleted":4,"is_public":22,"is_downloadable":22,"audit_status":22,"page_count":33,"language":139,"language_code":8,"site_id":7,"html_lang":8,"table_of_contents":140,"faqs":141,"seo_title":142,"seo_description":12,"update_tm":79,"read_time":123,"preview_page_count":33,"preview_urls":143},3985747859855,"https://ap-avatar.wpscdn.com/davatar_276721f389ce27ea32af1340a28f341c","Massachusetts Institute of Technology  \nDepartment of Electrical Engineering and Computer Science  \n6.087: Practical Programming in C  \nIAP 2010  \nLab 1: Game of Life  \nIn-Lab: Wednesday, January 13, 2010 Due: Tuesday, January 19, 2010  \nOverview  \nThe Game of Life, invented by John Conway in 1970, is an example of a zero-player “game” known as a cellular automaton. The game consists of a two-dimensional world extending inﬁnitely in all directions, divided into “cells.” Each cell is either “dead” or “alive” at a given “generation.” The game consists of a set of rules that describe how the cells evolve from generation to generation. These rules calculate the state of a cell in the next generation as a function of the states of its neighboring cells in the current generation. In a 2-D world, a cell’s neighbors are those 8 cells vertically, horizontally, or diagonally adjacent to that cell. Conway’s set of rules are summarized as:  \n1. A live cell with fewer than two live neighbors dies.  \n2. A live cell with more than three live neighbors also dies.  \n3. A live cell with exactly two or three live neighbors lives.  \n4. A dead cell with exactly three live neighbors becomes alive.  \nIn this lab, we will be implementing Conway’s Game of Life, with the minor restriction that our 2-D world is ﬁnite. The neighbors of a cell on the edge of the world that would be beyond the edge are assumed dead. You can read more about Conway’s Game of Life on Wikipedia at [http://en.wikipedia.org/wiki/Conway](http://en.wikipedia.org/wiki/Conway)’s_Game_of_Life.  \nExample (the so-called “glider”):  \n||  \n||  \n|  \n||  \n||  \n|  \n*  \n||  \n||  \n|  \n*  \n||  \n||  \n|  \n**  \n*  \n||  \n||  \n|  \n||  \n||  \n|  \n||  \n||  \n|  \n−→  \n\n|  |  | * | * | * |  |\n| --- | --- | --- | --- | --- | --- |\n| * *\u003Cbr>| | | | | |  |  |  |  |  |\n\nLegend: * = alive,   = dead  \nPart A: Implementing Evolution (In-Lab)  \nIn this part, we will focus on implementing the rules needed to evolve the world from one generation to the next. To assist you, we provide several functions you should use to access and modify the current and next state of the world. These functions are described in the header ﬁle lifegame .hand implemented in the ﬁle lifegame .c. Also, we have provided a skeleton describing what you need to do for this part in lab1a .c.  \nBefore getting started, you should copy all these ﬁles from the locker (/mit/6.087/Lab1/) into your working directory. When compiling, you need to compile lab1a .c and lifegame .c together to generate a single executable ﬁle (let’s call it lab1a.o) with all the code in it (otherwise, you’ll get “undeﬁned reference” errors) . Here’s an example command line for compiling this code:  \nathena% 1 gcc-g-O0-Wall lab1a .c lifegame .c-o lab1a .o  \nathena%  \nStart by examining the contents of lifegame .h and lab1a .c. You need to ﬁll in a few lines in main() and complete the functions next generation() , get next   state(x,y) , and num neighbors(x,y) . There is no need to modify the ﬁles lifegame .h or lifegame .c in this part.  \n(a) How will you initialize the world for the Game of Life? Write the appropriate code in the main() function.  \n(b) How will you output the ﬁnal state of the world once all the evolutions are done? Write the appropriate function call in main() .  \n(c) The main() function calls next generation() for each generation to handle the evolution  \nprocess. Your code should set each cell’s state in the next generation according to the rules speciﬁed in the Overview of this handout. Once the states of all the cells have been set for the next generation, calling finalize evolution() will set the current world state to the next generation and reset the next generation state. Your code should make use of the get next   state(x,y) function to compute the next state of each cell.  \n(d) Write the code for get next   state(x,y) , so the function returns the next state (ALIVE or DEAD) of the cell at the speciﬁed coordinates using the number of live neig","cbCainfK0F73UAEp","https://ap.wps.com/l/cbCainfK0F73UAEp","pdf",146521,"English","# Overview\n# Part A: Implementing Evolution (In-Lab)\n## Initialization and output requirements\n## Evolution loop and state transition functions\n## Neighbor counting on a finite world\n# Part B: The World in a File\n## Reading initial state from a file\n## Saving final state to a file","[{\"question\":\"What rules define Conway’s Game of Life in this lab handout?\",\"answer\":\"A live cell with fewer than two live neighbors dies, a live cell with more than three live neighbors dies, a live cell with exactly two or three live neighbors lives, and a dead cell with exactly three live neighbors becomes alive.\"},{\"question\":\"How does the lab handle cells at the edge of the finite world?\",\"answer\":\"Neighbors that would fall beyond the edge are assumed dead, so edge cells’ evolution only considers valid adjacent positions within the finite grid.\"},{\"question\":\"What additional changes does Part B require compared to Part A?\",\"answer\":\"Part B modifies the code to initialize the world from a file pattern (using '*' for alive and space for dead) and to save the final world state back to a file in the same format, with appropriate error handling.\"}]","Lab 1 - Game of Life - Implementing Evolution and File-Based World Updates | PDF",[144,148,152,156],{"page_no":22,"url":145,"width":146,"height":147},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-18/5729d6c895e24d24d024198a3e14cee3.webp",983,1272,{"page_no":26,"url":149,"width":150,"height":151},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-18/aff2c8224317275149a78e8a84c45d70.webp",982,1270,{"page_no":30,"url":153,"width":154,"height":155},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-18/79c8339bc5473deb0c096e81f09a6ba1.webp",981,1269,{"page_no":33,"url":157,"width":158,"height":159},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-18/0ae4035324fd1228248d44e5a13d0eb2.webp",980,1268,{"list":161,"token":11},[162,168,174,181,187,193,199,205,211,216],{"doc_id":163,"doc_title":164,"file_type":137,"home_preview_img_url":165,"slug":166,"view_count":100,"category_name":29,"create_tm":167},475374,"Reflecting a Point Across an Axis - Worksheet","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229926682103/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796178419&Signature=idYwo9vv7F8puYNjaH5e2YSNulY%3D","reflecting-a-point-across-an-axis-worksheet",1790785896,{"doc_id":169,"doc_title":170,"file_type":137,"home_preview_img_url":171,"slug":172,"view_count":100,"category_name":29,"create_tm":173},700092,"Lab - 2 - Finite State Machines","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230012011568/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796178419&Signature=0sOf4t3a%2FUU09NB48DfKuaZfiY4%3D","lab-2-finite-state-machines",1794515678,{"doc_id":175,"doc_title":176,"file_type":137,"home_preview_img_url":177,"slug":178,"view_count":179,"category_name":29,"create_tm":180},481037,"Identifying Constant of Proportionality (Tables) - Answer Key","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229926754137/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796178419&Signature=Ke%2BzTA6jZHcPhOBNMZYGWA21oFM%3D","identifying-constant-of-proportionality-tables-answer-key",13,1790796034,{"doc_id":182,"doc_title":183,"file_type":137,"home_preview_img_url":184,"slug":185,"view_count":30,"category_name":29,"create_tm":186},682428,"Logic Gate Worksheet - Logic Circuits Truth Table Practice","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229999564253/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796178419&Signature=koMq391%2BxT%2FxmVKYp9PsHFr6uDE%3D","logic-gate-worksheet-logic-circuits-truth-table-practice",1793970597,{"doc_id":188,"doc_title":189,"file_type":137,"home_preview_img_url":190,"slug":191,"view_count":105,"category_name":29,"create_tm":192},635102,"INPUT OUTPUT FUNCTION TABLES SHEET 4C - Write formulas and fill missing outputs","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229969663620/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796178419&Signature=RLoxFCNUrcuzKcJUB1a54FhymHw%3D","input-output-function-tables-sheet-4c-write-formulas-and-fill-missing-outputs",1792675303,{"doc_id":194,"doc_title":195,"file_type":137,"home_preview_img_url":196,"slug":197,"view_count":117,"category_name":29,"create_tm":198},358789,"Constant of Proportionality—From Graphs (A) - Practice Worksheet","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229912738109/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796178419&Signature=pFSXs%2By8M%2BROXOMccLMmvGE%2BNoY%3D","constant-of-proportionalityfrom-graphs-a-practice-worksheet",1790135308,{"doc_id":200,"doc_title":201,"file_type":137,"home_preview_img_url":202,"slug":203,"view_count":105,"category_name":29,"create_tm":204},477101,"Identifying Rate of Change (Equations) - Answer Key","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229926713435/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796178419&Signature=HJgRW3d7Xp5Osg%2BfljTgg%2BDm1vs%3D","identifying-rate-of-change-equations-answer-key",1790789110,{"doc_id":206,"doc_title":207,"file_type":137,"home_preview_img_url":208,"slug":209,"view_count":115,"category_name":29,"create_tm":210},467418,"Identify Linear Functions - Table - Answer Key","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229925882229/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796178419&Signature=WkF36B0GSgLzS2pt6ycKmDmmfCM%3D","identify-linear-functions-table-answer-key",1790772843,{"doc_id":212,"doc_title":213,"file_type":137,"home_preview_img_url":214,"slug":209,"view_count":110,"category_name":29,"create_tm":215},467405,"Identify Linear Functions (Table) - Answer Key","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229925881857/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796178419&Signature=Ecl3toak%2FtcYORn7gdvVX2ZNXI4%3D",1790772825,{"doc_id":217,"doc_title":218,"file_type":137,"home_preview_img_url":219,"slug":220,"view_count":100,"category_name":29,"create_tm":221},467406,"Identify Linear Functions - Graphs","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229926492719/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796178419&Signature=583R2vUqI8SeqX9%2F82vv1ZspiAw%3D","identify-linear-functions-graphs",1790772826]