Skip to content

Conversation

@recule556688
Copy link
Contributor

Conway’s Game of Life – Gno Smart Contract Package

This pull request adds a full implementation of Conway's Game of Life as a Gno smart contract package.
It includes game logic, pattern management, rendering, an API for interaction, and documentation.

The package supports both numeric and letter-based coordinates, several well-known patterns, and a simple web interface.


Core Game Logic

  • grid.gno: defines the Grid type, with grid initialization, cell manipulation, generation tracking, and clearing. Grid size is fixed at 20x20.
  • game.gno: defines the GameEngine type, with Conway’s rules for survival, reproduction, and death, plus advancing the grid by one generation.

Pattern Support

  • patterns.gno: provides the PatternManager type.
  • Supports predefined patterns: block, blinker, toad, beacon, glider, pulsar.
  • Functions to load patterns into the grid and list them.

API and Coordinates

  • conway.gno: main API entry point, with functions for:

    • game management (NewGame, Step, Clear)
    • cell manipulation (numeric or letter-based coordinates)
    • loading patterns
    • rendering
  • Includes helper functions for coordinate conversion and parsing.

Rendering and Docs

Module Metadata

  • gnomod.toml: declares the Gno module and version.

Features

  • Complete Game of Life implementation in Gno
  • Numeric and letter-based coordinates
  • Classic patterns included (blinker, block, glider, etc.)
  • Web interface with rendering
  • Gas-efficient design for blockchain use
  • API and full documentation

Next Steps

  • Add unit tests (planned during the week)
  • Replace text renderer with SVG output

- Complete Conway's Game of Life implementation for Gno
- Dual coordinate systems (numeric and letter-based)
- Pre-defined patterns: blinker, block, glider
- Web interface with grid rendering
- Gas-optimized for blockchain deployment
- Comprehensive API and documentation
Copy link
Contributor

@leohhhn leohhhn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leaving some preliminary comments. can you write some tests?

@recule556688
Copy link
Contributor Author

leaving some preliminary comments. can you write some tests?

Hi i wrote i would add some test i will add some today then, and try to fix everything for today thank you for the review

@recule556688
Copy link
Contributor Author

Hey @leohhhn, thanks for the review! I've gone through and fixed everything you mentioned:

What I changed:

  • Moved helper functions to the bottom of files
  • Got rid of the init() function and just initialize variables directly in the var block
  • Removed NewGame() since you're right, anyone could reset the game and there is already a function for that I'm thinking maybe later add a whitelist for people to newgame() if needed
  • Added proper godoc comments everywhere
  • Wrote tests for all the functionality
  • Tests are all passing now. Let me know if you see anything else that needs fixing!

@leohhhn
Copy link
Contributor

leohhhn commented Sep 24, 2025

Cool, will take a look soon. Can you remove the CI addition here? We've a CI coming soon in #7 that will test all packages.

@leohhhn
Copy link
Contributor

leohhhn commented Sep 24, 2025

Also, generally speaking, when you have comments on a PR, leave it up to the person who wrote them to resolve the comments, and ideally reply with the commit that fixes the matching comment. This makes it a lot easier for reviewers

@recule556688
Copy link
Contributor Author

Hi @leohhhn ,

Thanks for the feedback! I've addressed the performance issues that were causing the high gas consumption with the Step function. The game is now working properly.

Changes made to fix the performance issue:

7047593 - Added optimized grid handling with temporary grid reuse to eliminate memory allocation on each step
5aa4a77 - Implemented optimized neighbor counting method with direct array access and inline bounds checking
3c22c82 - Made grid cells field public (Cells) for direct access, avoiding function call overhead
e7b1fa5 - Updated help text to reflect the optimized gas usage
The Step function now executes successfully with much lower gas consumption. The optimizations reduced function call overhead from ~3,200+ calls per step to direct array operations, and eliminated unnecessary memory allocations by reusing pre-allocated grids.

Verification: The game is now fully functional - users can load patterns, step through generations, and interact with the game without gas issues.

@leohhhn
Copy link
Contributor

leohhhn commented Oct 2, 2025

Check the CI 🙏

Copy link

@Davphla Davphla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks clean to me.
I think as we discussed you can extend it to have a more "gamified" game of life, but it is good like it is.
Think of adding visual of your Render through the main post in the PR!

@Davphla
Copy link

Davphla commented Oct 3, 2025

Also CI is not passing.

@leohhhn leohhhn merged commit a319712 into gnoverse:main Oct 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants