Skip to content

Commit

Permalink
.gitignore + file management.
Browse files Browse the repository at this point in the history
  • Loading branch information
amtoine committed Jul 3, 2021
1 parent 1e8e705 commit 3b0513f
Show file tree
Hide file tree
Showing 4 changed files with 301 additions and 51 deletions.
249 changes: 249 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
# pycharm directory ?
.idea/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

## Temp files
*~

## Jupyter notebooks
.ipynb_checkpoints

## Core latex/pdflatex auxiliary files:
*.aux
*.lof
*.log
*.lot
*.fls
*.out
*.toc
*.fmt
*.fot
*.cb
*.cb2
.*.lb

## Intermediate documents:
*.dvi
*.xdv
*-converted-to.*

## Bibliography auxiliary files (bibtex/biblatex/biber):
*.bbl
*.bcf
*.blg
*-blx.aux
*-blx.bib
*.run.xml

## Build tool auxiliary files:
*.fdb_latexmk
*.synctex
*.synctex(busy)
*.synctex.gz
*.synctex.gz(busy)
*.pdfsync

## Auxiliary and intermediate files from other packages:
# algorithms
*.alg
*.loa

# achemso
acs-*.bib

# amsthm
*.thm

# beamer
*.nav
*.pre
*.snm
*.vrb

# changes
*.soc

# cprotect
*.cpt

# elsarticle (documentclass of Elsevier journals)
*.spl

# endnotes
*.ent

# fixme
*.lox

# feynmf/feynmp
*.mf
*.mp
*.t[1-9]
*.t[1-9][0-9]
*.tfm

#(r)(e)ledmac/(r)(e)ledpar
*.end
*.?end
*.[1-9]
*.[1-9][0-9]
*.[1-9][0-9][0-9]
*.[1-9]R
*.[1-9][0-9]R
*.[1-9][0-9][0-9]R
*.eledsec[1-9]
*.eledsec[1-9]R
*.eledsec[1-9][0-9]
*.eledsec[1-9][0-9]R
*.eledsec[1-9][0-9][0-9]
*.eledsec[1-9][0-9][0-9]R

# glossaries
*.acn
*.acr
*.glg
*.glo
*.gls
*.glsdefs

# gnuplottex
*-gnuplottex-*

# gregoriotex
*.gaux
*.gtex

# hyperref
*.brf

# knitr
*-concordance.tex
# TODO Comment the next line if you want to keep your tikz graphics files
*.tikz
*-tikzDictionary

# listings
*.lol

# makeidx
*.idx
*.ilg
*.ind
*.ist

# minitoc
*.maf
*.mlf
*.mlt
*.mtc[0-9]*
*.slf[0-9]*
*.slt[0-9]*
*.stc[0-9]*

# minted
_minted*
*.pyg

# morewrites
*.mw

# nomencl
*.nlo

# pax
*.pax

# pdfpcnotes
*.pdfpc

# sagetex
*.sagetex.sage
*.sagetex.py
*.sagetex.scmd

# scrwfile
*.wrt

# sympy
*.sout
*.sympy
sympy-plots-for-*.tex/

# pdfcomment
*.upa
*.upb

# pythontex
*.pytxcode
pythontex-files-*/

# thmtools
*.loe

# TikZ & PGF
*.dpth
*.md5
*.auxlock

# todonotes
*.tdo

# easy-todo
*.lod

# xindy
*.xdy

# xypic precompiled matrices
*.xyc

# endfloat
*.ttt
*.fff

# Latexian
TSWLatexianTemp*

## Editors:
# WinEdt
*.bak
*.sav

# Texpad
.texpadtmp

# Kile
*.backup

# KBibTeX
*~[0-9]*

# auto folder when using emacs and auctex
./auto/*
*.el

# expex forward references with \gathertags
*-tags.tex

# standalone packages
*.sta

# saved numpy arrays.
*.npy

# some temporary miscelaenous files.
.misc

# do not include torch saves.
*.pth

# do not include data and out directories to save space in the remote.
*data/
*out/

# weights and biases directory.
wandb/
14 changes: 14 additions & 0 deletions src/Apple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import curses

import numpy as np


class Apple:
def __init__(self):
self.pos = (np.random.randint(curses.LINES), np.random.randint(curses.COLS))

def spawn(self):
self.pos = (np.random.randint(curses.LINES), np.random.randint(curses.COLS))

def show(self, stdscr):
stdscr.addstr(*self.pos, 'O')
52 changes: 1 addition & 51 deletions main.py → src/Snake.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import curses
import time

import numpy as np

_directions = {
curses.KEY_UP: (-1, 0),
Expand All @@ -12,13 +9,9 @@

_corners = {
"dr": 4194410,
(0, 1): 4194410,
"ur": 4194411,
(0, -1): 4194411,
"ul": 4194412,
(1, 0): 4194412,
"dl": 4194413,
(-1, 0): 4194413,
}


Expand Down Expand Up @@ -114,7 +107,7 @@ def update(self, eating_apple):

def show(self, stdscr):
for i, part in enumerate(self.body[1:]):
stdscr.addch(*part, self.tokens[i+1])
stdscr.addch(*part, self.tokens[i + 1])

if self.inside():
stdscr.addstr(*self.body[0], '@')
Expand All @@ -125,46 +118,3 @@ def show(self, stdscr):
h = 0 if self.head()[0] > curses.LINES // 2 else curses.LINES - 1 - len(msgs)
for row, msg in zip(range(len(msgs)), list(map(str, msgs))):
stdscr.addstr(h + row, 0, msg)


class Apple:
def __init__(self):
self.pos = (np.random.randint(curses.LINES), np.random.randint(curses.COLS))

def spawn(self):
self.pos = (np.random.randint(curses.LINES), np.random.randint(curses.COLS))

def show(self, stdscr):
stdscr.addstr(*self.pos, 'O')


def main(stdscr):
if not curses.can_change_color():
raise Warning("Cannot change terminal colors...")
curses.curs_set(0)
stdscr.nodelay(1)

snake = Snake()
apple = Apple()

fps = 15

play = True
while True:
stdscr.erase()

snake.change_direction(stdscr.getch())
if play:
snake.move()
if snake.update(snake.is_eating(apple)):
play = False

snake.show(stdscr)
apple.show(stdscr)

stdscr.refresh()
time.sleep(1 / fps)


if __name__ == "__main__":
curses.wrapper(main)
37 changes: 37 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import curses
import time

from Apple import Apple
from Snake import Snake


def main(stdscr):
if not curses.can_change_color():
raise Warning("Cannot change terminal colors...")
curses.curs_set(0)
stdscr.nodelay(1)

snake = Snake()
apple = Apple()

fps = 15

play = True
while True:
stdscr.erase()

snake.change_direction(stdscr.getch())
if play:
snake.move()
if snake.update(snake.is_eating(apple)):
play = False

snake.show(stdscr)
apple.show(stdscr)

stdscr.refresh()
time.sleep(1 / fps)


if __name__ == "__main__":
curses.wrapper(main)

0 comments on commit 3b0513f

Please sign in to comment.