Tuesday, December 20, 2011

On the Enchantment Level - Bookshelf Dependency in Minecraft

[Editors Note: For those who do not play Minecraft, you should. You can play it in your browser here, but I strongly recommend downloading the client from here.]

[Another Editors Note: This post is outdated. Updated versions are available for the enchanting systems introduced in version 1.1 and version 1.3]

After watching episode 125 of Etho's Minecraft series, and listening to him complaining about how long higher level enchantments take to find, I decided to work out exactly what the distributions of the various enchantment levels are, and find the optimum number of bookshelves to use when looking for a specific enchantment level.

Because there is an increasing scale for the amount of experience required to obtain each level, a lot of experience is wasted if you spend your levels on more than one enchantment at a time. For example, if you start at level 0, and gain 10 levels and spend them on a level 10 enchantment, and then gain another 10 levels and spend them on another level 10 enchantment, you will have had to kill roughly 154 hostile mobs to obtain those two level 10 enchantments. But, if you gained 20 levels, and then spent all of them on two level 10 enchantments, you would have had to kill around 294 mobs for the same net result.

As a result of this, it is necessary to find an enchantment that will use up all (or almost all) of your levels in order to minimise the amount of experience wasted.

When enchanting an item, the player is offered three possible enchantments of random levels. The levels of the enchantments that are offered depend on two non-random and three random variables. The non-random variables are the slot in which the enchantment is offered and the number of bookshelves surrounding the enchantment table, and the random variables are integers uniformly distributed between zero and the number of bookshelves, zero and half the number of bookshelves (rounded up), and one and five. The three random variables are added together, and multiplied by a factor of 0.5, 0.66 or 1.0, depending on whether the enchantment is being offered in the top, middle or bottom slot.

This means that with 30 bookshelves around the enchantment table, the maximum level that can be offered in each slot is 25, 33 and 50 respectively. In other words, an enchantment of level 34 or above can only appear in the bottom slot. However, it is possible for a level 1 enchantment to be offered in any of the three slots.

Because of this, the distribution of the enchantment levels offered is skewed significantly toward the lower levels, with the first, second, third, and fourth groups of 10 levels appearing on average 8.0, 18.2, 9.3, and 3.4 times more often than the fifth group of 10 levels for 30 bookshelves.

The resulting probability distributions for the bottom slot are shown in Figure 1 below. For clarity, the numbers of bookshelves for which the graph is plotted match the combinations available using Etho's piston mechanism for the variable bookshelf enchanting room (built in episode episode 112 of his series.

Figure 1: Distribution of enchantment levels appearing in the bottom slot

The likelihood of being offered a level 50 enchantment is 0.04%, which means that the expected value for the number of attempts required to obtain this is 2 480. At two attempts per second, this means that it would take on average, over 20 minutes of clicking to get a level 50 enchantment. However, with some considerable luck (and faster clicking) this time could be much shorter.

Since the enchantment levels offered in the middle and top slots favour the same distribution, albeit squashed on the horizontal axis, it is apparent that lower level enchantments are much more likely to show up. For example, with 30 book shelves, a level 17 enchantment is the easiest to obtain. Obtaining an enchantment of exactly level 17 is likely to be quicker than obtaining an enchantment of any level from 38 to 50 (requiring on average 6.4 attempts, as opposed to 7.4 attempts).

This sort of behaviour will be familiar to all players who make use of higher enchantments. What is more useful is to use the distributions to calculate the optimum number of bookshelves to maximise the probability of being offered an enchantment of a specific level. This is quite easy to do, and the results are shown in Table 1. Oscillations in the distributions of the top and middle slots are caused by the rounding error after multiplying by the slot factor, and these play a small but important role in the calculation (for an example, level 14 is most easily obtained with 22 bookshelves, while level 15 requires just 21).

Table 1: Optimum number of bookshelves for specific enchantment levels.

Level Bookshelves
2 and below 0
3 1
4 3
5 5
6 7
7 9
8 11
9 12
10 14
11 15
12 18
13 19
14 22
15 21
16 26
17 25
18 27
19 and up 30

This phenomenon is not present when using Etho's variable bookshelf design. In this case, the optimum number of bookshelves to use is 2 for levels 4 and below, 9 for levels 5 to 8, 16 for levels 9 to 12, 23 for levels 13 to 17, and 30 for levels 18 and above.

