OK, I’m excited to get on with the next game, so let’s talk about what it’s going to be. I don’t have much time to play games these days, which tends to limit my playing when I do have time to the sorts of games that can be picked up quickly. Although back in the day I used to like reading the game manuals (and before that typing in the code), these days I need to be able to grasp something quickly and, if I’m going to play it for any length of time, figure out where the “juice” is…
OK, I’m sufficiently bored with this to want to move on. I’m going to push this up to Github at https://github.com/dsbw/fxgames.git.
For future adventures, I’ll do the following: I’ll start a new branch for the game we’re working on, and for each entry in the blog, I’ll commit the changes to git. This should make it super-easy (barely an inconvenience!) to follow along.
I’ll also be a little less drunk in prose and code styles, though not consciously. After all, who wants to be boring? …
Let’s wrap up the “backend” of our tic-tac-toe game by putting in tie-games and making some “artificial intelligence”. Or as I have it in the title, Artificial “Intelligence”. Or maybe it should be “Artificial “Intelligence”” because we’re not doing anything like what’s formally recognized as AI, and “intelligence” is a stretch even by AI terms.
We’ll create some computer players that will play tic-tac-toe against a human player or each other. But before we do that, we’ll need to introduce the game that ends with a tie, because otherwise our artificially intelligent players will keep playing the same game forever.
I feel like we’re coming to the end of our tic-tac-toe adventure. There are some graphical niceties to add in, maybe an “AI”, some polish, etc. But I notice that my “dyslexia” has struck again. I’ve mixed up the columns and rows for the drop-check code such that…well, look:
You see, we have the “not” symbol in the first column, second row and, I can assure you, we have an okay to drop on the second column, first row.
It’s kind of fun to do this simple stuff and see how the need for various things evolved. We’ve seen, e.g…
Last time, we left things hanging a bit because we wanted to save our game data and it was becoming too complicated — or as Rich Hickey put it in his seminal talk “Simple Made Easy”, complected. To “complect” something is to mix concerns, so that we have game logic and game presentation mixed up in the same object.
I did this deliberately, of course — no, really, as much as I make mistakes and pretend I did them on purpose, this really was intentional on a number of levels. …
We should have a way to save our game and subsequently, a way to load it, which would wrap up our tic-tac-toe adventure, but that I think necessitates some way to name the players. After all, it wouldn’t do to have Joe and Fred save their game only to have Faye and Jill come along later and write over it. So, back to the SceneBuilder!
But if we look at our basic board fxml:
We really didn’t give ourselves much in the way of slack, did we? That’s why we ended up doing the group pane in previous sections. We…
So, the first thing we want to do with our tic-tac-toe board, administratively speaking, is allow it to be reset. Although the meat of this is not specifically FX, because we’re just resetting values, it does cross over in some ways. I have done this whole thing in a fairly sloppy fashion, because I find that doing things fast — even though “wrong” — is a great way to get information on how to do them “right”.
When we get out of the rarified atmosphere of math, there is no real “right” and “wrong”, only “righter” and “wronger”.
So, we want to declare a winner. Traditionally this is done by slashing a giant line through the grid, with the loser running to momma crying.
Or maybe you grew up differently.
Now, you can’t just draw a line because of course you can’t. That would be too easy. Think of it this way: FX container nodes typically describe the way its child nodes won’t run into each other. Like an HBox says, “place ’em side by side” and a FlowPane says “place ’em one after the other till you run out of space along that dimension, and then wrap.”
Well, if someone says “You can’t go snark-hunting in your footie pajamas,” there’s a certain segment of people who are going to say, “Well, dammit, that’s just what I’m going to do.” Even if they have to go buy footie pajamas and do a lot of research on the nesting places of the snark.
I am not one of those people — and pay no heed to the snickering crowds of people who claim to “know me” and suggest otherwise — but if I was already going to go snark hunting and had planned to wear my footies, well, someone…
My idea for the tic-tac-toe grid is to have it work as though there were a couple of bins of Xs and Os on the right and the player will drag the token he wants on to the square he wants.
I’ve assigned the controller for the game to TttController and set up IDs for the elements.
public GridPane xobin;
public ImageView X;
public ImageView O;
public GridPane board;
The xobin is where the Xs and Os will live. …
I am a poor, wayfaring stranger, traveling through this world of woe.