It has been more than one month from my last entry and almost two months from my last academic entry. What I've been done? Some learning and some researches though I can't say much about them here.

As the chance I come across with college mathematics decreases I hardly focus on them and find new topic about it to discuss. Instead I came across with distinct and wider field and as a result I write more of them in different manner. Project Euler and tenhou are sort of trials.

Sometimes I can't really concentrate on self-learning during vaccation but I'm still willing to write something about them.

All these indicates a shift in manner and field on the contexts I write, from academic stuffs from schools sublimating to further application or something research-worthy topic.

So, please look forward to my coming topics:

1) Completing the economy in virtual society.

2) Staired random walk. This occur natrually in some games/leagues, where the organizer is trying to avoid the match between two teams with too-large-ability difference. How is the distribution looks like? Are there any conversion between measurement in-game and the ability? They are supposed to be different if the player is in distinct stair.

3) More on finite difference and FFT --- a crossover between simple computational maths and complex alogarithms!

## Monday 17 December 2012

## Friday 26 October 2012

### Fantasica: money in virtual world

This is basically a extension based my last entry money market in virtual world.

As discussed last time the game that I recently playing, Fantasica has a very low demand on money and people trade using commodity or even work in a barter economy instead of using money. The phenomenon has raised my interest and we can investigate them a bit.

I. Advantage of commodity money over inconvertible money

In virtual world all money can be treated as just a simple statistic of a certain player, and you might say all of them are electronic money. To make our classification easier we treat the game like happening in the real world and using the terms "commodity money", "flat money", etc. We would refer the official currency of virtual world as inconertible money to produce a complete simulation.

Why people use commodity instead of money to trade? The instant advantage is that the commodity itself can be consumed whenever necessary, but if you hold inconvertible money it costs you a bit in buying necessary commodity (transaction cost). Of course, this reduces cost and simulates player's decision towards holding commodity instead of currency.

There's a pre-requisite for the system to work:

The commodity available, in terms of turnover/volume transacted should be highly homogenous. That is, most of the barter trading among goods involves the same commodity. Let's say the commodity traded very frequenctly be X. Under such condition the double-coincidence problem is loosened (because X is always preferred though not necessary the first choice as a medium of trade, or they always hold a demand on X). When players used to trade with X the demand on it eventually shift from a simple demand on a goods to a money demand --- they story wealth, as a standard of deferred payment, etc.

The pre-requsite discussed is pretty ridiculous in real world so in real world the history shifts from commodity money to inconvertible money. However in Fantasica this ridiculous condition is satisfied with the commodity 'Time Elixir' which eliminates the cooldown time between battle (having more battle earns you more). They can be bought with real currency and sometimes from quests. The cards trading are highly hetrogeneous but TE is very much dominating the transaction volume so it becomes the trading unit.

There's also an interesting point to note: even in real world, the commodity supply is not a constant. With expected nominal interest rate to increase people produce more (in short run), so MS in such a case is a upgoing slope instead of a vertical line.

As discussed last time the game that I recently playing, Fantasica has a very low demand on money and people trade using commodity or even work in a barter economy instead of using money. The phenomenon has raised my interest and we can investigate them a bit.

I. Advantage of commodity money over inconvertible money

In virtual world all money can be treated as just a simple statistic of a certain player, and you might say all of them are electronic money. To make our classification easier we treat the game like happening in the real world and using the terms "commodity money", "flat money", etc. We would refer the official currency of virtual world as inconertible money to produce a complete simulation.

Why people use commodity instead of money to trade? The instant advantage is that the commodity itself can be consumed whenever necessary, but if you hold inconvertible money it costs you a bit in buying necessary commodity (transaction cost). Of course, this reduces cost and simulates player's decision towards holding commodity instead of currency.

There's a pre-requisite for the system to work:

The commodity available, in terms of turnover/volume transacted should be highly homogenous. That is, most of the barter trading among goods involves the same commodity. Let's say the commodity traded very frequenctly be X. Under such condition the double-coincidence problem is loosened (because X is always preferred though not necessary the first choice as a medium of trade, or they always hold a demand on X). When players used to trade with X the demand on it eventually shift from a simple demand on a goods to a money demand --- they story wealth, as a standard of deferred payment, etc.

The pre-requsite discussed is pretty ridiculous in real world so in real world the history shifts from commodity money to inconvertible money. However in Fantasica this ridiculous condition is satisfied with the commodity 'Time Elixir' which eliminates the cooldown time between battle (having more battle earns you more). They can be bought with real currency and sometimes from quests. The cards trading are highly hetrogeneous but TE is very much dominating the transaction volume so it becomes the trading unit.

There's also an interesting point to note: even in real world, the commodity supply is not a constant. With expected nominal interest rate to increase people produce more (in short run), so MS in such a case is a upgoing slope instead of a vertical line.

## Wednesday 24 October 2012

### The money market in online games

Reference: my note on classical view of money

Recently I'm playing an android app called Fantasica, what interested me is not about the RPG system or something similar, but the trading system. Besides the basic trading unit (let's call it money), there are two commodities that requires money in the real world to acquire (may drop from quests occasionally as well). Interestingly the main transaction unit is the commodities instead of money, which violates the classical view of barter economy. How can this happen?

Before we solve the above problem just revise the problem that came up with barter economy:

1) Difficulty to quantitize its value because the value of a good is subjective, some goods like living things are hard to be divided

2) High transaction cost, low transacted quantity

3) Hard to meet double-coincidence of wants, that is, trader A wants trader B’s goods while trader B wants trader A’s goods. Also heterogeneity exist among goods, it may cause disagreement of the exchange.

4) No standard of deferred payment and low durability: goods depreciates time to time so the value of goods in future is less foreseeable.

Or course the transaction unit that we're interested does not construct a barter economy. They serves as medium of trade, standard of deferred statement, bla bla bla and it's a commodity money. However commodity money still contain some of the disadvantage stated above, like the difficulty in quantitizing its value.

And now what's the difference between virtual world's economy and that of in the real world?

