Miroir commited on
Commit
cebf2e3
·
1 Parent(s): cf65513

minor updates on game_service

Browse files
app.py CHANGED
@@ -65,13 +65,22 @@ async def use_joker(joker: JokerUse):
65
  logger.error(f"Error using joker: {str(e)}")
66
  raise HTTPException(status_code=500, detail="Internal server error")
67
 
 
 
 
 
 
 
 
 
68
  @app.get("/api/visualization")
69
  async def get_visualization():
70
  try:
71
  state = game_service.get_state()
 
72
  return visualization_service.prepare_3d_visualization(
73
  state["target_word"],
74
- state["guessed_words"]
75
  )
76
  except Exception as e:
77
  logger.error(f"Error getting visualization: {str(e)}")
 
65
  logger.error(f"Error using joker: {str(e)}")
66
  raise HTTPException(status_code=500, detail="Internal server error")
67
 
68
+ @app.post("/api/reset-game")
69
+ async def reset_game():
70
+ try:
71
+ return game_service.reset_game()
72
+ except Exception as e:
73
+ logger.error(f"Error resetting game: {str(e)}")
74
+ raise HTTPException(status_code=500, detail="Internal server error")
75
+
76
  @app.get("/api/visualization")
77
  async def get_visualization():
78
  try:
79
  state = game_service.get_state()
80
+ guessed_words = [attempt['word'] for attempt in state["attempts"]]
81
  return visualization_service.prepare_3d_visualization(
82
  state["target_word"],
83
+ guessed_words
84
  )
85
  except Exception as e:
86
  logger.error(f"Error getting visualization: {str(e)}")
services/game_service.py CHANGED
@@ -1,4 +1,4 @@
1
- # file location: backend/services/game_service.py
2
 
3
  import json
4
  from pathlib import Path
@@ -194,3 +194,22 @@ class GameService:
194
  logger.exception("Error getting history")
195
  return []
196
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # file location: semantix-api/services/game_service.py
2
 
3
  import json
4
  from pathlib import Path
 
194
  logger.exception("Error getting history")
195
  return []
196
 
197
+ def check_word(self, word: str) -> Dict:
198
+ """
199
+ Check a word against the target word and save the attempt.
200
+ Returns the updated game state.
201
+ """
202
+ try:
203
+ state = self._load_state()
204
+ target_word = state['target_word']
205
+
206
+ # Calculate similarity
207
+ similarity = self.word_service.calculate_similarity(word, target_word)
208
+ logger.info(f"Word: {word}, Target: {target_word}, Similarity: {similarity:.3f}")
209
+
210
+ # Save attempt and return updated state
211
+ return self.save_attempt(word, similarity)
212
+
213
+ except Exception:
214
+ logger.exception(f"Error checking word: {word}")
215
+ raise
services/visualization_service.py CHANGED
@@ -1,4 +1,4 @@
1
- # file location: backend/services/visualization_service.py
2
 
3
  import numpy as np
4
  import umap # pip install umap-learn
 
1
+ # file location: semantix-api/services/visualization_service.py
2
 
3
  import numpy as np
4
  import umap # pip install umap-learn