Spaces:
Sleeping
Sleeping
df
Browse files- gpt-engineer/projects copy/example-improve/README.md +0 -17
- gpt-engineer/projects copy/example-improve/controller.py +0 -21
- gpt-engineer/projects copy/example-improve/main.py +0 -18
- gpt-engineer/projects copy/example-improve/model.py +0 -32
- gpt-engineer/projects copy/example-improve/prompt +0 -1
- gpt-engineer/projects copy/example-improve/requirements.txt +0 -1
- gpt-engineer/projects copy/example-improve/run.sh +0 -7
- gpt-engineer/projects copy/example-improve/view.py +0 -19
- gpt-engineer/projects copy/example-vision/images/ux_diagram.png +0 -0
- gpt-engineer/projects copy/example-vision/navigation.html +0 -13
- gpt-engineer/projects copy/example-vision/prompt +0 -1
- gpt-engineer/projects copy/example/Structure +0 -10
- gpt-engineer/projects copy/example/crud/crud.py +0 -19
- gpt-engineer/projects copy/example/duckdb_sample.py +0 -50
- gpt-engineer/projects copy/example/main.py +0 -19
- gpt-engineer/projects copy/example/models/duckdb_model.py +0 -44
- gpt-engineer/projects copy/example/prompt +0 -2
- gpt-engineer/projects copy/example/requirements.txt +0 -1
- gpt-engineer/projects copy/example/run.sh +0 -2
- gpt-engineer/projects copy/example/sample.csv +0 -3
- gpt-engineer/projects copy/example/sample.db +0 -0
gpt-engineer/projects copy/example-improve/README.md
DELETED
@@ -1,17 +0,0 @@
|
|
1 |
-
To implement the game Snake in Python using the Model-View-Controller (MVC) design pattern, we will need several classes and files. The game will be controlled using the keyboard.
|
2 |
-
|
3 |
-
Here are the core classes and their purposes:
|
4 |
-
|
5 |
-
1. `Game`: This is the main class that will control the game flow. It will be responsible for starting the game, handling user input, and updating the game state.
|
6 |
-
|
7 |
-
2. `Snake`: This class will represent the snake in the game. It will have methods to move the snake, grow the snake, and check if the snake has collided with itself.
|
8 |
-
|
9 |
-
3. `Food`: This class will represent the food in the game. It will have methods to place the food at a random location on the game board.
|
10 |
-
|
11 |
-
4. `Board`: This class will represent the game board. It will have methods to draw the board, the snake, and the food.
|
12 |
-
|
13 |
-
5. `Controller`: This class will handle user input. It will have methods to listen for keyboard events and update the direction of the snake accordingly.
|
14 |
-
|
15 |
-
Now, let's start with the entry point file, `main.py`, and then go to the ones that are imported by that file.
|
16 |
-
|
17 |
-
src/main.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gpt-engineer/projects copy/example-improve/controller.py
DELETED
@@ -1,21 +0,0 @@
|
|
1 |
-
import keyboard
|
2 |
-
|
3 |
-
|
4 |
-
class Controller:
|
5 |
-
def __init__(self, game, view):
|
6 |
-
self.game = game
|
7 |
-
self.view = view
|
8 |
-
|
9 |
-
def handle_input(self):
|
10 |
-
if keyboard.is_pressed("up") and not hasattr(self, "last_key_pressed"):
|
11 |
-
self.game.move("down")
|
12 |
-
self.last_key_pressed = "up"
|
13 |
-
elif hasattr(self, "last_key_pressed") and self.last_key_pressed == "up":
|
14 |
-
self.game.move("right")
|
15 |
-
del self.last_key_pressed
|
16 |
-
elif keyboard.is_pressed("down"):
|
17 |
-
self.game.move("up")
|
18 |
-
elif keyboard.is_pressed("left"):
|
19 |
-
self.game.move("right")
|
20 |
-
elif keyboard.is_pressed("right"):
|
21 |
-
self.game.move("left")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gpt-engineer/projects copy/example-improve/main.py
DELETED
@@ -1,18 +0,0 @@
|
|
1 |
-
from controller import Controller
|
2 |
-
from model import Game
|
3 |
-
from view import View
|
4 |
-
|
5 |
-
|
6 |
-
def main():
|
7 |
-
game = Game()
|
8 |
-
view = View(game)
|
9 |
-
controller = Controller(game, view)
|
10 |
-
|
11 |
-
while game.is_running:
|
12 |
-
controller.handle_input()
|
13 |
-
game.update()
|
14 |
-
view.render()
|
15 |
-
|
16 |
-
|
17 |
-
if __name__ == "__main__":
|
18 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gpt-engineer/projects copy/example-improve/model.py
DELETED
@@ -1,32 +0,0 @@
|
|
1 |
-
import random
|
2 |
-
|
3 |
-
from dataclasses import dataclass
|
4 |
-
|
5 |
-
|
6 |
-
@dataclass
|
7 |
-
class Point:
|
8 |
-
x: int
|
9 |
-
y: int
|
10 |
-
|
11 |
-
|
12 |
-
class Game:
|
13 |
-
def __init__(self):
|
14 |
-
self.snake = [Point(5, 5)]
|
15 |
-
self.food = self.generate_food()
|
16 |
-
self.is_running = True
|
17 |
-
|
18 |
-
def generate_food(self):
|
19 |
-
return Point(random.randint(0, 10), random.randint(0, 10))
|
20 |
-
|
21 |
-
def update(self):
|
22 |
-
# Move the snake
|
23 |
-
self.snake.move()
|
24 |
-
|
25 |
-
# Check for collision with food
|
26 |
-
if self.snake.head == self.food:
|
27 |
-
self.snake.grow()
|
28 |
-
self.food = self.generate_food()
|
29 |
-
|
30 |
-
# Check for collision with boundaries
|
31 |
-
if not (0 <= self.snake.head.x < 10 and 0 <= self.snake.head.y < 10):
|
32 |
-
self.is_running = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gpt-engineer/projects copy/example-improve/prompt
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
If up is pressed, the snake should turn down and after one step to the right. If down is pressed it should go up. Also, make the snake go left when right is pressed and right when left is pressed.
|
|
|
|
gpt-engineer/projects copy/example-improve/requirements.txt
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
keyboard==0.13.5
|
|
|
|
gpt-engineer/projects copy/example-improve/run.sh
DELETED
@@ -1,7 +0,0 @@
|
|
1 |
-
# a) Install dependencies
|
2 |
-
python3 -m venv venv
|
3 |
-
source venv/bin/activate
|
4 |
-
pip install -r requirements.txt
|
5 |
-
|
6 |
-
# b) Run all necessary parts of the codebase
|
7 |
-
python main.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gpt-engineer/projects copy/example-improve/view.py
DELETED
@@ -1,19 +0,0 @@
|
|
1 |
-
from model import Point
|
2 |
-
|
3 |
-
|
4 |
-
class View:
|
5 |
-
def __init__(self, game):
|
6 |
-
self.game = game
|
7 |
-
|
8 |
-
def render(self):
|
9 |
-
# Print the game state
|
10 |
-
for y in range(10):
|
11 |
-
for x in range(10):
|
12 |
-
if Point(x, y) in self.game.snake:
|
13 |
-
print("S", end="")
|
14 |
-
elif Point(x, y) == self.game.food:
|
15 |
-
print("F", end="")
|
16 |
-
else:
|
17 |
-
print(".", end="")
|
18 |
-
print()
|
19 |
-
print()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gpt-engineer/projects copy/example-vision/images/ux_diagram.png
DELETED
Binary file (19.2 kB)
|
|
gpt-engineer/projects copy/example-vision/navigation.html
DELETED
@@ -1,13 +0,0 @@
|
|
1 |
-
<html>
|
2 |
-
<head></head>
|
3 |
-
<body style="margin: 0; padding: 0;">
|
4 |
-
<div id="navigation" style="width: 100%;border-bottom: 1px solid #ccc;padding: 0;margin: 0;background-color: #008000;">
|
5 |
-
<ul style="list-style: none; padding: 5px; margin: 0; display: flex; justify-content: start;">
|
6 |
-
<li style="margin-right: 20px;"><a href="#home" style="text-decoration: none; color: black; display: block; padding: 10px 0;">Home</a></li>
|
7 |
-
<li style="margin-right: 20px;"><a href="#about" style="text-decoration: none; color: black; display: block; padding: 10px 0;">About Us</a></li>
|
8 |
-
<li style="margin-right: 20px;"><a href="#services" style="text-decoration: none; color: black; display: block; padding: 10px 0;">Services</a></li>
|
9 |
-
<li><a href="#contact" style="text-decoration: none; color: black; display: block; padding: 10px 0;">Contact</a></li>
|
10 |
-
</ul>
|
11 |
-
</div>
|
12 |
-
</body>
|
13 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gpt-engineer/projects copy/example-vision/prompt
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
Alter the nav so it looks like the ux diagram provided
|
|
|
|
gpt-engineer/projects copy/example/Structure
DELETED
@@ -1,10 +0,0 @@
|
|
1 |
-
duckdb_crud/
|
2 |
-
requirements.txt
|
3 |
-
models/
|
4 |
-
__init__.py
|
5 |
-
duckdb_model.py
|
6 |
-
crud/
|
7 |
-
__init__.py
|
8 |
-
crud.py
|
9 |
-
main.py
|
10 |
-
sample.csv
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gpt-engineer/projects copy/example/crud/crud.py
DELETED
@@ -1,19 +0,0 @@
|
|
1 |
-
from models.duckdb_model import DuckDBModel
|
2 |
-
|
3 |
-
|
4 |
-
class CRUD:
|
5 |
-
def __init__(self, db_file):
|
6 |
-
self.db = DuckDBModel(db_file)
|
7 |
-
|
8 |
-
def create(self, table_name, columns, values):
|
9 |
-
self.db.create_table(table_name, columns)
|
10 |
-
self.db.insert(table_name, values)
|
11 |
-
|
12 |
-
def read(self, table_name, columns, conditions=None):
|
13 |
-
return self.db.select(table_name, columns, conditions)
|
14 |
-
|
15 |
-
def update(self, table_name, columns, values, conditions):
|
16 |
-
self.db.update(table_name, columns, values, conditions)
|
17 |
-
|
18 |
-
def delete(self, table_name, conditions):
|
19 |
-
self.db.delete(table_name, conditions)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gpt-engineer/projects copy/example/duckdb_sample.py
DELETED
@@ -1,50 +0,0 @@
|
|
1 |
-
import duckdb
|
2 |
-
from dataclasses import dataclass
|
3 |
-
|
4 |
-
|
5 |
-
@dataclass
|
6 |
-
class User:
|
7 |
-
id: int
|
8 |
-
name: str
|
9 |
-
email: str
|
10 |
-
|
11 |
-
|
12 |
-
def create_database():
|
13 |
-
conn = duckdb.connect(database=":memory:")
|
14 |
-
return conn
|
15 |
-
|
16 |
-
|
17 |
-
def create_table(conn):
|
18 |
-
conn.execute("CREATE TABLE users (id INTEGER, name VARCHAR, email VARCHAR)")
|
19 |
-
|
20 |
-
|
21 |
-
def insert_data(conn, users):
|
22 |
-
conn.execute("INSERT INTO users (id, name, email) VALUES (?, ?, ?)", users)
|
23 |
-
|
24 |
-
|
25 |
-
def query_data(conn):
|
26 |
-
cursor = conn.cursor()
|
27 |
-
cursor.execute("SELECT * FROM users")
|
28 |
-
return cursor.fetchall()
|
29 |
-
|
30 |
-
|
31 |
-
def main():
|
32 |
-
conn = create_database()
|
33 |
-
create_table(conn)
|
34 |
-
|
35 |
-
users = [
|
36 |
-
(1, "John Doe", "john@example.com"),
|
37 |
-
(2, "Jane Doe", "jane@example.com"),
|
38 |
-
(3, "Bob Smith", "bob@example.com"),
|
39 |
-
]
|
40 |
-
|
41 |
-
for user in users:
|
42 |
-
insert_data(conn, user)
|
43 |
-
|
44 |
-
results = query_data(conn)
|
45 |
-
for row in results:
|
46 |
-
print(row)
|
47 |
-
|
48 |
-
|
49 |
-
if __name__ == "__main__":
|
50 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gpt-engineer/projects copy/example/main.py
DELETED
@@ -1,19 +0,0 @@
|
|
1 |
-
from crud.crud import CRUD
|
2 |
-
|
3 |
-
|
4 |
-
def main():
|
5 |
-
crud = CRUD("sample.db")
|
6 |
-
crud.create("sample", ["id INTEGER", "name TEXT", "age INTEGER"], [1, "John", 25])
|
7 |
-
crud.create("sample", ["id INTEGER", "name TEXT", "age INTEGER"], [2, "Jane", 30])
|
8 |
-
|
9 |
-
print(crud.read("sample", ["id", "name", "age"]))
|
10 |
-
|
11 |
-
crud.update("sample", ["name", "age"], ["Jane", 31], "id = 2")
|
12 |
-
print(crud.read("sample", ["id", "name", "age"]))
|
13 |
-
|
14 |
-
crud.delete("sample", "id = 1")
|
15 |
-
print(crud.read("sample", ["id", "name", "age"]))
|
16 |
-
|
17 |
-
|
18 |
-
if __name__ == "__main__":
|
19 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gpt-engineer/projects copy/example/models/duckdb_model.py
DELETED
@@ -1,44 +0,0 @@
|
|
1 |
-
import duckdb
|
2 |
-
|
3 |
-
|
4 |
-
class DuckDBModel:
|
5 |
-
def __init__(self, db_file):
|
6 |
-
self.conn = duckdb.connect(database=db_file)
|
7 |
-
|
8 |
-
def create_table(self, table_name, columns):
|
9 |
-
query = f"CREATE TABLE IF NOT EXISTS {table_name} ({', '.join(columns)})"
|
10 |
-
self.conn.execute(query)
|
11 |
-
|
12 |
-
def insert(self, table_name, values):
|
13 |
-
query = f"INSERT INTO {table_name} VALUES ({', '.join(['?' for _ in values])})"
|
14 |
-
self.conn.execute(query, values)
|
15 |
-
|
16 |
-
def select(self, table_name, columns, conditions=None):
|
17 |
-
query = f"SELECT {', '.join(columns)} FROM {table_name}"
|
18 |
-
if conditions:
|
19 |
-
query += f" WHERE {conditions}"
|
20 |
-
return self.conn.execute(query).fetchall()
|
21 |
-
|
22 |
-
def update(self, table_name, columns, values, conditions):
|
23 |
-
if not conditions:
|
24 |
-
raise ValueError("Conditions are required for update operations.")
|
25 |
-
query = f"UPDATE {table_name} SET {', '.join([f'{col} = ?' for col in columns])} WHERE {conditions}"
|
26 |
-
self.conn.execute(query, values)
|
27 |
-
|
28 |
-
def delete(self, table_name, conditions):
|
29 |
-
if not conditions:
|
30 |
-
raise ValueError("Conditions are required for delete operations.")
|
31 |
-
query = f"DELETE FROM {table_name} WHERE {conditions}"
|
32 |
-
self.conn.execute(query)
|
33 |
-
|
34 |
-
|
35 |
-
# 例としての使用方法
|
36 |
-
if __name__ == "__main__":
|
37 |
-
db = DuckDBModel("test.db")
|
38 |
-
db.create_table("users", ["id INTEGER", "name TEXT"])
|
39 |
-
db.insert("users", [1, "Alice"])
|
40 |
-
print(db.select("users", ["*"]))
|
41 |
-
db.update("users", ["name"], ["Alice Smith"], "id = 1")
|
42 |
-
print(db.select("users", ["*"]))
|
43 |
-
db.delete("users", "id = 1")
|
44 |
-
print(db.select("users", ["*"]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gpt-engineer/projects copy/example/prompt
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
duckdbのサンプルの作成
|
2 |
-
sample.csvを作成して その内容にCRUD
|
|
|
|
|
|
gpt-engineer/projects copy/example/requirements.txt
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
duckdb
|
|
|
|
gpt-engineer/projects copy/example/run.sh
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
python -m pip install -r requirements.txt
|
2 |
-
python main.py
|
|
|
|
|
|
gpt-engineer/projects copy/example/sample.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
"id","name","age"
|
2 |
-
1,"John",25
|
3 |
-
2,"Jane",30
|
|
|
|
|
|
|
|
gpt-engineer/projects copy/example/sample.db
DELETED
Binary file (537 kB)
|
|