Recently I'm playing an android app called Fantasica, what interested me is not about the RPG system or something similar, but the trading system. Besides the basic trading unit (let's call it money), there are two commodities that requires money in the real world to acquire (may drop from quests occasionally as well). Interestingly the main transaction unit is the commodities instead of money, which violates the classical view of barter economy. How can this happen?

Before we solve the above problem just revise the problem that came up with barter economy:

1) Difficulty to quantitize its value because the value of a good is subjective, some goods like living things are hard to be divided

2) High transaction cost, low transacted quantity

3) Hard to meet double-coincidence of wants, that is, trader A wants trader B’s goods while trader B wants trader A’s goods. Also heterogeneity exist among goods, it may cause disagreement of the exchange.

4) No standard of deferred payment and low durability: goods depreciates time to time so the value of goods in future is less foreseeable.

Or course the transaction unit that we're interested does not construct a barter economy. They serves as medium of trade, standard of deferred statement, bla bla bla and it's a commodity money. However commodity money still contain some of the disadvantage stated above, like the difficulty in quantitizing its value.

And now what's the difference between virtual world's economy and that of in the real world?

## Monday 15 October 2012

### Counting in combinatorics I - Review in basic arithmetics

*Counting is the action of finding the number of elements of a finite set of objects.*

Counting is perhaps described as a pre-math skill, but is consistantly used in numerous higher fields, like linear algebra, abstract algebra, and especially combinatorics --- fitting the definition above, combinatorics emphasizes the sample spaces and targetted set. In other words, number of combinations is simply the number of elements in the targeted set.

I. the basic implication of counting

Back to what you've learnt in the kindergarden, we are turning a "situation" into a specific number, which is an elemental quantification process. If '+' is representing 'an' apple then we count '+++' --- 'an apple and an apple and an apple' --- to 3.

Sometimes we will use the concept of steps to conduct the counting --- we start from '+' which is 1, two '+'s left means 2 steps forward which is 2, and 3. The 'step approach' develops as the principle of addition in such given situations.

What can be called a suprise is that what we've learnt in kindergarden has a high coincidence with vigoruously defined arithemetic system, which relies on the Peano's arithmeitc axioms.

Another approach for counting is by defining specific finite numbers. Instead of saying '+++' is 'one more than one plus one' we 'define' it to be 'three' --- this is particular effective for finite numbers, as well as for pre-education as they don't have the concept of addition.

In a formal way to describe the above approach, we say the 'situations' (number of '+', apples, whatever) is mapped to a sequence {1,2,3,4,.....}, which is the natrual numbers.

Mapping between different spaces is one of the most important idea in mathematics: geometry (inversion), linear algebra (linear transformation), algebra (functions), statistics (distribution transformation), etc. And we use mapping again in counting.

More precisely, combinatorics, the extension of counting.

II. Principle of counting

This time I didn't aim to introduce so advanced tricks to compute hard combinatorical problem, but I'm trying to provide alternatiive views for counting-based college combinatorics problems.

How do we count?

With finite and 'small' set of elements we can count it by 'definition' of specific numbers like above, but for harder problems we need an aloairthm for it.

