BLOGROLLS

CSharp Upgrade & nvim macros

By: wormius On: Fri 17 January 2025
In: misc
Tags:

Back in 2015, for my Quardinex/Tetrakinesis game, someone provided me a graph traversal solver for it written in C#.

For YEARS I have been trying to get one working via my own hand in Python. My first attempts have always failed, initially due to the limited stack. I learned that I need to memoize the data (deepcopy) in order to prevent recursion of edge links to nodes ad infinitum.

Regardless, I stopped that for now. I did find networkx which I used in a naive approach, however, while it supports directed graphs, I am not sure if it supports acyclical graphs. Or rather, my graph is time-contingent. That is, the state of the graph changes as a player makes a move on the board. It is similar to the Knights Tour where a previous visited location is completely removed from the board, and cannot be revisited. Networkx does seem to have some pathfinding ability, but from what I can tell it's more about finding a path exists between a start and end node, not whether the "board could be cleared"/all paths from a given node can be found.

So - I went to the old code, because there are a few things I want to do with the current puzzle solving code that I have.

Right now the code I was given only solves for a single board. It also only solved for a given start location. I also was pretty sure my original boards were all solveable, but I lost some of the original layouts, and tried to generate some just manually. I had trouble with solving some of them, and wasn't sure if they were solveable or not.

Using the C# solver, I was able to determine that at least 3 of the 25 puzzles had no solution. I ran through every single start point.

I also found an interesting one that had NO solutions for any start points except one particular node/location on the board, but that one had 428 possible solutions, which was kinda crazy (IIRC).

So, the next goal is to create a jagged array of multidimensional arrays (currently my boards are m*n sized, m=n; a multidimensional array in C# terms.

This way I can load all 25 boards, and just iterate through them. But I really dislike C#'s handling of arrays. I could probably try to figure a way to do it with lists, I suppose. But the verbose method of declaring an array of array, where you have to declare "new int[]" for every sub array, instead of it just automagically knowing due to the original declaration.

That said I'm working on an old model of understanding, and since so many pages dealing with this may be older, if there has been syntactic sugar added, they haven't been reflected in the documentation I've seen. I really appreciate the ease of which JS and Python handle arrays/lists. It's soooooo much simpler.

What I'd like to do is determine every single solution for every single board, from every single starting point/node. This would allow me to determine diffulty for each board and rank them in order for players (or giving a set of tiered options: easy, medium, hard). Because you may have a smaller board, with fewer solutions, as a ratio, then a larger board that may have more solutions. My current method is dividing the size of the board by the number of solutions to determine the difficulty level.

Anyways, in the process of messing with this stuff, I decided to update from 4.81 .NET to 9.0 .net/core. So I had to deal with a bunch of stupid MS bullshit just to upgrade, but found a nice tool called try-convert that was able to upgrade the project.

Finally - the other fun thing I learned was how to use macros. When generating the solutions of the graph traversal, there was a space between each one, and for the small amount of solutions, I just arrowed down and deleted the spaces (usually just 1 or 2 "downs" and then delete key, but once I hit some puzzles with hundreds, I was like eff this noise... I looked up how to use macros in nvim, and holy cow. it made things super easy and nice. and was far more intuitive than I thought. I know it's far more powerful as well, but I'm not sure how much I'll need it, but as text processing goes, damn, thatw as nice and convenient).

New job, going to training tomorrow. Morning. Blech.


If you found the article helpful, please share or cite the article, and spread the word: