Posts

Showing posts from 2016

Accountability(); Pt. 1 Intro

Image
Procrastination is a wonderful thing. I meant to start documenting this back in august when I started working on the app, but then I made a promise to myself that I would do it the next day.

Anyways, it's November, so better late then never right? According to blogspot the only people who read this blog anyways are bots from porn websites, so who am I disappointing?


The Basic Premise

As a quick reminder I currently work at an after-school care program for elementary school students, and one of the main things that we have to do is something called "Accountability." Unlike a normal classroom, where a teacher will tend to deal with his/her entire class as a whole IE: Sending them to music, the gym, computer lab, etc, we allow kids to move (somewhat) freely between different rooms, such as the art room, gym, multi-purpose, and alike. This means we CONSTANTLY need to keep track of which kids are in which room as they switch.

Pretty much every school in our program uses the s…

Othello(); Pt. 3 The AI

Image
This is it. The moment I have been waiting for! With the actual game part complete, all that is left is to program the AI (the reason I started this whole project).

My theory on how the AI will work is pretty simple:
1) Check all valid positions
2) Pick the position with the highest outcome of flipped pieces.

The first step is to eliminate all the spaces which are not possible. We know that a space is only valid if it can flip at least one piece, so that means that one of the bordering spaces of an empty piece has to contain at least one piece of the opposite color.

In order to check for this, I run a 3x3 grid over every space, and if the center is empty, then it checks the surrounding spaces for one of the opposite color. If there is one of the opposite color, then it marks that space as "possible." Even though this will still mark spaces that are not technically possible, it narrows it down enough to be useful. The result is this:


From here, I can the "tryFlip()"…

Othello() Part 2: Simple logic

Image
At this point I have all of the drawing code implemented. The pieces and UI are drawn to the board, as well as being able to place pieces randomly on the board (which you shouldn't be able to do, but oh well)


The rules of Othello are simple:

You can capture your opponent's pieces by trapping them in between two of your own. This can be up, down, left, right, or diagonal. You can capture more than one piece if possible.Only pieces directly affected by the current turn are flippedYou can only place a piece if it "captures" at least 1 other pieceThe game is over when no other moves can be made. In order for any of those rules to be implemented, the first rule has to be somewhat working, so lets start with that.

I came up with a basic algorithm in my head, and it ended up working pretty good. It takes the X/Y of the cell the mouse has clicked in, and checks all 8 directions around it for a piece matching your color. If it encounters an empty space, then it stops checking …

Resurrection and... Othello();

Image
I decided instead of letting this blog just sit here, I might as well use it to share some of my personal projects and talk a little bit about them.

Recently I had realized that throughout all of my programming projects that I have worked on, be it personal or freelance, I have never once programmed an AI! I mean, technically I have, but I would hardly count a stationary floor turret as an "Artificial Intelligence," as all it did was do some trig on the players position to figure out what angle to point. So I started looking up dozens of videos on AI theory, and A* algorithms, but then I realized I didn't have a project to build an AI into.

Enter, the Othello project. As I said in my first post,  I work at an after-school care program at an elementary school, which means I do a lot of games and activities with the kids. One of the big games that the kids always want to play is Othello, and so just out of curiosity I decided to try and program an Othello AI with the goal…