Denote the count of a set A be . (If you know some set theory this shouldn't be something new to you.)

The two basic principle:

*.*

__Principle of addition (in combinatorics):__Why? We start to count from A, starting from

__zero__: 0, 1, 2, .... up to |A|. We can also count B, starting from zero again: 0, 1, 2,... up to |B|. Now, if we start to count B after A --- starting from |A|, we have |A|, |A|+1, |A|+2,... up to |A| + |B| which is our answer.

Formally, as elements repetition will be counted with its multiplicity, we assume all elements are distinct, then which leads to the above result.

I have to point out that the concept of zero appears quite frequently which is different from the natrual number system elementally ruled by the peano's axioms. This is an interesting problem to think with: As natrual numbers are used since the pre-historic era but the concept of zero appears very lately (later than negative numbers and fractions), why the concept of zero is so elemental in modern society? One of the reason is probably about the number bases creates a 'nothing' in a certain digit but the overall number represents something --- in ancient times they uses a blank to represent 'nothing' for that digit but that looks so odd and the concept of zero eventually appears.

*Definition.*We can 'multiply' sets (formally called cartesian product): If where A, B are sets, then C is also a set which includes:

*Example.*Denote the result of the first toss of a coin be and that for the second coin be the same. The result of tossing two coins is given by .

In basic arithmetic, multiplication is only a 'repetition' or 'short form' of addition (similarly, power or factorial is only a 'repetition' or 'short form' of multiplication.

Here's quite a famous quote from

*master rigorist*, Landau's

*Foundation of Analysis*:

'

*The preface for student...*

*4. The multiplication table will not occur in this book, not even the following theorem:*

*2*2 = 4*

*but I would recommend, as an exercise, define:*

*2 = 1+1*

*4 = ((1+1)+1)+1*

*then prove the theorem as an exercise...*

*The preface for scholar...*

*...I hope that I've written this book in such a way that a normal student can read it in two days. And then (since he already knows the formal rules from school) he may forget its contents.*"

(Interested reader should try to prove the above statement.)

Multiplication is not a necessary in arithmetic because there is addition. Similarly we transform the expression of multiplication into the basic way (addition) and our counting would work.

*.*

__Principle of multiplication (in combinatorics):__What does it imply? If A and B are sets with some elements, and C is the set of choice to choose one from A and one from B, then the resulting count is given by |A x B|.

Proof: left as exerise --- if you have no idea try to prove the theorem that Landau stated.

Up to now it seems that we are simply repeating what we're taught in schools, but starting from the basic, magic will happen soon.

## Friday 5 October 2012

### The journey of Tenhou

Considering that I recognize appropiate tactics since like a month ago (with 200 plays already accumulated), the recent result sounds really good here. Different from the Canton style or Taiwan style, the result from Japanese mahjong is accounted every 2 'rounds', the points calculation and yaku patterns promotes the defensive tactics to a very large extent. Like many sports, somehow you need some luck to allow you to score in the offending side, but defending is more about determination, alertness, calculation and skill, and most people treat the Japanese styled mahjong with the highest technical level about different styles of mahjong.

Raising the rank is quite time-consuming but sometimes through playing against the public you can really know your ability throughly.

Well... it's hard to talk about them in English...

I don't think I'm good enough to deal with tactics systemetically yet, but there's one point I would like to stress with:

As an echo with the passage I written about, different games has their own index of dependence on luck and randomness, but as long as they're not completely random (an example for completely random game would be the jackpot 777 machines in casino... that's why you should never play in casino but you'll always lose as your skill isn't helping you.), through a large enough number of plays the confidence interval of ability to play can stil be distingusihable among different players. Some of the games doesn't allow a large number of plays (at least at the competition level) but mahjong isn't one of them. Through a large number of play we can have a series of statistics to deal with. One of the most significant statistic is the percentage of ranking. In a 3 -players mahjong assuming complete randomness the expected result should be like :

1: 0.333, 2: 0.333, 3: 0.333

However, as you can see above the percentage of ranking really differs quite a lot. In private multiplayer room my percentage of 1st rank is almost 50% with a large enough plays (300). If you have studied some basic statistics you will know that a hypothesis testing --- chi square test here. You can actually work out yourself, but the about statistics is showing evidence that tactics is significant to your ranking.

Despite the statistical arguement, we can also use 'existance' to support our arguement inversely. As most players know, the overall ranking depends on the pts, and sometimes the pts you lose for 3rd is more than you earn per 1st. That is, to raise your rank you have to get 1st more than 3rd in a certain ratio --- under a completely random system this is possible but the iteration expectation length is much much longer than the entire situation. Mathematically if a point start at 0 at t = 0 and when t goes by 1 unit, the point goes left or right randomly. Then at t = k the expected maximum distance from origin is 1/sqrt(k). Similarly here: If you are going to get a net +10 ratio you expect to have 100 plays; but when the ratio of 1st:3rd is 4:3 (for most cases), the net difference required increases as number of games increases, and as a result the games required increases dramatically.

You can try this from the following Python code:

from random import random

def randomwalk(netdiff=10,trial=20,plus=1,minus=-1):

for i in range(trial):

x = 0

count = 0

while x < limit:

a = random()

if a < 0.5:

x += plus

else:

x += minus

count += 1

print count

randomwalk()

Now, try randomwalk(10,20,1,-4.0/3)? What will happen?

It shows that it's nearly impossible to raise the rank under completely random system, and that's why we need tactics, we need to defense to avoid getting the third, and this is how 'gambling' stuffs can be 'scientific'.

There are far more stuffs in mahjong involves statistical analysis or even probability calculation, and I think more of them will come soon.

Raising the rank is quite time-consuming but sometimes through playing against the public you can really know your ability throughly.

Well... it's hard to talk about them in English...

I don't think I'm good enough to deal with tactics systemetically yet, but there's one point I would like to stress with:

As an echo with the passage I written about, different games has their own index of dependence on luck and randomness, but as long as they're not completely random (an example for completely random game would be the jackpot 777 machines in casino... that's why you should never play in casino but you'll always lose as your skill isn't helping you.), through a large enough number of plays the confidence interval of ability to play can stil be distingusihable among different players. Some of the games doesn't allow a large number of plays (at least at the competition level) but mahjong isn't one of them. Through a large number of play we can have a series of statistics to deal with. One of the most significant statistic is the percentage of ranking. In a 3 -players mahjong assuming complete randomness the expected result should be like :

1: 0.333, 2: 0.333, 3: 0.333

However, as you can see above the percentage of ranking really differs quite a lot. In private multiplayer room my percentage of 1st rank is almost 50% with a large enough plays (300). If you have studied some basic statistics you will know that a hypothesis testing --- chi square test here. You can actually work out yourself, but the about statistics is showing evidence that tactics is significant to your ranking.

Despite the statistical arguement, we can also use 'existance' to support our arguement inversely. As most players know, the overall ranking depends on the pts, and sometimes the pts you lose for 3rd is more than you earn per 1st. That is, to raise your rank you have to get 1st more than 3rd in a certain ratio --- under a completely random system this is possible but the iteration expectation length is much much longer than the entire situation. Mathematically if a point start at 0 at t = 0 and when t goes by 1 unit, the point goes left or right randomly. Then at t = k the expected maximum distance from origin is 1/sqrt(k). Similarly here: If you are going to get a net +10 ratio you expect to have 100 plays; but when the ratio of 1st:3rd is 4:3 (for most cases), the net difference required increases as number of games increases, and as a result the games required increases dramatically.

You can try this from the following Python code:

from random import random

def randomwalk(netdiff=10,trial=20,plus=1,minus=-1):

for i in range(trial):

x = 0

count = 0

while x

if a < 0.5:

x += plus

else:

x += minus

count += 1

print count

randomwalk()

Now, try randomwalk(10,20,1,-4.0/3)? What will happen?

It shows that it's nearly impossible to raise the rank under completely random system, and that's why we need tactics, we need to defense to avoid getting the third, and this is how 'gambling' stuffs can be 'scientific'.

There are far more stuffs in mahjong involves statistical analysis or even probability calculation, and I think more of them will come soon.

## Friday 7 September 2012

### Operator precedence

Alright, this is my first passage lablled with "coding" although there have been a few MATLAB passage already.

As you can see from the right-hand side of the blog, there's a new label associated with Project Euler -- fun programming and maths challenge and you guys could hv a go for it.

I'm not going to write a long one like I did before, and I'm just going to share a few thoughts about the problem, problem 093 from Project Euler.

And I'm serious: don't copy my code to find the answer. It rips your satisfaction and chance to learn in solving the problem.

The question is: using + - * / () and 4 numbers, we can combine them to give a series of number. For example the number 1 2 3 4 can form 36 numbers. However only 1 ~ 28 are form consecutively, while 29 can't be done. Find 4 number so that the longest chain of number from 1 to n can be formed.

It's hard to list out all possible operations, so are there any methods to kill this problem? The idea here is: there are 3 "main operator" (+ - * /) in the formula, while the bracket change the order of calculation, so we have to find a way to substitute the precedence of calculation.

One should notice that this idea has a high overlapping with the simple programming:

a = 1

a += 1

a *= 2

print a

