From 5dfdec2cf17b1bcfee7e2946f9766b38916702eb Mon Sep 17 00:00:00 2001 From: Nitsan Avni Date: Sat, 11 Nov 2023 09:22:54 +0100 Subject: [PATCH] README.md --- README.md | 65 ++++++++++-------------------------------- with-grimoire.py | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 50 deletions(-) create mode 100644 with-grimoire.py diff --git a/README.md b/README.md index 326f41e..a6a71ef 100644 --- a/README.md +++ b/README.md @@ -1,60 +1,25 @@ +CodeRetreat 2023, Follow-up Week, Session 5 -[![Test](../../actions/workflows/test.yml/badge.svg)](../../actions/workflows/test.yml) +**Pair:** @isidore, @nitsanani -# ApprovalTests.Python.StarterProject -Starter project for getting approvaltests up and running +## Constraint: Feature Factory - -## Contents +Use all available AI tooling to get as many features done. - * [Who is this project for?](#who-is-this-project-for) - * [Getting Started](#getting-started) - * [Watch the video](#watch-the-video) - * [What is included?](#what-is-included) - * [Recommended Tooling?](#recommended-tooling) - * [ApprovalTests Basics](#approvaltests-basics) - * [Next steps](#next-steps) +## Results / Retro -## Who is this project for? -Anyone that wants to do some new code in Python with Approvaltests. -It works great for experimentation, katas or starting a green field project. +Retro link here -## Getting Started +## After-Session Work -If you are familar with python, you can either: -* download the zip (under the `code` button - -or -* Fork the code by pressing `use this template` - -### Watch the video -If you are having any difficulties, We suggest you watch the [getting started video](https://www.youtube.com/watch?v=2PbA273JHYE) -**tip:** pause the video after each step and do it so you are in sync - - -## What is included? -* [Github actions](https://github.com/approvals/ApprovalTests.Python.StarterProject/actions/workflows/test.yml) - CI that runs your tests on Mac, Windows & Linux - This is also what powers the green 'passing' badge at the top of this document -* `requirements.txt` - standard place to include all your [pip dependiences from pypi](https://pypi.org/) -* `tox.ini' - A working [tox file](https://tox.wiki/en/latest/) -* `tests` & `project` folders - to keep your production code and tests seperate -* Sample tests that pass - to get you off to a great start -* [MDSnippets intergration](https://github.com/simonCropp/MarkdownSnippets) to easily add code snippets to your markdown documentation - -## Recommended Tooling? - -* [Pycharm](https://www.jetbrains.com/pycharm/download/#section=mac) (both community and professional will work) -* [Python 3](https://www.python.org/downloads/) -* Diff Tools - * Windows - [WinMerge](https://winmerge.org/?lang=en) - * Mac - [DiffMerge](https://sourcegear.com/diffmerge/) - -## ApprovalTests Basics - - -## Next steps - -If you are just exploring you might want to try a sample exercise(kata). I would suggest you start with [LCD digits kata](https://codingdojo.org/kata/NumberToLCD/) +Used [a GPT](https://chat.openai.com/g/g-n7Rs0IK86-grimoire) to generate the whole thing from a single prompt. +The prompt: +> game of life +> 10x10 +> a glider collides with a square +> python, tkinter +[See chat here](https://chat.openai.com/share/4ceab0af-225f-4bd8-8415-7b3f31172515) +[See code here](./with-grimoire.py) diff --git a/with-grimoire.py b/with-grimoire.py new file mode 100644 index 0000000..85a3216 --- /dev/null +++ b/with-grimoire.py @@ -0,0 +1,73 @@ +# this code was generated from the grimoire +# link to chat: https://chat.openai.com/share/4ceab0af-225f-4bd8-8415-7b3f31172515 + +import tkinter as tk +import copy +import time + +# Constants for the grid size and cell size +GRID_SIZE = 10 +CELL_SIZE = 20 + +# Initialize the grid +def init_grid(): + return [[0 for _ in range(GRID_SIZE)] for _ in range(GRID_SIZE)] + +# Place the glider and square on the grid +def setup_initial_state(grid): + # Glider pattern + grid[1][2] = grid[2][3] = grid[3][1] = grid[3][2] = grid[3][3] = 1 + # Square pattern + grid[8][8] = grid[8][9] = grid[9][8] = grid[9][9] = 1 + +# Count the alive neighbors of a cell +def count_neighbors(grid, x, y): + neighbors = 0 + for i in range(-1, 2): + for j in range(-1, 2): + if i == 0 and j == 0: + continue + if 0 <= x+i < GRID_SIZE and 0 <= y+j < GRID_SIZE: + neighbors += grid[x+i][y+j] + return neighbors + +# Update the grid based on the Game of Life rules +def update_grid(grid): + new_grid = copy.deepcopy(grid) + for i in range(GRID_SIZE): + for j in range(GRID_SIZE): + neighbors = count_neighbors(grid, i, j) + if grid[i][j] == 1 and (neighbors < 2 or neighbors > 3): + new_grid[i][j] = 0 + elif grid[i][j] == 0 and neighbors == 3: + new_grid[i][j] = 1 + return new_grid + +# Draw the grid using Tkinter +def draw_grid(canvas, grid): + canvas.delete("all") + for i in range(GRID_SIZE): + for j in range(GRID_SIZE): + color = "black" if grid[i][j] == 1 else "white" + canvas.create_rectangle(j*CELL_SIZE, i*CELL_SIZE, (j+1)*CELL_SIZE, (i+1)*CELL_SIZE, fill=color, outline="gray") + +def main(): + root = tk.Tk() + root.title("Game of Life") + canvas = tk.Canvas(root, width=GRID_SIZE*CELL_SIZE, height=GRID_SIZE*CELL_SIZE) + canvas.pack() + + grid = init_grid() + setup_initial_state(grid) + + def update(): + nonlocal grid + grid = update_grid(grid) + draw_grid(canvas, grid) + root.after(500, update) + + update() + root.mainloop() + +if __name__ == "__main__": + main()