Posts tagged ‘Magic’

Trying out the StackExchange platform

For the last couple of days I’ve been obsessing over a new toy. Jeol & Jeff, the powers behind StackOverflow, have launched a public beta of StackExchange – a platform for hosting Q&A sites. Browsing the list of stack exchange sites, I saw several more and less successful sites, including:

I decided to try and open my own site, about Magic: The Gathering. The setup itself was rather easy. I:

  • Bought a domain and set it up, with some help
  • Seeded the site with some questions and answers
  • Tweaked the color scheme, logo and favicon (thanks Eran)
  • Got some friends to help out (though so far they’ve only posted answers, not questions)
  • Setup Google Analytics, and noticed incoming search traffic only stayed for 42 seconds on the site
  • Opened a small AdWords campaign, paying 1.5$ a day to test the water.
  • Post the site on this blog, of course.

Now what remains to be seen is whether the site can accumulate the needed critical mass. For now, the site is in beta, meaning I don’t have to pay anything to keep it running (except time and effort). When the beta is over, the cost will be $129 a month, which is quite challenging to make using adsense.

Keep your fingers crossed for me :)

P.S.

Just got a $100 coupon for AdWords by visiting Google Webmasters Tools – how cool is that? In a second look, it appears the coupon was lying in my Webmasters Tools inbox for two months now, just waiting for the perfect opportunity.

I also forgot to mention opening a uservoice forum (+ adding the widget to my site).

Zendikar draft walkthough – green red

A new year, a new Magic block. Get the latest draft walkthrough here.

Java is less magical than C#

I have been programming in C# for several years now, and recently made the switch to Java (at least for now). I noticed that Java, as a language, is “less magical” than C#.

What do I mean by that is that in C# things are usually done for you, behind the scenes, magically, while Java is much more explicit in the toolset it provides. For example, take thread-local storage. The concept is identical in both langauges – there is often a need for a copy of a member variable that’s unique to the current thread, so it can be used without any locks or fear of concurrency problems.

The implementation in C# is based on attributes. You basically take a static field, annotate it with [ThreadStatic], and that’s it:

[ThreadStatic]
private static ThreadUnsafeClass foo = null;
 
private ThreadUnsafeClass Foo
{
  get
  {
    if (foo != null)
      foo = new ThreadUnsafeClass(...);
 
    // no other thread will have access to this copy of foo
    // note - foo is still static, so it will be shared between instances of this class.
    return foo;
  }
}

How does it work? Magic. Sure, one can find the implementation if he digs deep enough, but the first time I encountered it I just had to try it to make sure it actually works, because it seemed too mysterious.

Let’s take a look at Java’s equivalent, ThreadLocal. This is how it works (amusingly enough, from a documentation bug report):

public class SerialNum {
     // The next serial number to be assigned
     private static int nextSerialNum = 0;
 
     private static ThreadLocal<Integer> serialNum = new ThreadLocal<Integer>() {
         protected synchronized Integer initialValue() {
             return new Integer(nextSerialNum++);
         }
     };
 
     public static int get() {
         return serialNum.get();
     }
 }

No magic is involved here – get() gets the value from a map, stored on the calling Thread object (source code here, but the real beauty is that’s it’s available from inside your IDE without any special effort to install it).

Let’s look at another example – closures.

In C#, you can write this useful piece of code:

var list = new List<int>();
...
// find an element larger than 10
list.Find(x => x > 10);

You can also make this mistake:

var printers = new List<Action>();
...
foreach (var item in list)
{
  printers.Add(() => Console.WriteLine(item));
}
Parallel.Foreach(printers, p => p())

An innocent reader might think this prints all the items in list, but actually this only prints the last items list.Count times. This is how closures work. This happens because the item referred to in the closure is not a new copy of item, it’s actually the same item that’s being modified by the loop. A workaround is to add a new temporary variable like this:

foreach (var item in list)
{
  int tempItem = item;
  printers.add(() => Console.WriteLine(tempItem));
}

And in Java? Instead of closures, one uses anonymous classes. In fact, this is how they are implemented under the hood in C#. Here the same example, in Java:

for (Integer item : list)
{
  final int tempItem = item;
  printers.add(new Action(){
    public void doAction()
    {
      // can't reference item here because it's not final.
      // this would have been a compilation error
      // system.out.println(item);
      System.out.println(tempItem);
    });
}
...

Notice it’s impossible to make the mistake and capture the loop variable instead of a copy of it, because Java requires it to be final. So … less powerful perhaps than C#, but more predictable. As a side note, Resharper catches the ill-advised capturing of local variables and warns about it.

I myself rather prefer the magic of C#, because it does save a lot of the trouble. Lambdas, properties, auto-typing variables… all these are so convenient it’s addictive. But I have to give Java a bit of credit, as the explicit way of doing stuff sometimes teaches you things that you just wouldn’t have learn cruising away in C# land.

Alara Reborn Draft Walkthrough – 5-Color Naya

Another Alara Reborn draft, this time a Naya deck with some 5-color & bombs.

A lucky Alara Reborn walkthrough (Esper)

Check out this lucky Esper walkthrough (Alara Reborn).

Conflux draft walkthrough (Domain/5 color)

A new Magic set has been released, check out my new draft walkthrough.

Another draft walkthough, Grixis

Find it here.

Another draft walkthrough, 4-color Alara

Check it out here.

Multiplayer Magic meta-strategy

Last night I played multiplayer Magic with my usual group, and for the first time we have 5 players instead of the usual 4. Usually we play 2 headed giant (2 players act as one giant and duel against the other 2 players), or occasional chaos magic – basically Last Man Standing, where everyone fights against everyone.

Two headed giant is rather simple in its meta strategy, and Chaos multiplayer is usually about who can hide his intentions long enough, not be noticed, and then wipe out everyone else.

Last night was different. We played an unnamed variant (didn’t find it here) that has the following rules:

  • A player can only attack the players opposite of him (his opponents)
  • A player can target whatever he wants (opponents’ creatures, allies creatures, …)
  • A player wins if his two opponents are dead

We’ll use the back of a magic as a convenient representation for the players (suppose for simplicity that there are 5 mono-colored decks that sit at the appropriate positions).

It appears this format has much meta-strategy: At first, you have your two “opponents” and two “allies”, and the game seems orderly. You attack your opponents and encourage your allies to attack your opponents instead of your other ally. Around mid-game, you start seeing one or two players with a bad board position and/or low life score. This immediately turns them to the underdogs.

The allies of these players do not want them to go out. If the weaker player dies, his allies are more vulnerable. So, his allies start defending the weak player more vigirously, throwing precious spells at their own allies, in to save their other weaker ally.

When the first play dies or is very near death, things change again. Let’s say the Black player dies. If Blue will die, then Green wins. Therefore, it’s in everybody’s interest except Green to prevent Blue from dying. The same goes for Red – if he dies, White automatically wins. So Blue, White’s ally, will do everything possible to prevent Red from dying – even though Red is Blue’s traditional opponent.

What should Blue do? The answer is simple – quickly take out Green. Once Green is out, the game degenerates into 2 on 1 – Blue & White both take on Red and usually win together (if their one remaining opponent dies, both win at the same time). Symmetrically, Red must take out white as soon as possible. What might happen is that with Red protecting Blue and trying to kill White, it might be in Red & Green’s best interests to unite against White – the sooner White is out of the equation, the sooner both can win (in a joint victory). If Green doesn’t want to share victory and refuses to turn on White but tries to kill Blue directly, most likely that all three players will kill him off first.

We played two very interesting games last night, and I died first in both, so don’t take my post-analysis here too seriously. What I think is certain, is that like chaos multiplayer, you should beware of appearing as the strongest player on the board. The strongest player will be taken care of before everyone else, and will eventually die (in my case, I had Avator of Woe out, which would have dominated the game if I hadn’t been killed straight after I played her – great card btw for multiplayer magic)

Apparently, I’m a gamer

I’ve been playing Magic online for quite some time now, and have always had problems connecting to other players. Magic isn’t a bandwidth intensive or particularly sensitive to network latency, but I found that more and more I’m getting disconnected, have huge (10 seconds +) lag, and just plain connection problems.

Well, today, the problem is solved. It appears that Smile 012, my ISP, had to classify me as a “Gamer Profile” in order to get a straight connection working. These two test sites just would not work 99% of the time under the normal profile. It appears that the so called Gamer Profiles are connected to the internet backbone by fewer hops (012 usually charge 15 NIS – 4$ for this privilege). I’m not sure why it worked – as I mentioned, Magic shouldn’t be affected this much by latency.

Anyway, if you have the dubious pleasure of being a 012 customer, and want a supposedly better connection to the backbone, just tell them the tests sites I listed don’t work well for you – they won’t charge you for it. I think it also improved my torrent speeds.