If you enjoyed this post, then don't forget to like, tweet, +1, or upvote on reddit. If you have any questions, comments or complaints, post them using the form below.
. . . . . . . . . . . . . . . . . . . . . . . .

Monday, December 12, 2011

On the Imminent Loss of the Ultimate Kitchen Instrument

[A picture stolen from ebay.co.uk]
Growing up, I always took the set of Tullen Shears (pictured right) mounted on our kitchen wall for granted. They could (and did) cut through almost anything, and I simply assumed that everyone had a pair. Unfortunately, over the last couple of years or so, they have been getting progressively less sharp. This is not that surprising, considering what they have had to cut through in their almost 29 year life: virtually everything, including plastic, cardboard, tin cans, chicken bones, a couple of pairs of sunglasses, and a glass window pane. Ironically, the one thing that it could never make a clean cut through was paper.

While the shears still work, they don't cut through some things (like plastic) quite as neatly as they once did, so we have been looking for a replacement pair for a while now. This has unfortunately been unsuccessful. After turning to the great power of the internet for an answer, we found (with some digging, in a forum dated five years ago, from someone claiming to be the daughter of the inventor of the shears) that Tullen New Zealand was sold to an English company in the late 1980s and they stopped making the shears shortly thereafter.

At first I was surprised that no one had ever seen the gap in the market and come up with shears that could match those once made by Tullen, but gradually it began to make sense to me. Those who have never heard of Tullen Shears do not know that such an incredible instrument is possible, and those that do know about them still have a working pair.

If you enjoyed this post, then don't forget to like, tweet, +1, or upvote on reddit. If you have any questions, comments or complaints, post them using the form below.
. . . . . . . . . . . . . . . . . . . . . . . .

Sunday, December 4, 2011

On Irrational Driving Part 1: Only Accelerating on the Downhills

There seems to be a growing trend for drivers to apply non-optimal behaviour to their driving techniques. I do understand that I tend to analyse things a bit more in depth than the average person, but there are certain facts that seem obvious to me. One of those facts is that it is more economical (not to mention less frustrating for other drivers on the road) to maintain a constant speed while driving along a straight road. Despite this, some drivers tend to enjoy accelerating the car to its top speed on the downhill sections of the road, and then let the car's momentum carry it up the following uphill at a much slower speed. This is a horribly inefficient way of driving, and I am going to attempt to explain why now.

In a very simplified consideration of a car, kinetic energy (or speed) is gained primarily from two sources, and mostly lost in two ways. The car gets extra kinetic energy by burning fuel, or by losing altitude. That is, if the car starts at the top of a hill, then without burning any fuel, it can start moving, simply because it is on a downward slope. The car loses energy to aerodynamic drag (and friction and a bunch of other things, but at fast speeds, drag is the most important), and by gaining altitude. A car slows down much quicker on an uphill than on a flat road. These things are obvious to most drivers, I hope.

The general idea for maintaining a constant speed is to balance the energy you gain from going down the slope with the energy from burning fuel. That is, you ease off on the accelerator on the downhills, and accelerate harder on the uphills.

On to the irrational behaviour. Some drivers, for some reason, like to put all the energy into the car at once, i.e. accelerate only on the downhills. It is very simple to show why this doesn't work.

Consider a road that consists of a 50/50 distribution of uphill and downhill slopes of equal gradient. Now consider two drivers: one who goes as fast as he can on the downhills, say 120 km/h, but then goes much slower on the uphills, say 80 km/h; and a second who maintains a constant speed of 96 km/h. We will assume that the uphill and downhill stretches are relatively long, and that the first car changes speeds quickly (so that we can neglect the time spent accelerating and decelerating). The advantage of these numbers is that for a journey of say, 6 km (which I chose for the round numbers it gives), both cars will take exactly the same time to reach the destination, that is 125 seconds. We will also assume that there are equal numbers of up and downhills, so that the starting point and destination are at the same altitude - this just makes the calculations a bit simpler.

The difference comes into the power that the cars lose through aerodynamic drag, since this power lost is proportional to the cube of the velocity (that is, a car doing twice the speed will lose eight times the power to aerodynamic drag). So while the drag of the first car is 30.6% lower on the uphills than that of the second car, it is 56.3% higher on the uphills. The result of this extra drag is that the first car loses 12.8% more energy to drag than the second car.

Since a specific quantity of fuel will release a specific amount of energy when it is burnt in the engine, this means that the car that accelerates hardest on the downhills will need to burn 12.8% more fuel throughout the journey.

So to sum up, a car that accelerates to 120 km/h on downhills but only does 80km/h on the uphills will use 13% more fuel than a car that holds a constant 96km/h, but arrive at it's destination at exactly the same time.

If you enjoyed this post, then don't forget to like, tweet, +1, or upvote on reddit. If you have any questions, comments or complaints, post them using the form below.
. . . . . . . . . . . . . . . . . . . . . . . .

Thursday, December 1, 2011

On NaNoWriMo Part IV: Type IV

Even though I did not finish, I would call National Novel Writing Month 2011 a success from my point of view. I managed to write over 16 days in November, and put out 22 186 words (or 44% of the novel's minimum length) - my contribution to the more than three billion words written worldwide. This is a big increase over NaNoWriMo 2010, during which I managed to write a total of 4 607 words.

Unfortunately, I won't be giving you a full novel, because I have decided over the course of the next few months, I will be finishing it. It will be released as a free e-book under a Creative Commons license as soon as it is finished (and hopefully proof read and edited too).

The novel, is titled Type IV(Working Title) is set in a world very similar to the world inhabited by Ashley of last year's novel, and Sarieth of this blog's opening post. It is a world that may or may not be our own, long after a technological civilisation, which may or may not be us, has fallen and receded. The story centres on our descendants who are living in and around the ruins of ancient cities. The story centres on two characters.

Amser is an extremely gifted girl who is obsessed with discovering things. Although the sciences of the ancients are long since forgotten in the isolated city in which she was born and raised, she is a genius when it comes to inventing. Her true gift however, is chemistry. Through a childhood of trials and experiments, she has learned how to create a vast range of mixtures and chemicals that can perform a whole range of apparently magical functions. These lead her to discover ways to temporarily restore books left behind by the ancients, and she explores the world, absorbing knowledge, and applying it where she can.

Llyr, aka Pedran, aka Elhaearn, is a man who is being hunted by the Company - a corrupt private law enforcement agency that has the entire country under its terrifying rule, much like the rule of Llyr's father (self-appointed lord of the city of Pyr, notorious pirate and marauder, and insidious conman) had once had over those very same people. Hunted in exile, he is searching for these mysterious creatures that have been prophesied to be the ones to bring freedom from tyrannous rule to his country. Funnily enough, he finds that these creatures have a very strange connection with the foreign girl, Amser.

Anyway, here's a short extract:

“This guy saved our lives back there. Don’t they have names?” he asked.

Amser shrugged. “Not really. I’m not good with names. I call that one Type I,” she said, pointing to the smaller of the bird-creatures upon whose back Llyr was now sitting. “I call this one here Type IV.”

“In that case, I’m going to call this one Sion. Strong name. Means ’saviour’.”

Amser laughed. “I’m sticking with Type IV. Accurate name. Means the fourth combination of ingredients that worked.”

And then because I have the habit of graphing things (more for show than for actual information),

And of course, since I promised you at least part of a novel, you can have a prologue.

Prologue: The Girl Who Explored

CAREFULLY, using a sharp, flat piece of metal, the girl pried the small square concrete slab out of place. Once it was loose, she began to lift it, ever so slowly, keeping it absolutely straight. As soon as it was clear of the slabs around it, she tossed it through the battered doorway where it joined a pile of other identical slabs. The girl let out a sigh of relief. The faint rust outline of a key was just visible on the coarse cement base beneath. She removed a thin square of paper from a wooden box she had taken out of her coat pocket and placed it over the outline. From a small glass bottle in the box, she poured a clear pungent chemical over the paper and then blew over it. The red outline of the key was gradually drawn through the paper. She mixed two more chemicals from the box in a small vial and poured the silver mixture into the area within the outline. Within seconds, it was glowing red hot, the paper curling in the heat. The girl was ready with a bottle of water as soon as the paper caught alight. Once the billowing steam had cleared, she lifted a rough key from the floor. After quickly filing the burs from the key, she placed it in a pocket of her coat, together with her wooden box, and after a nervous glance at the window, hurried out of the room.

Several hours later, she was several stories underground at the bottom of a narrow and broken flight of concrete stairs that had apparently been ineffectually repaired with wooden planks a number of times in their long history. Panting from moving some of the concrete slabs from the rooms above all the way down to bridge missing steps, she began to search her pockets.

She quickly found what she was looking for. She removed two small vials, one containing a clear transparent liquid, and the other containing a thick orange gel. She rubbed a small bead of the gel over her left hand, and then allowed a tiny drop of the liquid to spill over it. She closed her eyes as the combination erupted into blinding blue flames, engulfing her entire hand. The flames resided in an instant, leaving just a glowing blue aura around her hand which cast a faint but sufficient light several metres around her.

She was standing in a narrow stone passageway. The floor was slippery with moss, and the thick smell of damp hung in the air. She slowly advanced along the passageway. Every now and then, at somewhat irregular intervals, passageways identical to the one she was in would branch off to her left or right. Most of these she ignored, but every now and then, she would turn down one. After half an hour, the light emitted by her hand was no longer bright enough to show the path in front of her. She rubbed some more of the orange gel over her hand, and the light was restored.

Eventually, she approached a thick steel door. Here, the damp heavy air at the entrance had given way to a much dryer thin atmosphere. A thick layer of dust coated the floor and was thrown up by her feet as she passed. She stopped several meters away from the door, pulled a cloth over her nose and mouth, and moving very slowly, she pulled a small spray bottle from one of her pockets and began spraying a fine mist into the air. She waited while the dust settled, taking shallow breaths and exhaling very slowly. When the air was clear again, she moved forward, the dust remaining undisturbed bar a few faint foot prints.

When she reached the door, she examined it for several minutes. Finally, she fired a short burst of the mist from her spray bottle into the key hole, and then immediately blew into the lock. Out came her wooden box again --- this time so that she could take out a small bottle with a brush in the lid. She took out the key and painted over it with a thick red-grey grease. Slowly but forcefully, she slid the key into the lock, listening for each click as either the key or the catch in the lock gave way and sprang back into place. Once the key was fully in the lock, she sprayed it with a new bottle, this one containing a transparent fluid with a soft acrid smell which slowly ran out of the lock. She searched a coat pocket hurriedly for something, cursing under her breath when she couldn't find it. She eventually found what she was looking for in another pocket --- a small silver-grey rectangular stone. She held it a few inches away from the lock, and the fluid, stained slightly brown from grease, flowed towards the stone. She slowly moved the stone in a circular motion, spiralling first clockwise, and later reversing the direction. Once she had been round several times, she turned the key in the lock. With a loud grinding noise, the lock eventually turned. With a loud clang, the door was unlocked.

With no shortage of resistance, and a deafening squeal of resistance from the long neglected hinges, she finally got the door open. She quickly moved into the room and pushed the door shut behind her. A smile slid across her face as she walked across the floor. The rough concrete roof was only just higher than her head, and lined with cables with long perished white rubber insulation. Every few meters, bare glass bulbs dangled from the ceiling, and where they were missing, shattered shards lay on the ground. The room extended further than she could make out and was filled with rows and rows of crude metal shelves, many of which had buckled under the weight of books they had held for centuries.

She made her way to the centre of the room, taking care not to disturb anything. Where a shelf had collapsed, or books had fallen, she changed rows to pass them, rather than disturb the fallen heap.

When she reached the room's centre, she took off the large tanks that she had strapped to her back and placed them on the floor. She untied a small mask that was attached to the one and fastened it across her face. She opened the valves on the two tanks, first on the one her mask was connected to, and then the other. A thick yellow mist filled the room. As the gas filled the room, she began to lift books of their shelves seemingly at random, spraying the liquid she had used earlier to settle the dust. Turning the rigid pages one by one, she began to read...

If you enjoyed this post, then don't forget to like, tweet, +1, or upvote on reddit. If you have any questions, comments or complaints, post them using the form below.
. . . . . . . . . . . . . . . . . . . . . . . .