![]() The center cell will stay dead, because it is surrounded by exactly five live cells.Īfter each row is completed, the numbers in the array are updated by dividing the existing numbers by 7, discarding the decimal part, and adding 49 times the values of the cells in the new column. ![]() Example diagram (let's say there is a glider centered at a certain column at Y=45: Row # | Cell State | Stored number | Mod 6 = cell count Saves about 10 bytes by itself and gives the opportunity to use the next two optimizations. Then I take the remainder mod 6 of the sum of the three numbers around the cell being modified to find the total number of live neighbor cells (it's just like the divisibility by 9 trick-in base 7, the remainder mod 6 equals the sum of the digits). The 49's place holds the column to the right, the 7's place holds the middle column, and the units place holds the left column-1 for a live cell and 0 for a dead cell. I store the states of the three columns next to the one being updated in a 63-element array of base-7 numbers. Saves one byte over the shortest other method and about four over the obvious method. After the first frame is drawn, I turn the clock off. At the start of the program, the date/time clock is enabled, and I use the value of the global isClockOn flag to determine whether it is the first iteration. This version is probably the most golfed code I have ever written, and contains some truly nasty obfuscatory optimizations: If 2rand>isClockOn=pxl-Test(Y,X)+int(3fPart(3cosh(fPart(6ֿ¹iPart(sum(Ans,Y,Y+2 However, it is not a competing entry because it does not wrap the screen the cells on the outer border will always be considered dead if the graph screen is cleared beforehand. In subsequent runs it automatically continues the simulation if stopped after a frame is finished. This code has an additional feature: it detects if it is being run for the first time, and if randomizes the screen state. User input is easy: before running the program, use the Pen tool to draw your shape on the graph screen.Īdapted from my entry to a code golf contest at the calculator forum Omnimaga. Because the calculators have only a 15MHz z80 processor and BASIC is a slow interpreted language, the code only gets one frame about every five minutes. Each cell is one pixel, and the program updates line by line horizontally to the right across the screen. Uses every accessible pixel on the screen, and wraps correctly. This was quite a challenge, because there is no easy way to write a buffered graphics routine (definitely nothing built in), and the graph screen has only four relevant graphics commands: Pxl-On(), Pxl-Off(), Pxl-Change(), and pxl-Test(). TI-BASIC, 96 bytes (87 for non-competing entry)įor your TI-84 series graphing calculator (!). The online version is 11 characters longer because jsFiddle puts a text node just before the canvas (why?) and thus the canvas is no longer the first child.Įdit 1: Lots of optimisations and restructurings.Įdit 3: Inlined the complete script block plus minor changes. Unfortunately there is an issue I couldn't work around yet. You can now also try the new version here. You can toggle cells by clicking (also possible in running mode). I always wanted to do something with canvas, so here is my attempt (original version online). Again, I really appreciate any help.HTML5 Canvas with JavaScript, 940 639 586 519 characters Run ![]() This was my question and I hope you can help. My question here is that when I try to run this, I get this error: I am having difficulty in function 4, advancing the whole grid by one generation, by using function 5 and iterating through the whole grid. If grid = dead_cell and num_living_neighbors(row, col, grid) = 3: If grid = living_cell and num_living_neighbors(row, col, grid) 4: I removed it for the sake of brevityĭef num_living_neighbors(row, col, grid): This is my code so far: living_cell = "O" Return: the number of living neighbors of the cell Return: whether the cell is alive or not (True or False)įunction 6: determine the number of living neighbors of a cell Return: a new grid advanced by one generationįunction 5: advance a cell one generation These are the functions I am using to create Conway's Game of Life:įunction 4: advance a grid one generation From when I sent my last question, I have progressed a bit and I have coded 5/6 functions so far (1, 2, 3, 5, and 6), and function 4 is really just putting together functions 5 and 6, which is what I need help with. I have just one (most likely) last question.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |