Sealed Tonight #1

So I did a Sealed Theros Phantom Event tonight on MTGO. I was hoping to get out of my loosing streak which is 0-4. Long story short I didn’t really fare any better.
The event was a standard 8 person sealed, but the only win I got was on a bye and I don’t really consider them real wins. So the streak is now 0-6 *sigh*.

The event was not a real blowout however. I felt like a made slight improvements on my deck building as well as my general game. With regards to the deckbuilding I put together a pretty solid midrange white/blue deck with a few early aggro elements (hooray for Vaporkin). Both rounds I won the first match, but my deck fell through on the second one and I the both times decided to sideboard aggresively into a black/green control deck. That didn’t improve the situation. I got especially annoyed in the last game, where my opponent got a [c]Fleecemane Lion[/c] out and I didn’t play a [c]Time to Feed[/c] on my [c]Nylea’s Disciple[/c] to take it out before it got monstrous. Apparently I didn’t totally internalize what Marshall Sutcliffe and Brian Wong spoke about on Limited Resources episode 211.

 

So my key learning points from this is:

– Stick with the deck and don’t just throw it away because you lose one match

– Remember what works when playing or holding back spells

– Don’t get greedy

 

Until next time, with dedication

Lars

Revamping “Neurons In Action”

Hi all,

I’ve felt that this site has been a bit idle and inactive for a while. The reason for this I think is that I haven’t really felt any interest in the topic on which the domain was aimed at. I’ve therefore decided that, instead of discontinuing the site, I’d revamp it into something that I do feel like sharing my thoughts on.

At the moment I’d mentally preparing for the prerelease of “Born of the Gods”. For those of you who doesn’t know what this is, it’s the upcoming expansion for the collectible card game Magic: The Gathering. I’m really loookign forward to this and I’m playing a bit online to try and improve my skills, which currently is in a sorry state. The revamp will make this site into sort of a logbook of my matches and whatever research and resources I manage to come across. It doesn’t imply that Android development is totally off the table, just that you’ll probably see a lot more updates that’s got nothing to do with that.

With dedication

Lars

Merry Christmas to everyone

Hi all,

It’s that time of the year. The time when we get to spend a little time with the family and enjoy a Chrismassy meal and a few presents perhaps.

I just wanted to wish all of you a merry Christmas. I hope you and you families have a happy holiday 😀

Building an AI with ASyncTask

I’ve wanted to add an AI for the 10.000 game, since giving users a single player option seems like a necessity, if I want to retain them. I for one was getting a little bit tired of playing both sides, if I couldn’t find someone else to play against.

The game before implementing the AI
Up until now the game has been built around the assumption that only users generated input for the game. I didn’t really take any measures to incorporate alternative input methods that an AI could use.

Drawing the architecture of the app you’ll get:

UI –> Model

Needless to say I’ll put a little bit of thought into the architecture, before punching in any lines of code, since there’s no simple way to integrate it in the existing architecture. As the model stands now, it has a set of methods that you can use to manipulate it’s state with, giving me some flexibility.

Examples of this are:

public boolean canRoll()
public void performRoll()
public boolean performLock(int diceNo)

Caveat: Expanding the app with an AI
I could write an AI class, that could manipulate the model, using the available methods. However, if I did that;

  1. How would the AI know when to update and when not to?
  2. How would the UI know when to allow user input and when not to?

Using the Observer pattern (through the Java event model) enables me to publish events. With these events I can trigger the two classes and thus get them to do something, be it a calculation, a move etc. It doesn’t however limit them from performing actions, when any or every event is published. The Command pattern could probably be used in this regard, to give the model some uniform way of validating which actions are ok and which are not. That partly solves the problem, since it does not limit the AI would from performing a task and the UI would still enables user generated input.

The proposed changes so far
Updating the architecture with the AI gives me a diagram:

UI –> Model <– AI

It only states that the UI and AI should exist as separate objects and that they can independently make calls to the model. To ensure that only the allowed object can perform actions at a given time, the model needs to check who’s making the calls.

Caveat: Figuring out who invokes a method

The model could use Reflection to figure out who invoked a given method. Using Reflection does generate an overhead in resource consuption, compared to simpler solutions, and I’m not entirely convinced that it is secure. I base that assumption on this thread.

A simpler implementation would be to change all public method signatures to include a reference to the calling object as the first parameter. This must be filled out with a “this” reference, when any object tries to call a method, thus ensuring a check for legality of the performed call. The solution doesn’t gurantee a solution to the security issue 100%, since you could just pass a reference to another object, but I’ve decided there’s no need to bring out any bigger guns, when ther’s only a game of 10.000 at stake.

The aforementioned examples gets updated to:

public boolean canRoll(Object caller)
public boolean performRoll(Object caller)
public boolean performLock(Object caller, int diceNo)

Now we’re getting somewhere 🙂

Implementing the AI

Since the AI will be doing some computations and needs to be able to idle for a bit, so that the user the AI performed actions separately in the UI, it’s necessary to place this in a separate thread.

Caveat: AI and the UI thread
Implementing the AI (by extending the Thread class or implementing Runnable) doesn’t detach the AI from the UI. This means that when the AI goes into a wait state or does some computations, it’ll lock up the UI. This is a sure way of degrading the user experience and may even result in some ANRs. It should be obvious that you’ll want to avoid this.

The answer is using AsyncTask to detach the AI from the UI. The AsyncTask is part of Androids threading framework and solves the problem of locking your UI thread. An alternative could be using an IntentService, but with a litte careful programming I believe that an ASyncTask will solve my problem just fine.

One thing to be aware of though, is if your app gets reloaded, for instance if you rotate the screen, the AsyncTask will be killed. Program your solutions accordingly.

 

That pretty much wraps up my thoughts for how to expand the architecture in the 10.000 app. Be sure to check back for more information 🙂