Skip to content

Commit

Permalink
README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
nitsanavni committed Nov 11, 2023
1 parent 3e7c3bb commit 5dfdec2
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 50 deletions.
65 changes: 15 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

<!-- toc -->
## 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)<!-- endToc -->
## 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)
73 changes: 73 additions & 0 deletions with-grimoire.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 5dfdec2

Please sign in to comment.