I suggest you gentlemen invent a way to put a square peg in a round hole. Rapidly.- Gene Kranz (Apollo 13)
Tuesday, March 12, 2024
If You Build It, You Need to Send it Out
Sunday, December 17, 2023
Artisanal Code by Software Artists
The problem with schools are that they are run by people who WERE good at things.- Alex Lindsay
Saturday, November 18, 2023
AI: The Mediocre Solution
"Looks for what's there. Not what you want to be there. You will see the truth soon enough."- Sherlock Holmes (Enola Holmes)
Thursday, November 2, 2023
Cribbage and the Python
You get beautiful designs when you build simple things that compose correctly.- Chris Lattner
I’ve been ramping on on writing software for AI, and Python is the language of AI. So I thought to myself, could I write a Cribbage Engine in Python, wrap it in Gymnasium and then use Stable Baselines to build an RL agent that could play cribbage well through re-enforced learning. Welp, I’m not there yet, because I built the cribbage engine and started doing some statistical analysis and have gone done the rabbit whole of programmatic cribbage and statistical regression.
Cribbage holds a special place in my heart. When I first met Mrs.Chaos somehow the topic of cribbage came up and we learned that both of us had played a lot of cribbage. It is not a popular card game. She beat me at cribbage... a lot. So, all that time ago, being the nerd I was (am?) I wrote a little engine in JavaScript where you put in the six cards in your hand and it would do a very basic calculation to tell what to discard. Running that PWA on my iPhone 3 took around 30 seconds to crunch, I wonder how fast it would go today? Sadly, the program is lost to the land of wind and ghosts.
This time, because I was trying to learn Python, I built the whole cribbage game as an engine with an agent that played randomly. I have THOUGHTS on Python for later. I kept running 100 games and player one would win 70/30 and I figured I must have a bug - and it was player one always had the first crib. So, if you have the first crib in the game, you have a significant advantage. Once I fixed this so that playing multiple games alternates the crib, the win rate balanced out to 50/50. Good! Seems solid.
There are a couple really difficult problems in scoring cribbage. When the run is occuring, a straight of 3-cards can occur out of order and then can be built on. So a run of (5,7,6) scores a run of three, for three. Then a (5,7,6,4) builds on that for a run of four. But a play of (5,7,4,6) does not count as a run of four and scores no points. In scoring a hand, it's important to score a complete run (4,5,6,7) for for points, but then DO NOT score the sub-runs (4,5,6 and 5,6,7) of three.
Then, rather than build the re-enforced learning agent, could I program a decent cribbage player? I find when I start to peel a game apart it makes me a better player. Play begins with six cards dealt to you, so how to decide what to discard? Oh, university combinatorics, how I miss you. C(6,2) (six choose two) and Python does have a nice helper for that: list(combinations(player_hand, 2))
Now, once those two cards are “discarded” to the crib, run through ALL POSSIBLE forty-six cards left in the deck and if it were chosen as the run card, what is the hand worth? Get an average score for the possible hands. Then for the two cards into the crib for ALL POSSIBLE combinations of two from the forty-five cards C(45,2) what is the average value of the crib? If it’s your crib, add it and if it’s the opponents crib subtract it. Pick the highest score and go for it.
There are some missed optimizations here - because based on your opponent you might have different strategies. For a good opponent, the likelihood of any particular discard to the crib will not be random. ACTUALLY, this would be a fascinating statistic to look out. What are the most common discards for this particular agent over time and then use that to adjust the model from an even distribution. Put it on the W0511 list (that's a pylint joke, hysterical)!
After the discard, the other part of the game is what cards to play during the run portion of the game. So here was the strategy I programmed. First, for all the cards in your hand, if you played it, what is the amount of points you would get? Then I nudge this based on a few different strategies. 1) If the run total is going to be less than 5, nudge it up, because that means your opponent can’t get 15. 2) If the run total is going to be exactly 5 or 10, nudge it down, because that means your opponent may more likely get a 15. 3) If the run total was LESS than 15 and your card makes it MORE than 15, nudge up, because you blocked your opponent. 4) Finally, all other things being equal, play the biggest card you can because that helps towards you getting a “Go” for a point.
So that’s the engine. How do you think it does when the OptimizedPlayer goes against the random player? It wins 80/20. So, what I’m reading here is… if you are a really good cribbage player and your opponent is playing randomly, they still win one out of five times. How did Mrs.Chaos beat me so often? I will never know. Maybe I was sub-consciously letting her win.
Monday, October 2, 2023
Don’t Say It Outloud—Augmented Reality
Wednesday, September 13, 2023
AI Won’t Take Your Job; I Might
Tuesday, February 21, 2023
Six Color Report Card 2022
Every year, for quite a few years now, Jason Snell over at Six Colors does the Apple Report card where he sends out a survey to a collection of developers, journalists, and enthusiasts of Apple and compiles a “how are they doing?” view of things. I am not one of the panelists of the report card,but as an Apple fanboy, I find it find to review on the questions he is asking.
Mac - A
The Mac is doing great. I can ride on the coattails of last years M1 release and just see that the Mac hardware is crushing it and the software continues to move forward well. I don’t need crazy innovation in the Mac world, just year-over-year improvements and a continual push of the platform forward. I’m proud to be a Mac user in work and in my personal life. I cannot imagine being a Windows user, a Linux user, or a Chromebook user.
iPhone - A
For the last couple of years, slightly by surprise, I have been using an iPhone SE. Here is what I realized - all iPhone are great! I will probably return to a Pro Max at some point, but honestly, having the iPhone SE has never felt like a problem for me. The Touch ID is a bit rough in the cold winter with my gloved fingers, but no more difficult than Face ID when wearing a mask due to covid. The iPhone and iOS is a mature platform, and I’m perfectly happy on the cheapest version for years ago. That is surprising to me!
iPad - B
I don’t have a personal computer anymore. For work, I have a MacBook, but for my own personal life the iPad is my primary computing device and I don’t think I need anything more. This year, when I’ve needed to do some complicated personal computing, I’ve plugged in an external monitor with a mouse and keyboard and gotten it done.
Every year I ask myself the question, can I use my iPad for work? I’m an systems integrator / solutions engineer, and for the most part I totally can. The introduction of Stage Manager was rough - but mostly met my needs. I simply wanted to have a second display and so now I can run two apps at the same time each running full screen - one on my iPad and on my external display. Even more, I can run video conference (Google Meet, Zoom, Teams) and I can screen share on my iPad display while my secondary display is running Slack as I complain to my coworkers about how dumb the meeting is.
My main problem is apps quitting in the background. I do a lot of stuff that requires a persistent connection so having my ssh connections (via Prompt) or my screen connections (via Screens) quit in the background totally messes up my flow. I have to aggressive manage my stages in Stage Manager to try and keep those apps from quitting - and I make sure I am running screens on the destination Unix system so when I do drop I can reconnect.
Wearables - A
I wear the latest Apple Watch for health tracking as part of the quantified self and I love it. There’s nothing magical about it - but I feel a sense of reassurance that I’m logging heart rate, Sp02, etc. over time and that each time I do a walk or go rock climbing I can log the workout. I honestly feel sad when I forget to log a workout; it’s like it didn’t happen.
Apple TV - B
It’s fine and I think this is mostly a commodity space for me now. I have a sense that AppleTV stalked me less than the competitors? I don’t use Up Next, I use three apps: TV Time, Movies (both track through Trackt) and JustWatch. That is where I manage all of the list of shows and movies I want to watch along with figuring out where the heck I am able to watch shows.
Services - B
There is nothing special going on for me with services. I am not an Apple Music subscriber, I take my free Amazon Prime music. I don’t subscribe to Arcade or Fitness or TV+. I conceptually like the idea of Apple One, but for now, it’s just not something that speaks to me.
HomeKit - A
Okay okay, I hear a lot of griping about HomeKit and that Matter is going to solve it - but for me, HomeKit works great. I make sure to buy everything HomeKit that I can and I have a few minor things I need to use HomeBridge for, but I am happy. Open the garage door and the lights turn on. “Hey Siri, goodnight” turns off the TV, lights, and turns on the fan. At my friends house, when the indoor air quality drops, his air purify turns on. HomeKit makes all of that happen and it’s not difficult.
Hardware Reliability - A
I haven’t really had any Mac or iOS hardware failures. It all continues to work and keep on trucking.
Software Quality - A
I don’t struggle with software quality. It all works and works well. I know there are some complaints about the System Preferences changes for macOS, but that’s fine. I know Stage Manager has been a bit of a fiasco, but it does sort of get the job done. Mostly, I find things work and work reliably.