gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
would you pls write a service for the game "Ball-Match 3D"?
- User
would you pls write a service for the game "Ball-Match 3D"?
- Assistant
Sure! Here's a sample code for a basic service for the game "Ball-Match 3D":
pythonfrom flask import Flask, jsonify, request app = Flask(__name__) # Store the leaderboard data in memory leaderboard = [] # Route to add a new score to the leaderboard @app.route('/leaderboard', methods=['POST']) def add_score(): data = request.get_json() if 'name' not in data or 'score' not in data: return jsonify({'error': 'Invalid data. Must provide name and score.'}), 400 name = data['name'] score = data['score'] leaderboard.append({'name': name, 'score': score}) return jsonify({'success': True}), 200 # Route to retrieve the leaderboard @app.route('/leaderboard', methods=['GET']) def get_leaderboard(): sorted_leaderboard = sorted(leaderboard, key=lambda x: x['score'], reverse=True) return jsonify({'leaderboard': sorted_leaderboard}), 200 if __name__ == '__main__': app.run()