This gives (1+1)*2 = 4, not 1+1*2 = 3, however we don't even employ bracket there. The point is: when we assign the order of calculation,

When we write a program that calculates step by step, like:

a = 520

a += 2

a *= 17

a += -34

a *= (1/17)

print a

It's equivalent to ((((520+2)*17)-34)*1/17)

However there is a problem. Observing the above bracket array you can notice that the brackets are one in another and the big one includes all.

define operator(a,b,n) #a,b: numbers to operate, n: operator id (+-*/)

xs = set()

define ord(n) #to find the longest chain

for permutations of possible (a,b,c,d):

for permutations of operator:

xs.add operator(a,operator(b(operator(c,d,i),j),k)

print longest chain's digit

In fact, one of the original version of the related problem does not use 1,2,3,4, but 4,4,4,4. By this program we also verify that 4 4's only gives a chain from 1 to 9.

There are several interesting question

1) When we change the questions to 5 or more numbers, how can we use recursion to deal with the question?

2) When we introduce square and square root as legal operator in the formula how can we deal with the problem? Assume square root and square can only use once on each number (i.e. we can't do x^2 ^2)

This is easy -- for each permutations, set another operator that permutes (1,2,3) to like (1,2,3), (1,2,9), (1,4,9), (1,4,9) and do the operator combinations.

And therefore here's a harder question for you: we allow factorial AND multiple factorials (Two implications: 1: (x!)!, e.g. (3!)! = 720, 2: x!!, please read wikipedia), how can be code this one?

3) In one of the forum I hold before, there's a post asking people to combine seven 4's to form number chains from 1 to n. + - x / () ! multiple !, square, square root are permitted. How long is the chain? I can tell you that the answer exceeds 1000 by manual trials.

As you can see from the right-hand side of the blog, there's a new label associated with Project Euler -- fun programming and maths challenge and you guys could hv a go for it.

I'm not going to write a long one like I did before, and I'm just going to share a few thoughts about the problem, problem 093 from Project Euler.

And I'm serious: don't copy my code to find the answer. It rips your satisfaction and chance to learn in solving the problem.

The question is: using + - * / () and 4 numbers, we can combine them to give a series of number. For example the number 1 2 3 4 can form 36 numbers. However only 1 ~ 28 are form consecutively, while 29 can't be done. Find 4 number so that the longest chain of number from 1 to n can be formed.

It's hard to list out all possible operations, so are there any methods to kill this problem? The idea here is: there are 3 "main operator" (+ - * /) in the formula, while the bracket change the order of calculation, so we have to find a way to substitute the precedence of calculation.

One should notice that this idea has a high overlapping with the simple programming:

a = 1

a += 1

a *= 2

print a

This gives (1+1)*2 = 4, not 1+1*2 = 3, however we don't even employ bracket there. The point is: when we assign the order of calculation,

**an array of bracket**appears natrually in the calculation.When we write a program that calculates step by step, like:

a = 520

a += 2

a *= 17

a += -34

a *= (1/17)

print a

It's equivalent to ((((520+2)*17)-34)*1/17)

However there is a problem. Observing the above bracket array you can notice that the brackets are one in another and the big one includes all.

**There are no separate pair of brackets.**To solve this one we need extra method like recursion, but for 4 numbers the only exception is (a+b)*(c+d) as well as (a+b)/(c+d). Let's write a pseudo code here:define operator(a,b,n) #a,b: numbers to operate, n: operator id (+-*/)

xs = set()

define ord(n) #to find the longest chain

for permutations of possible (a,b,c,d):

for permutations of operator:

xs.add operator(a,operator(b(operator(c,d,i),j),k)

print longest chain's digit

In fact, one of the original version of the related problem does not use 1,2,3,4, but 4,4,4,4. By this program we also verify that 4 4's only gives a chain from 1 to 9.

There are several interesting question

1) When we change the questions to 5 or more numbers, how can we use recursion to deal with the question?

2) When we introduce square and square root as legal operator in the formula how can we deal with the problem? Assume square root and square can only use once on each number (i.e. we can't do x^2 ^2)

This is easy -- for each permutations, set another operator that permutes (1,2,3) to like (1,2,3), (1,2,9), (1,4,9), (1,4,9) and do the operator combinations.

And therefore here's a harder question for you: we allow factorial AND multiple factorials (Two implications: 1: (x!)!, e.g. (3!)! = 720, 2: x!!, please read wikipedia), how can be code this one?

3) In one of the forum I hold before, there's a post asking people to combine seven 4's to form number chains from 1 to n. + - x / () ! multiple !, square, square root are permitted. How long is the chain? I can tell you that the answer exceeds 1000 by manual trials.

## Monday 13 August 2012

### An open problem, matlab and randomness II

Before we deal with the original problem again, let's deal with the following problem:

Given X as a uniform distribution from 0 to 1. What's the expected value of E(1/X)?

Recall the formula of E(X) for uniform distribution

When we extend the formula into continous distribution it becomes .

Firstly we have .

Now how can we get the probability distribution for ?

Consider the following, let a and b be numbers within

Now take the inverse, let the inverse of X be Y:

. It's hard to deal with the integral form, but consider the probability density function with limits. Applying idea from calculus, which is FToC II (Fundamental Theorem of Calculus).

Given X as a uniform distribution from 0 to 1. What's the expected value of E(1/X)?

Recall the formula of E(X) for uniform distribution

When we extend the formula into continous distribution it becomes .

Firstly we have .

Now how can we get the probability distribution for ?

Consider the following, let a and b be numbers within

Now take the inverse, let the inverse of X be Y:

. It's hard to deal with the integral form, but consider the probability density function with limits. Applying idea from calculus, which is FToC II (Fundamental Theorem of Calculus).

## Friday 3 August 2012

### An open problem, matlab and randomness

Just sharing a question that I've done recently, and that actually recalls something that I intend to write some times before but gave up very soon.

Now consider a hypothetical cat and a mouse on a circle chasing each other.

1) Cat's speed is random from -2 to 2 (-ve = anti-clockwise)

2) Mouse's speed is i) fixed at 1 ii) random within a certain range.

