Paweł Łaba commited on
Commit
7e137d1
·
1 Parent(s): 8b6236c

zmiana w uruchamianiu proagramu

Browse files
Files changed (3) hide show
  1. app.py +32 -0
  2. public/index.html +1 -1
  3. public/script.js +0 -1
app.py CHANGED
@@ -76,6 +76,38 @@ async def get_status():
76
  "model_path": "model/model.keras"
77
  }
78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
  @app.post("/move")
81
  async def get_move(request: Request):
 
76
  "model_path": "model/model.keras"
77
  }
78
 
79
+ @app.post("/savegame")
80
+ async def save_game(request: Request):
81
+ try:
82
+ data = await request.json()
83
+ final_board = data.get("final_board")
84
+ sequence = data.get("sequence")
85
+
86
+ if not final_board or not sequence:
87
+ raise HTTPException(status_code=400, detail="Missing required data")
88
+
89
+ game_hash = hash(str(final_board) + str(sequence))
90
+ game_data = {
91
+ "final_board": final_board,
92
+ "sequence": sequence,
93
+ "hash": abs(game_hash)
94
+ }
95
+
96
+ try:
97
+ with open("public/game_data.json", "r") as f:
98
+ existing_data = json.load(f)
99
+ except (FileNotFoundError, json.JSONDecodeError):
100
+ existing_data = []
101
+
102
+ existing_data.append(game_data)
103
+
104
+ with open("public/game_data.json", "w") as f:
105
+ json.dump(existing_data, f)
106
+
107
+ return {"status": "success", "hash": game_data["hash"]}
108
+ except Exception as e:
109
+ raise HTTPException(status_code=500, detail=str(e))
110
+
111
 
112
  @app.post("/move")
113
  async def get_move(request: Request):
public/index.html CHANGED
@@ -15,6 +15,6 @@
15
  </div>
16
 
17
 
18
- <script src="./static/script.js?r=1" defer></script>
19
  </body>
20
  </html>
 
15
  </div>
16
 
17
 
18
+ <script src="./static/script.js?r=2" defer></script>
19
  </body>
20
  </html>
public/script.js CHANGED
@@ -122,7 +122,6 @@ async function handleMove(index) {
122
 
123
  // Inicjalizacja gry i pobranie aktualnego stanu
124
  async function initGame() {
125
- console.log( $('.restart'));
126
 
127
  $('.restart').addEventListener('click', (e)=>{
128
  log('add event restart');
 
122
 
123
  // Inicjalizacja gry i pobranie aktualnego stanu
124
  async function initGame() {
 
125
 
126
  $('.restart').addEventListener('click', (e)=>{
127
  log('add event restart');