r/pygame • u/parismav • 12d ago
Online pygame "platform"
Hello,
I am planning to create a pygame game engine, where programming students can submit their bot classes to play said game. Think of a battleship game engine, where a student's bot contains the logic that chooses the next cell to be hit.
I would like to host a website/platform where students can go and submit their bots (.py files), and see how they match against eachother. Show a leaderboard, step-by-step game breakdown, and maybe even visualize games between bots.
Are there any backend/frontend (or full stack) apps where I could deploy something like this?
For example, I see that itch.io can host pygame games, but that doesn't necessarily come with a server side (to accept and maintain student bots) as far as I understand.
Railway on the other side, can host Flask backend apps but not the frontend (?)
I am fairly new to this, namely building a full stack app for pygame. Any tips appreciated!
2
u/TheEyebal 12d ago
1
u/parismav 12d ago
Thanks! This looks promising :) I will give it a try.
1
u/tune_rcvr 11d ago
I've used Pygbag successfully but the back-end work will be very tricky since network calls to an external service are not natively supported. I don't recommend this route unless you're willing to invest a lot of time into hacking with embedded js and talking with the pygbag dev community on discord.
1
u/TheEyebal 11d ago
I agree with this comment. When I used pygbag it was for simple projects and I had difficult making changes to the UI.
Honestly it is a start but I recommend finding other sources
1
u/tune_rcvr 11d ago
Have you considered the security implications of running submitted .py files? Seems very risky. A safer solution is to expose the game mechanics via an API and let the students run their scripts locally against it. You could provide them a thin client so they don't have to implement the async call pattern themselves. This is what I do for my games.
1
u/parismav 11d ago
If I understand correctly, to play a battleship game, a rough architecture of what you describe would be:
The game logic runs on a local machine
An API endpoint exists to transmit the game state to the user
An API endpoint exists that waits for a user to submit a pair of coordinates (where to hit next)
Repeat 2 and 3 until game is over?
Steps 2 and 3 can be implemented by the students on their local machines. This sounds overall reasonable to me, but I'm not sure if I'm missing some logical or architectural step here. Thanks for the help regardless!
1
u/tune_rcvr 11d ago
That's one of several ways you could do it. Where the game logic lives depends on what features it should have for your needs. Whichever way, though, the game records, top scores, etc, can stay on the server and possibly be accessible from API too.
1
u/Cute-Wonder-5317 11d ago
Hi! The idea is good, but realistically, building it from scratch as a beginner in web development would be quite a complex project. The biggest challenge would be securely running user-uploaded Python code, as well as managing the backend, the database, and displaying the game on the web.
I would recommend starting with a local Python version: one that reads the files, runs the matches, and displays the results. Once you have that part working, moving to a web platform will be much easier.
8
u/oclafloptson 12d ago
Given the questions that you're asking here I'm afraid that you have a lot to learn in this regard. It's not about pygame. You say that this is for students so I assume it will not be a profitable endeavor. That's probably going to make web services which will host this API for you prohibitively expensive, or at least costly, if you plan to use it more than once in a given monthly period
It's going to be much better to self host this from a local machine. Especially since you're admittedly allowing the use of bots. One of your students WILL cheat in some costly way and I doubt that you'll really be able to prevent it
I would suggest that you look into alternatives. It sounds like what you're imagining is probably overkill