3) The cat "catches" the mouse if the cat "catches" the mouse or the mouse "catches" the cat.

4) The mouse starts at random position of circle (radius 2) while cat starts at x=0.

And let's deal with the matlab code...

-------------

clear

vm=zeros(401,1000)+1; %vm = speed of mouse, we are generating a matrix here in case we will use random speed later

d=rand(401,1000)*4*pi %random position of mouse

A=zeros(401,1000);

for I=1:401

vc=(I-201)/100;

for J=1:1000

if vc > vm(I,J)

A(I,J)=abs(vc*d(I,J)/(vc-vm(I,J));

else

A(I,J)=abs(vc*(4*pi-d(I,J))/(vc-vm(I,J));

end

end

end

for I=1:201

y(I)=(mean(A(200+I,:))+mean(A(202-I,:)))/2;

end

%direction of cat is the not our concern (though it behaves differently)

y(101)=(y(100)+y(102))/2;

%If vc=vm the cat never catches the mouse and by default distance travelled = 0 is not our interest, so delete that entry and smooth the curve.

x=0:0.01:2;

plot(x,y)

----------

Output:

(In fact I'm not using y(101) as the mean of y(100) and y(102) here because it's supposed to tend to infinity and hence it's not the mean of the neighbouring terms.)

What can you observe? A significant peak like the IR spectrometry or something else? Even though we are generating randomness, this is pretty much an "expected" result --- let see what we can interpret here.

Now consider a hypothetical cat and a mouse on a circle chasing each other.

1) Cat's speed is random from -2 to 2 (-ve = anti-clockwise)

2) Mouse's speed is i) fixed at 1 ii) random within a certain range.

3) The cat "catches" the mouse if the cat "catches" the mouse or the mouse "catches" the cat.

4) The mouse starts at random position of circle (radius 2) while cat starts at x=0.

And let's deal with the matlab code...

-------------

clear

vm=zeros(401,1000)+1; %vm = speed of mouse, we are generating a matrix here in case we will use random speed later

d=rand(401,1000)*4*pi %random position of mouse

A=zeros(401,1000);

for I=1:401

vc=(I-201)/100;

for J=1:1000

if vc > vm(I,J)

A(I,J)=abs(vc*d(I,J)/(vc-vm(I,J));

else

A(I,J)=abs(vc*(4*pi-d(I,J))/(vc-vm(I,J));

end

end

end

for I=1:201

y(I)=(mean(A(200+I,:))+mean(A(202-I,:)))/2;

end

%direction of cat is the not our concern (though it behaves differently)

y(101)=(y(100)+y(102))/2;

%If vc=vm the cat never catches the mouse and by default distance travelled = 0 is not our interest, so delete that entry and smooth the curve.

x=0:0.01:2;

plot(x,y)

----------

Output:

What can you observe? A significant peak like the IR spectrometry or something else? Even though we are generating randomness, this is pretty much an "expected" result --- let see what we can interpret here.

## Saturday 28 July 2012

### Thought and theories on game development (IV) - musical games

Since when rhythmic games has been part of my life?

IIDX - since 1999; Taiko no tatjusin (TnT) - since 2001; some are invented more recently, like osu! (2008) (ok all of us know osu! is not the original inventor...), jubeat, project DIVA... What makes them attractive and what's the principle behind their development?

A primary factor of the games is about instrument simulation. Psychologically this is a compensation to players who does not use to play instruments well (I'm not offending those players). IIDX simulates drum kit while TnT simulates taiko which is a traditional instrument. When we play in the acrade machines we have to hit the real drums (TnT) or rub the disc (IIDX) which enhances the feeling that "I'm playing music". Inversely this is also how developer promotes their game using "authenticity" -- playing the game is like playing the instrumental itself.

IIDX - since 1999; Taiko no tatjusin (TnT) - since 2001; some are invented more recently, like osu! (2008) (ok all of us know osu! is not the original inventor...), jubeat, project DIVA... What makes them attractive and what's the principle behind their development?

A primary factor of the games is about instrument simulation. Psychologically this is a compensation to players who does not use to play instruments well (I'm not offending those players). IIDX simulates drum kit while TnT simulates taiko which is a traditional instrument. When we play in the acrade machines we have to hit the real drums (TnT) or rub the disc (IIDX) which enhances the feeling that "I'm playing music". Inversely this is also how developer promotes their game using "authenticity" -- playing the game is like playing the instrumental itself.

## Sunday 22 July 2012

### Thought and theories on game development (III) - walkthroughs

In most cases games are for relaxing and the achievement to complete the whole game. However sometimes players failed to completed a certain part of the game, or they are impatient to deal with the game, walkthrough appears upon demand. In this section we'll discuss how walkthrough is developed, and the reason behind these development.

With electronic game being more popular and more online interactions are promoted, walkthrough in fact develop in terms of how it spreads and also its content.

Back to 1990s internet / online games aren't mature enough, most games are solo PC games, or even not working on PC, instead an individual machine (e.g. tamagochi), and a more traditional ways of spreading message is adopted. Printed simple walkthroughs are circulated among players and this is the initial form of walkthroughs, and it hasn't been commercialized.

With electronic game being more popular and more online interactions are promoted, walkthrough in fact develop in terms of how it spreads and also its content.

Back to 1990s internet / online games aren't mature enough, most games are solo PC games, or even not working on PC, instead an individual machine (e.g. tamagochi), and a more traditional ways of spreading message is adopted. Printed simple walkthroughs are circulated among players and this is the initial form of walkthroughs, and it hasn't been commercialized.

## Saturday 14 July 2012

### Thoughts and theories on game development (II) - about chess and board games

Games are not necessarily electronic. There are many famous board games and chesses and they are popular and globally recognized. Now we are going to discuss a way to classify the games and relate them to popularity and other reality measurements.

Assume the player is at his/her best form. How can we access his/her performance and how do we measure his/her ability to play? There would be two part of measurement: techniques and luck.

Techniques is the major measurement on the ability of players, and it's a constant value in short term while luck is a random variable, and could be different in every game.

I must admit that the definition is far too simple and failed to deal with many cases, for example the ability to play varies case-by-case but let's make it as a general measurement. Luck should be totally random (all known factor should be excluded). Let's have some example here: when we play bridge, you're the declarer and you know nothing useful from opponent's bidding and leading, a simple finesse has 50% of successful rate and this is totally random and this is luck. However, "100%" approach like squeezing is not "luck" but techniques because the process that determines whether the game successful is not random, and the player is able to maximize the probability to win.Psychological operation on opponents would be somehow between techniques and luck because it has a chance to put a bigger pressure on the opponents but there's only a certain chance that the opponent is affected. For example, a large raise in texas poker which may mislead your opponents that you may have a very good hand.

Assume the player is at his/her best form. How can we access his/her performance and how do we measure his/her ability to play? There would be two part of measurement: techniques and luck.

Techniques is the major measurement on the ability of players, and it's a constant value in short term while luck is a random variable, and could be different in every game.

I must admit that the definition is far too simple and failed to deal with many cases, for example the ability to play varies case-by-case but let's make it as a general measurement. Luck should be totally random (all known factor should be excluded). Let's have some example here: when we play bridge, you're the declarer and you know nothing useful from opponent's bidding and leading, a simple finesse has 50% of successful rate and this is totally random and this is luck. However, "100%" approach like squeezing is not "luck" but techniques because the process that determines whether the game successful is not random, and the player is able to maximize the probability to win.Psychological operation on opponents would be somehow between techniques and luck because it has a chance to put a bigger pressure on the opponents but there's only a certain chance that the opponent is affected. For example, a large raise in texas poker which may mislead your opponents that you may have a very good hand.

## Thursday 12 July 2012

### Thoughts and theories on game development (I) - balance and variation

It seems that this is my first time posting nothing in the past 30 days...anyway here's another project or longer studies on game development. The topics listed below are a bit irrelevent each other, but they actually surround the consideration on the attractive force between players, game and developer.

Sometimes I'm simply too lazy to type stuffs in Chinese (in fact there's a passage about RPG systems in this blog in Chinese, typed several years ago), but using English won't affect how the systems be described.

1) Balance and variation on different games

2) Classifying card and chess games

3) Theories developed based on games: walkthroughs and techniques

