Blog Post

Excel Blog
2 MIN READ

Ready Player Zero

Yutao_Huang's avatar
Yutao_Huang
Icon for Microsoft rankMicrosoft
Apr 28, 2021

Repeated tasks can slow down your efficiency but with Office Scripts in Excel for the web, you can automate your day-today tasks. In just a few simple steps, you can easily create a script and then share with your coworkers to automate your organization’s workflow.  While you can use Office Scripts to be more productive at work, we’d like to show how you can use Office Scripts for fun! 

 

To demonstrate the breadth and depth Office Scripts offers (and just for fun)we built Game of Life simulator. The Game of Life, also known simply as Life,” is a cellular automaton devised by 1970’s British mathematician, John Horton Conway. It is a zero player game, meaning that its evolution is determined by its initial state, requiring no further input. You simply create, sit back, and watch the evolution unfold.  

 

17c/45_Reaction, 16x5 (17c45reaction.rle)

 

Here are the steps to create your own zero-player game:

  • Create a new workbook in Excel on the Web. 

  • Open the “Automate” tab. 

  • Press the "New script" button. 

  • Copy the code from game-of-life.ts and paste into the Code Editor (optionally, rename the script as "Conway's Game of Life”).

  • Hit the “Run” button above the code editor. 

  • After a few seconds of churning (downloading the pattern rule and setting up the game board), a small "glider" will come to life and start to travel across the worksheet.  

 

Below are some examples of different Game of Life patterns - note the frame rates have been adjusted for demonstration purposes.


Maze wickstretcher, 6x8 (mazewickstretcher.rle)

 

2x2 Block Oscillators, 26x2 (2x2blockoscillators.rle)

 

Baker, 16x14 (baker.rle)

 

B3578/S238 Replicator, 7x7 (b3578s238replicator.rle)

 

To learn more about Office Scripts and Game of Life:  

 

We’d love to hear from you and look forward to seeing how you use Office Scripts in your workflows.  Happy scripting!

 

Updated Apr 23, 2021
Version 1.0
  • lori_m's avatar
    lori_m
    Steel Contributor

    Nice. I remembered seeing another implementation without macros using iteration only in a blog article a long time ago (though not all content still survives intact):

    https://www.microsoft.com/en-us/microsoft-365/blog/2007/11/02/iteration-conways-game-of-life/

    The late great mathematician John H Conway had a long career and actually wasn't too enamoured by his game of life invention feeling the attention it received detracted from many of his other ground-breaking discoveries some inspired by other games like Go.

  • robshrk's avatar
    robshrk
    Copper Contributor

    A single generation of Conway's Game of Life can be computed with this LAMBDA function:

    =LAMBDA(rng,
    	LET(r,ROWS(rng),c,COLUMNS(rng),
    	expand,OFFSET(rng,-1,-1,r+2,c+2),
    	MAP(expand,
    		LAMBDA(cl,LET(
    			x,SUM(OFFSET(cl,-1,-1,3,3)),
    			1*OR(x=3,AND(cl=1,x=4)))))))

     This may make it easier to run through a simulation in VBA or Office Scripts.

  • Hey lori_m! Thanks for sharing the 2007 blog article! Using iteration is truly a creative way to render Conway's Game of Life in Excel without writing any code. It's also amazing to see the breadth and depth Excel offers. The only limit is our imagination.