Multiplayer dream never came true (Python sockets)
Throughout my dev journey I always kept a small multiplayer blackjack game for the terminal dream project on my horizon. It stayed in front of me to finally joined my dev journey when I was done with my setup, remember the NixOS-Tmux-Neovim trinity? Anyways, I plunged into coding it to accomplish my dream but it all ended up in failure and a couple of lessons I'll tell you about on this entry.
Never learn a new programming language with a framework was my personal feedback from my food for thought project. With that in mind I chose to code my blackjack game with just Python and the least amount of libraries and dependencies. Yes, this was another episode of the working with constraints series where Python would become the star of the show.
I took a lot of time thinking on how to approach this dream project. First of, it needed to connect to a free card API to fetch cards from. Also, it needed a server that controls the game through a game manager module and manage communication between two players. Both players would have a player controller to make interactions possible plus a client that sends each player's actions to the server. All of that had to work together as a system with threads and sockets, HTTP calls to the API and a simple UI.
Why didn't I succeed on making my project dream true? There are a couple of answers to that question. One, I gave player's controller the responsibilty to evaluate the state of the game when that responsibility should have been given to the game manager in the server. Two, I was never able to test socket connection with unit tests so I switched to streams upon suggestion but that solution didn't keep the connection between the clients and the server. Coming back to sockets resulted in a dead lock problem where the clients needed a resource from the server and the server needed a resource from the clients to process their required resource. I also want to add that a factor that contributed to this failure was not having solid Python fundations. Learn foundations, learn foundations and again learn foundation and you are less likely to fail.
Did I give up? Not really. I'll try to make this dream true again when I'm done with my rustlings (sort of rust leet code) and a couple of tutorials from the Rust official book. Yes, I want the project to be made in Rust.
Do you want to take a look to my multiplayer blackjack attempt code? Here you go!