4) Theories developed based on musical games

-----------------

Definition. A balanced game implies that in long term, when a player is repeatedly making decision based on similar choices given, his/her choices won't be skewed seriously, but making decision averagely on different choices available. Sometimes it may refer to the average of entire player population.

On another hand, variation is rather a "clear" concept, where more different elements, characters, items or story lines are given.

Notice that both criterion are closely related because the how the game decisions are balanced act as a "multiplier" on how the game can vary because what the game available isn't exactly what the player plays. In a very unbalanced situation, e.g. choosing a particular character makes the game easy to play while it's nearly impossible to play with the rest of the character, a large proportion (the rest of the players are usually refers to the challenger group mentioned later) of players will take the easy route and it greatly restricts how the game can perform.

Sometimes I'm simply too lazy to type stuffs in Chinese (in fact there's a passage about RPG systems in this blog in Chinese, typed several years ago), but using English won't affect how the systems be described.

1) Balance and variation on different games

2) Classifying card and chess games

3) Theories developed based on games: walkthroughs and techniques

4) Theories developed based on musical games

-----------------

Definition. A balanced game implies that in long term, when a player is repeatedly making decision based on similar choices given, his/her choices won't be skewed seriously, but making decision averagely on different choices available. Sometimes it may refer to the average of entire player population.

On another hand, variation is rather a "clear" concept, where more different elements, characters, items or story lines are given.

Notice that both criterion are closely related because the how the game decisions are balanced act as a "multiplier" on how the game can vary because what the game available isn't exactly what the player plays. In a very unbalanced situation, e.g. choosing a particular character makes the game easy to play while it's nearly impossible to play with the rest of the character, a large proportion (the rest of the players are usually refers to the challenger group mentioned later) of players will take the easy route and it greatly restricts how the game can perform.

## Saturday 9 June 2012

### Detecting cheaters --- a statistical approach (I): creating a measurement

Cheating is a basic problem occuring in digital game. The idea of cheating is based on the ability to change the statistics easily. In reality the statistics is based on matter (action can be regarded as movement of matter) in a specified period. For example, one of the statistics --- money --- in a narrow sense --- legal tender, is measured by the amount of matter that you own that is recognised as legal tender. You can't "create" a $100 note from nothing and the cost of producing one is far too high.

In digital game, statistics are represented by configurations of electrons only. You can simply change the level from 1 to 2 by 01 to 10. The electrons are so cheap and the cost of changing it is very low. In single player game they are very common, like the GBA or NDS simulator in which (value):(position) cheating code is not even hard for a non-programmer to process.

However it causes problems in multiplayer game. As long as cheating players aren't the only group of players in the game, fair play should be enhanced. (You have to admit that fair play is the basis of commercial activity based on the game in typical MMORPG unless the added-value services is unachieveable by cheating like the osu!supporter tag) Cheating raises the level of achievement to an unreachable level for manual players, and eventually they are despaired and leave the game.

Definition 1. Cheating is a process that makes benefit from approaches that is not permitted in a certain system.

And therefore, cheating should be stopped.

So how?

In fact I'm writting this for something happened in osu!, so I'll take osu! as example.

Quantification or an exact measurement on player's ability is needed. Sometimes it's very hard to determine one's ability especially in MMORPG because different occupation can have advantage on each other, or they have different position in battle team as a whole. We say that the capability of MMORPG character is not well-ordered. However in games that promotes extreme techniques, the power of a player can be easily revealed.

