Boardgasm.Py: builtin method overriding

So – tonight I had something that looked like:

During work today, I thought why am I making a whole second method that’s just a basic wrapper around another method?  If my intuition of Python is correct I should be able to override the method, and further, that it would be fairly trivial.

So I coded the following attempt:

Do you see the issue?  Infinite recursion.
Ok, so I’m calling the append method to the list, but the append method has to call itself to add, but then.  OK, I put it aside for a bit, and when I came back to it later, it occurred to me.

There maybe a way to call the list method by calling the list class itself without instantiating it into an object.
I don’t know why this occurred to me, but I thought you know it just seems like something Python would do…

So, I modified the above code to this:

So here, on the third line, I went from self.append(player) to list.append(self, player).

Instead of calling the custom append code (self.append) , I call the original unaltered append (which was the intended behavior all along of course).

When it worked, and I double and triple checked that it actually worked, it was one of those. Well FUCK YEAH moments.

When your intuition of what SHOULD happen and what DOES happen pleasantly aligns, and not only that, the WAY it  happens is different enough so you get to LEARN something in the process.  Now that is beautiful.  And when you see HOW it did what it did and understand it, it just.

I hate to use “elegant” because it’s overused as is, and sometimes misused.  But goddamned there is something elegant about this.

The fact I was able to logically assume a certain modus operandi w/Python and see that my assumption turned out correct and further more that it matches my perception of how something would be done in the language.

I’d say that’s pretty damn Pythonic in itself.

There’s always the particularities, and an any system you’ll run across such little pleasures that make you appreciate how something is done a certain way.

So I started to work on a python version of the little code I had in C#.  I ended up making a simple player class.  I learned the “extend” method of the List class.

I was testing my list of players by doing Playerlist.append(p1)

But I tried to append a list Playerlist.append(p2, p3)

No dice.  Looking up info I found that since append appends as a single object I’m not appending the 2 player objects, only appending a list as a single unitary object I imagine if one were to view diagrammatically visually it may look something like [p1, [p2, p3]] 2 object list, player object and list object as opposed to [p1, p2, p3]  3 object list, 3 individual player objects.

So learned about the “extend” method to append an actual list to a list (I’m sure it’s deeper than that, but that’s the basic use I had for it).

The fact that Python is so vastly different to C# and I’d have to learn a lot of the particularities may mean that I may not want to do it.

On the other hand, I coded a lot of what I wanted in a shorter time and in less code than it took for C#.

Then again, I had already done the hard work w/C# to figure out the basic situation.

Perhaps, the next test would be the inverse – write in Python (this time the code for dealing with Pawns and ownership of pawns and their location in the playspace), and write the C# code after the Python.  I could see if writing in Python helped the C# go quicker.

Most of the issue is that my intuition of some things in Python don’t quite fit the actual model it provides.  And that’s fine, that’s just how Python is (or any language) and you’ll always be having to rethink such things, whether it’s a programming language or a specific library.  You’re never going to know all models 100% exactly.  That’s why they’re models.  And those models/frameworks you’re working with, may have underlying patterns that act as a common language of understanding or it may be that those models are, themselves, common languages between classes of thinking/operating.

Project BoardGASM (Graffiti Royale Board GAme State Manager)

The Graffiti Royale GAme State Manager idea is now Project BoardGASM.
So far I created a C# basis with a general object manager, and simple construction of Players (with names, id/player#, color attributes set).

When logging in, I test the character to make sure they’re less than the total number of allowed characters in game and if not, sorry, lobby’s full.

I had fun making 3 different ways to create a list of players… I Have a 4th way to try (which will be just as non-useful as the 2nd method below)

1st Used a method that created each player as a new object then added them individually. :

p1(“name”, “color”) …; AddPlayer(p1);

2nd Using varargs, I passed them in at once using an array.  For a simple setup purpose this isn’t bad, but if I were to use a server system for an online method I’d be logging in one at a time, not an array, so this was a mild waste, but I did learn how to do it which was what my goal was.

AddPlayers(p1, p2, p3, p4);

3rd Used the actual method I’ll probably end up using by directly passing in the data (after sanitizing, natch) offered for Player name and color choice, as entered in a field/selected from a menu.  The “player number” at this point is just determined by ordinality of login.  That could change, but for now good enough.

AddPlayer(“name”, “color”).

The 4th method would be a blend of 2 and 3 (and hence, why I said non-useful).  Basically instead of AddPlayers(p1, p2, p3, p4), it’d be something like AddPlayers(“Name1”, “Color1”, “Name2”, “Color2”, “Name3”, “Color3”, “Name4”, “Color4”)

I decided it would be fun to do this little bit in multiple languages and decided Python would be the next one.  So I got the first method up already.  It was less headbashy in some ways (once I got the actual python tools installed in vscode – I could do it in WSL/nano/vim(blech), but VSCode did it quite well).  I did see an interesting terminal editor that has UI and themes that’s more like Sublime/VSCode, but for the commandline, so I hope to try that if it’s workable in WSL).

But while Python was less headbashy it’d been a while since I did anything in it more complex than a simple script.  So I had to relearn how classes were made, and moreso, remembering how to deal with implicit typing (since most of my coding’s been with explicit type declarations)  Well, it was slightly brainjiggering.  And I haven’t done much using “var” in C#.

It did occur to me, however, that my earliest programming experiences were based on implicitly typed languages.  BASIC and Logo (At least IIRC, the Logo we used (Color Logo) didn’t have any explicit type system)).

I guess I’ll work on finishing the python bit and creating maybe a simple JSON file to parse for feeding in as player data so I can use that with all the different implementations I use (instead of hardcoding the test values/fake players in the main code).  Good practice to get into, me thinks.

Oh – I also spent a lot of time trying to get get github going in VS.  First time using Github, had used Bitbucket, GoogleCode and one other thing before that.  And always with hg, not git.
I saw VS have git integration and was like NICE!  But getting the first thing setup because it wouldn’t let me merge due to some “future”state crap.  Even though the solution was to pull, apparently.  It wouldn’t let me.  I ended up just downloading the git Windows client and that worked like a charm.

If anyone’s curious.  Here’s the github for it…