Definition 2. If the elements a_i in the set S is well-ordered, for a_i =/= a_j a > or < relation can be set up (search "definition of inequalities in this blog for further information about < and >) and the relation is transisive for all elements in the set. In reality we define a_i > a_j if there is a probability larger or equal to k that a_i plays better than a_j (trivially k > 0.5). For some reason we call it confidence constant first. If k = 1 they are absolutely well-ordered. Note that the "definition of well-ordered measurement in reality" is not properly well-ordered in mathematics.

The measurement of power of player should be clear and exact. Let S be the set of players and f is the mapping from players to measurement of power of player, then f: S -> R+ U {0} (non-negative real, and f(x)=0 if the player has no playing record). Considering the upper level of playing, assuming player plays enough many maps so that the overall power shows the ability to play all maps with different characteristic and difficult pattern. i.e., the measurement of power is not affected by the strength and weaknesses of players because they offset each other.

And now we go into some calculations.

In digital game, statistics are represented by configurations of electrons only. You can simply change the level from 1 to 2 by 01 to 10. The electrons are so cheap and the cost of changing it is very low. In single player game they are very common, like the GBA or NDS simulator in which (value):(position) cheating code is not even hard for a non-programmer to process.

However it causes problems in multiplayer game. As long as cheating players aren't the only group of players in the game, fair play should be enhanced. (You have to admit that fair play is the basis of commercial activity based on the game in typical MMORPG unless the added-value services is unachieveable by cheating like the osu!supporter tag) Cheating raises the level of achievement to an unreachable level for manual players, and eventually they are despaired and leave the game.

Definition 1. Cheating is a process that makes benefit from approaches that is not permitted in a certain system.

And therefore, cheating should be stopped.

So how?

In fact I'm writting this for something happened in osu!, so I'll take osu! as example.

Quantification or an exact measurement on player's ability is needed. Sometimes it's very hard to determine one's ability especially in MMORPG because different occupation can have advantage on each other, or they have different position in battle team as a whole. We say that the capability of MMORPG character is not well-ordered. However in games that promotes extreme techniques, the power of a player can be easily revealed.

Definition 2. If the elements a_i in the set S is well-ordered, for a_i =/= a_j a > or < relation can be set up (search "definition of inequalities in this blog for further information about < and >) and the relation is transisive for all elements in the set. In reality we define a_i > a_j if there is a probability larger or equal to k that a_i plays better than a_j (trivially k > 0.5). For some reason we call it confidence constant first. If k = 1 they are absolutely well-ordered. Note that the "definition of well-ordered measurement in reality" is not properly well-ordered in mathematics.

The measurement of power of player should be clear and exact. Let S be the set of players and f is the mapping from players to measurement of power of player, then f: S -> R+ U {0} (non-negative real, and f(x)=0 if the player has no playing record). Considering the upper level of playing, assuming player plays enough many maps so that the overall power shows the ability to play all maps with different characteristic and difficult pattern. i.e., the measurement of power is not affected by the strength and weaknesses of players because they offset each other.

And now we go into some calculations.

## Tuesday 29 May 2012

### Osu!: Taiko Mapping - drum breaks

Declaration: Taiko mapping is a place for creativity, existing no objective rules on good/bad map, and all to be discussed are individual opinion. Of course, comments are highly welcomed.

This is my first trial to write something on Taiko mapping --- in fact very difficult unless we take out a piece of music sheet can place each note corresponding to music, so I tried to take about some particular section instead.

What is a drum break? In a song full of instrumental (or vocal) sounds, we may found a section with no sound except a instrumental solo. It could be piano, drums, violin or whatever. That section can be stated as a transition, or a temporary period that takes auidences out of the original musical flow. And for the case of drums, it could be some stable 1/2 beats or a pure solo show-off.

The following youtube vid is from

In a taiko mapping environment of course you can't switch the instrument freely (and I personally object custom hitsounds even they are unique throughout the song because taiko is a simulation of taiko -- a tradtional japanese instrument -- and is unique.) so what you can do is switching the reference of mapping -- from a melody based approach to a semi-solo approach.

Sometimes I emphasize how the taiko fit with the song (song comes first because you used that song and you are not creating the song under entire taiko diff), and taiko diff shouldn't cover the song. With a strong melody flow taiko sound act as a nice assistant to the song, and in weaker part you process more variation and stream to the next section and that provides a more interesting diff rather than a fixed result from a song.

In vocaloid songs ABABCDAB approach is common. Assuming B is the chorus and that means you are pushing the pace to the climax at the third kiai time. C is typically instrumental, D is a slower vocal so a solo style on section C contrast to D and gradually a denser and stronger beat to B is one of the approach to produce an well-organized climax at the beginning of B (and difference should be shown comparing with the first two kiai in the final section, and their pitch sometimes rised. Example: Demetori - innumerable eyes (though this is not vocaloid but the section dividing is similar http://osu.ppy.sh/s/21480).

For IIDX or BMS songs they have a stronger beat throughout the song (because they are made for BMS games so beats are needed everywhere) so you might not have the chance to produce such a constrast, and we will discuss them later if possible. (Well, these songs already give enough chance for mapper to tweek the drum pattern a bit and deliver a solo-styled diff) Sometimes people always complain that following the song strictly is boring, but I don't really think so. A suitable choice of reference would be enough to give a nice diff without some intentional drum solo.

This is my first trial to write something on Taiko mapping --- in fact very difficult unless we take out a piece of music sheet can place each note corresponding to music, so I tried to take about some particular section instead.

What is a drum break? In a song full of instrumental (or vocal) sounds, we may found a section with no sound except a instrumental solo. It could be piano, drums, violin or whatever. That section can be stated as a transition, or a temporary period that takes auidences out of the original musical flow. And for the case of drums, it could be some stable 1/2 beats or a pure solo show-off.

The following youtube vid is from

*Go West*, a section where Chico plays the piano with apple. Around 1:00 you can see Chico making some beats instead of purely piano performance, and that is an impressive transition in the song.In a taiko mapping environment of course you can't switch the instrument freely (and I personally object custom hitsounds even they are unique throughout the song because taiko is a simulation of taiko -- a tradtional japanese instrument -- and is unique.) so what you can do is switching the reference of mapping -- from a melody based approach to a semi-solo approach.

Sometimes I emphasize how the taiko fit with the song (song comes first because you used that song and you are not creating the song under entire taiko diff), and taiko diff shouldn't cover the song. With a strong melody flow taiko sound act as a nice assistant to the song, and in weaker part you process more variation and stream to the next section and that provides a more interesting diff rather than a fixed result from a song.

In vocaloid songs ABABCDAB approach is common. Assuming B is the chorus and that means you are pushing the pace to the climax at the third kiai time. C is typically instrumental, D is a slower vocal so a solo style on section C contrast to D and gradually a denser and stronger beat to B is one of the approach to produce an well-organized climax at the beginning of B (and difference should be shown comparing with the first two kiai in the final section, and their pitch sometimes rised. Example: Demetori - innumerable eyes (though this is not vocaloid but the section dividing is similar http://osu.ppy.sh/s/21480).

For IIDX or BMS songs they have a stronger beat throughout the song (because they are made for BMS games so beats are needed everywhere) so you might not have the chance to produce such a constrast, and we will discuss them later if possible. (Well, these songs already give enough chance for mapper to tweek the drum pattern a bit and deliver a solo-styled diff) Sometimes people always complain that following the song strictly is boring, but I don't really think so. A suitable choice of reference would be enough to give a nice diff without some intentional drum solo.

## Saturday 19 May 2012

### Basics of integration. Part III. Ordinary Substitution

Again we start with differentiation.

Algebrically reading the equation it looks like "multiplying and divising the same thing to the entire function like rationalization and transforming complex number to standard form.

Apply chain rule to a composite function: . By chain rule we have If you are not sure about what the second term means, do a substitution u=f(x) and .

Now integrate both sides once: (notice that RHS can cancel out each other to give which clearly gives the term at LHS.)

We can transform the above equation to another common representation for easier reading .

**Example 1. (Chain rule)**Evaluate whereAlgebrically reading the equation it looks like "multiplying and divising the same thing to the entire function like rationalization and transforming complex number to standard form.

Apply chain rule to a composite function: . By chain rule we have If you are not sure about what the second term means, do a substitution u=f(x) and .

Now integrate both sides once: (notice that RHS can cancel out each other to give which clearly gives the term at LHS.)

We can transform the above equation to another common representation for easier reading .

**Theorem 1. Integration by substitution**.## Tuesday 15 May 2012

### M2: Algebra and geometry Part 2

When the rate of change considering the segment length is considered, one of the direct application is mechanical deduction. Differentiation build up a strong relationship between displacement, velocity and acceleration so differential equation would be useful here.

Locus of a certain point in coordinate geometry is a big topic in core/M2 mathematics, and it has significant applications, remarkably some pivot systems.

What I want to illustrate here is that, the differentiation operator has a very nice behavior that allows us to do questions in many ways. Denote |OB| = h.

Solution 1. Set up relation between x,y through h.

Obviously there are pairs of right angled triangle, hence and , then (since y is positive), then .

Solution 2. Implicit differentiation.

First we set up the explicit relation and . By differentiating w.r.t. t, , and do the same thing to to get .

Now

Therefore . Note that we can multiply both sides by dt/dx, and eliminate the terms dt by chain rule.

Solution 3. Differentation through angle.

Let angle BAC be . Then , , . Now , .

The same question can be solved by different approaches, and that's the art of problem solving.

Locus of a certain point in coordinate geometry is a big topic in core/M2 mathematics, and it has significant applications, remarkably some pivot systems.

**Example 3a. (Locus on linear system)**Let A, B and C be 3 points on positive x-axis, positive x-axis and negative x-axis respectively. AB = 5, BC = 7. Let |OA| = x, |OC| = y, find dy/dx.What I want to illustrate here is that, the differentiation operator has a very nice behavior that allows us to do questions in many ways. Denote |OB| = h.

Solution 1. Set up relation between x,y through h.

Obviously there are pairs of right angled triangle, hence and , then (since y is positive), then .

Solution 2. Implicit differentiation.

First we set up the explicit relation and . By differentiating w.r.t. t, , and do the same thing to to get .

Now

Therefore . Note that we can multiply both sides by dt/dx, and eliminate the terms dt by chain rule.

Solution 3. Differentation through angle.

Let angle BAC be . Then , , . Now , .

The same question can be solved by different approaches, and that's the art of problem solving.

## Friday 11 May 2012

### M2: Algebra and geometry Part 1

In HKCEE A-maths or HKDSE M2 paper, the topic "rate of change" as the application of differentiation always appear in the paper and sometimes it has been modelled into a geometric question like the velocity of a certain position of a pivot. What I want to illustrate is that geometric question can be modelled into a algebra question in many ways like vectors, coordinate geometry, and this time we can deal with calculus.

With the assistance of trigonometry we built up a strong relationship between segment lengths and angles, allowing us to relate different quantity, then the rate of change of a certain quantity can be transformed easily. We will demonstrate four questions, one unrelated to calculus, one A-math, one M2 and one Tokyo U questions, showing that differentiation can deal with meaningful conclusion instead of simply finding some derivatives.

Recall: Sine law and Cosine law.

Define be the area of the triangle ABC.

Now notice that

Since it is right angled triangle, , and therefore

Comparing with the x-y-z approach of incircle (Fact: AF = AG, CF = CE, BG = BE due to tangent properties or congruent triangle.) this is completed in a more algebrical way. (Using the x-y-z approach requires a cartesian plane which the right angled properties is shown in a geometrical simulation, but in this approach it is shown in a algebrical way).

With the assistance of trigonometry we built up a strong relationship between segment lengths and angles, allowing us to relate different quantity, then the rate of change of a certain quantity can be transformed easily. We will demonstrate four questions, one unrelated to calculus, one A-math, one M2 and one Tokyo U questions, showing that differentiation can deal with meaningful conclusion instead of simply finding some derivatives.

Recall: Sine law and Cosine law.

**Theorem. (Sine Law)****Theorem. (Cosine Law)****Question 1. (Incircle)**Let a,b,c be three sides of right-angled triangle ABC where c is the hyp. side. Show the incircle radiusDefine be the area of the triangle ABC.

Now notice that

Since it is right angled triangle, , and therefore

Comparing with the x-y-z approach of incircle (Fact: AF = AG, CF = CE, BG = BE due to tangent properties or congruent triangle.) this is completed in a more algebrical way. (Using the x-y-z approach requires a cartesian plane which the right angled properties is shown in a geometrical simulation, but in this approach it is shown in a algebrical way).

Subscribe to:
Posts (Atom)