Wednesday, December 26, 2012

Reading Capital Politically, Part 3

This blog entry contains the final set of quotes from Reading Capital Politically. These quotes are generally concerned with the money-form of value. Overall, a very quotable book, it would seem.
We can see now that just as the relative value form finds its meaning only in the equivalent form so it is that the working class recognizes itself as working class only through its relation to capital. Indeed, it is working class only within that relation. The relative form thus expresses the perspective of the working class. Destroy capital and there is no more working class as such. And, conversely, the refusal to function as working class (i.e., to work) acts to destroy capital. Put in the language above, the mass of workers have their joint condition as working class reflected to them through capital acting as a mirror which mediates this recognition.

Children work for capital to the extent that they produce their labor-power for future roles as workers (waged and unwaged), but they are not directly waged. They, like housewives, are supported by the resources (money) obtained by their waged father or mother. The relation with capital is mediated directly for the father by the money wage, but for the children and housewives there is also the father/husband. In these circumstances the fact that children and women in the family work for capital is hidden by their condition of wagelessness. They appear to stand only in some private relation to the male wage earner but not to capital.

This was one of the main aims of colonialism - the creation of a world-wide reserve army. And poverty continues to be the tool by which vast millions are kept alive but (it is hoped) easily available when it suits capital's purpose. These reserves are then drawn upon either for immigration into areas where their cheap labor can be used to hold down the wage demands of more powerful workers (e.g., Mexican and Caribbean labor drawn into the U.S.; workers from Mediterranean countries brought into northern Europe) or for employment in their own areas when runaway shops seek out their cheap labor locally. Of course, time and again things have not worked out so well and the struggles of the unwaged have made them unfit for capital's factories.

Another way the class struggle refuses the mediation of money is the refusal of price. This is the essence of direct appropriation and includes not only the price of labor-power but also the prices of other commodities. It involves self-reduction of utilities or housing prices, changing labels in a supermarket, using 15-cent slugs instead of 50-cent tokens in the subway, or total elimination of price through shoplifting, employee theft, or Black Christmases where commodities are seized. This refusal of price is a refusal of capital's rules of the game. The refusal to accept the role of money is the refusal to accept everything we have seen going into the determination of money - the whole set of value relations. This is the working-class perspective with a vengence.

Inflation means rising prices due, not to increases in labor input, but to monetary deflation. Prices are the money equivalents of the value of commodities which are expressed in the price form. To raise prices means to increase the amount of money (gold or paper) being exchanged for goods. If the amount of money the working class holds is fixed, then the amount it can buy decreases accordingly. In this way, the amount of value the working class receives for its labor-power is reduced, and the amount of surplus value that capital gets is increased.

[...] it is easy to raise prices simply by circulating more paper so that a given quantity of commodities, being represented by an increased quantity of paper, has higher prices (assuming velocity of money constant, etc.). This was just the idea of Keynes, then Lewis and others. The state could print more money, or expand money via the credit system, and thus raise prices, which would decrease the value of each unit of money and thus undercut working-class wages. This undercutting could be done whether working-class wages were constant or increasing.

Thursday, December 20, 2012

The robots have (finally) arrived

The New York Times recently published an article with content and arguments straight out of the 1820s.

OMG! Robots are replacing labour-power! I cannot believe it. What are these new fantastical devices? Quoting Karl Marx, the NYT declares that you can make a profit by replacing people with robots:
In one example, a robotic manufacturing system initially cost $250,000 and replaced two machine operators, each earning $50,000 a year. Over the 15-year life of the system, the machines yielded $3.5 million in labor and productivity savings.
Quoting John Stuart Mill, the NYT proclaims, when you think about it, no jobs are really lost. Think of all the new jobs being created!
Moreover, robotics executives argue that even though blue-collar jobs will be lost, more efficient manufacturing will create skilled jobs in designing, operating and servicing the assembly lines, as well as significant numbers of other kinds of jobs in the communities where factories are.
Don't Panic! Robots are kinda human and they're even fighting against the division of labour:
But the arms seem eerily human when they reach over to a stand and change their “hand” to perform a different task. While the many robots in auto factories typically perform only one function, in the new Tesla factory a robot might do up to four: welding, riveting, bonding and installing a component.
This brave new world - a beautiful symbiosis between man and machine - is a worker's paradise!
Mr. Graves wears headsets and is instructed by a computerized voice on where to go in the warehouse to gather or store products. A centralized computer the workers call The Brain dictates their speed. Managers know exactly what the workers do, to the precise minute.

Wednesday, December 19, 2012

Reading Capital Politically, Part 2

My last posthad a selection of quotes from Reading Capital Politically. There were so many that I retained some quotes until this blog entry.

[...] the overwhelming majority of the people are put in a situation where they are forced to work to avoid starvation. The capitalist class creates and maintains this situation of compulsion by achieving total control over all the means of producing social wealth. The generalized imposition of the commodity-form has meant that forced work has become the fundamental means of organizing society - of social control. It means the creation of a working class - a class of people who can survive only by selling their capacity to work to the class that controls the means of production.

Most fundamentally, the view of the commodity as use-value is the perspective of the working class. It sees commodities (e.g., food or energy) primarily as objects of appropriation and consumption, things to be used to satisfy its needs. Capital sees these same commodities primarily as exchange-values - mere means toward the end of increasing itself and its social control via the realization of surplus value and profit.

The preoccupation of the working class with exchange-value and the preoccupation of capital with use-value, however, are both the outgrowth of capital's success in imposing its social system.

Because of our need for this use-value of food, capital understood early on that its control over food as a commodity gave it control over workers. This was why the most basic means of production stripped from workers in the period primitive accumulation was land - the traditionally necessary precondition for producing food. Thus the fundamental use-value of food for capital is the power to force the working class to work to get it.

One way in which the old dichotomy between politics and economics has often been posed has been to label as "economism" struggles by workers which are deemed solely quantitative, for example, more wages, shorter workday, and so on. These struggles are said to be within capital, which is itself essentially quantitative. "Political" struggles are only those that challenge the "quality" of capital itself, that is, that threaten the "revolutionary" overthrow of capital via the seizure of state power. From what we have seen already, it should be apparent that struggles over the length and intensity of the workday (how much the commodity-form is imposed) are at once quantitative and qualitative: quantitative because they concern the amount of work that will be done for capital, qualitative because they put into question the realization of enough surplus value to maintain capital's control

[Quoting Marx:] ". . . the idea held by some socialists that we need capital but not the capitalists is altogether wrong. It is posited within the concept of capital that the objective conditions of labor -- and these are its own product -- take on a personality toward it, or what is the same, that they are posited as the property of a personality alien to the worker. The concept of capital contains the capitalist."

Men do benefit from women's work; whites do benefit from blacks' lower status; local workers do benefit from immigrant workers' taking the worst jobs. Therefore, the struggle to destroy the divisions generally finds its initiative in the dominated group, since the other side cannot be expected to always work to destroy its privileges. The efforts to overcome racism, sexism, imperialism, or the exploitation of students in the 1960s were led by the struggles of blacks not whites, women not men, peasants not Americans, students not professors or administrators.

[...] to conceive of the value of a commodity as being the direct result of the work of producing that individual commodity is to lose the social character of value and to see it instead as some metaphysical substance that is magically injected into the product by the worker's touch.

[Quoting Marx:] ". . . the real level of the overall labour process is increasingly not the individual worker. Instead, labour-power socially combined and the various competing labour-powers which together form the entire production machine participate in very different ways in the immediate process of making commodities, or, more accurately in this context, creating the product. Some work better with their hands, others with their heads, one as a manager, engineer, technologist, etc., the other as overseer, the third as manual labourer or even drudge. . . . If we consider the aggregate worker, i.e., if we take all the members comprising the workshop together, then we see that their combined activity results materially in an aggregate product which is at the same time a quantity of goods. And here it is quite immaterial whether the job of a particular worker, who is merely a limb of this aggregate worker, is at a greater or smaller distance from the actual manual labour."
These very important concepts should lead us once and for all away from any tendency to try to grasp value in terms of individual cases.

When Marx wrote, for example, in Chapter 15, Section 3, on the employment of women and children, he saw these persons being drawn ever deeper into the industrial machine to be chewed up daily and left to recuperate at night in the same fashion as male workers. There was no need for any special theory about the family, housework, or schoolwork, because these constituted negligible parts of the day. But later, with the expulsion of women and children from the mines and the mills and the factories, with the creation of the modern nuclear family and public school system by capital, such a theory is vital. Today, we must study how capital structures "free time" so as to expand value. We must see how housework has been structured by capital with home economics and television to ensure that women's time contributes only to the reproduction of their own, their husbands', and their children's labor-power. We must see the desire for the reproduction of life as labor-power behind capital's propaganda that it is in the interest of the individual or the family to have a "nice" home or a "good" education.

Both housework and schoolwork are intended to contribute to keeping the value of labor-power low. The more work done by women in the home, the less value workers must receive from capital to reproduce themselves at a given level. The more work students do in the school, the less value must be invested in their training and disciplining for the factory (or home).

[...] the labor an "average person" can perform, say, in the United States of 1775 and in the United States of 1975, or in the United States of 1975 and in upland Papua of 1975, is quite different. When put concretely this way, the vagueness of the notion vanishes. Workers of all these periods and places could be trained to perform "average labor" today in a New York City factory or office. But the amount of training our 1775 farmer or our 1975 tribesman would require would be substantially more and of a different order, involving not just linguistic, mathematical, or mechanical skills, but regularity and discipline.

Monday, December 17, 2012

The Civil War in France

I recently read Karl Marx's The Civil War in France. It's about the Franco-Prussian War and the Paris Commune, 1870-71. This was the book that really began Marx's rise to infamy - accused of plotting the whole uprising from London. It was written during the war and subsequent revolution in Paris.

If, like me, you're not overly familiar with the history of 19th Century France (and Prussia), here is a short description of the main characters you'll encounter reading this book:
Large chunks of this book aren't very interesting for a modern reader. These sections are largely concerned with military strategy and the criticism of various personalities (mostly Bonaparte and Thiers). At the time, revealing these people for what they were was an important thing to do, but they're now long dead.

There are six chapters. I've summarised them below:

Chapter 1 is amazing in that it contains communiques from French and Prussian workers opposing the war.
The English working class stretch the hand of fellowship to the French and German working people. They feel deeply convinced that whatever turn the impending horrid war may take, the alliance of the working classes of all countries will ultimately kill war. The very fact that while official France and Germany are rushing into a fratricidal feud, the workmen of France and Germany send each other messages of peace and goodwill; this great fact, unparalleled in the history of the past, opens the vista of a brighter future.
Chapter 2 is mostly concerned with military tactics, towns of Germany and France and a history of the two nation's conflicts. The chapter ends with an extremely ominous (and prophetic) warning:
Let the sections of the International Working Men’s Association in every country stir the working classes to action. If they forsake their duty, if they remain passive, the present tremendous war will be but the harbinger of still deadlier international feuds, and lead in every nation to a renewed triumph over the workman by the lords of the sword, of the soil, and of capital.
In Chapter 3, Marx gets stuck into Thiers, describing him as a "monstrous gnome" and elucidating the build-up to the massacre. I thought chapters 3 and 4 were the least relevant to anyone reading nowadays.

In chapters 5 and 6 Marx writes about the events of the Paris Commune; its successes and its destruction.
In spite of all the tall talk and all the immense literature, for the last 60 years, about emancipation of labor, no sooner do the working men anywhere take the subject into their own hands with a will, than uprises at once all the apologetic phraseology of the mouthpieces of present society with its two poles of capital and wages-slavery (the landlord now is but the sleeping partner of the capitalist), as if the capitalist society was still in its purest state of virgin innocence, with its antagonisms still undeveloped, with its delusions still unexploded, with its prostitute realities not yet laid bare. The Commune, they exclaim, intends to abolish property, the basis of all civilization!

To find a parallel for the conduct of Thiers and his bloodhounds we must go back to the times of Sulla and the two Triumvirates of Rome. The same wholesale slaughter in cold blood; the same disregard, in massacre, of age and sex, the same system of torturing prisoners; the same proscriptions, but this time of a whole class; the same savage hunt after concealed leaders, lest one might escape; the same denunciations of political and private enemies; the same indifference for the butchery of entire strangers to the feud.

If the acts of the Paris working men were vandalism, it was the vandalism of defence in despair, not the vandalism of triumph, like that which the Christians perpetrated upon the really priceless art treasures of heathen antiquity; and even that vandalism has been justified by the historian as an unavoidable and comparatively trifling concomitant to the titanic struggle between a new society arising and an old one breaking down.

All the chorus of calumny, which the Party of Order never fail, in their orgies of blood, to raise against their victims, only proves that the bourgeois of our days considers himself the legitimate successor to the baron of old, who thought every weapon in his own hand fair against the plebeian, while in the hands of the plebeian a weapon of any kind constituted in itself a crime.

Working men’s Paris, with its Commune, will be forever celebrated as the glorious harbinger of a new society. Its martyrs are enshrined in the great heart of the working class. Its exterminators history has already nailed to that eternal pillory from which all the prayers of their priest will not avail to redeem them.
Engels, in his 1891 Introduction, makes some very interesting comments about the state and the Dictatorship of the Proletariat, especially relevant in light of the horrors done in his and Marx's name in the 20th Century.
From the outset the Commune was compelled to recognize that the working class, once come to power, could not manage with the old state machine; that in order not to lose again its only just conquered supremacy, this working class must, on the one hand, do away with all the old repressive machinery previously used against it itself, and, on the other, safeguard itself against its own deputies and officials, by declaring them all, without exception, subject to recall at any moment.

Of late, the Social-Democratic philistine has once more been filled with wholesome terror at the words: Dictatorship of the Proletariat. Well and good, gentlemen, do you want to know what this dictatorship looks like? Look at the Paris Commune. That was the Dictatorship of the Proletariat.
I read the edition at marxists.org. I've re-formatted it as an e-book (including the bulk of the appendix) and made it available at: The Civil War in France.

Wednesday, December 12, 2012

Reading Capital Politically

I have recently re-read Reading Capital Politically by Harry Cleaver. It's a book that injects contemporary discussion (until 1979) and class analysis into a reading of the first chapter of Karl Marx's Capital, Vol 1. I re-read an e-book edition (below) that I put together from Harry Cleaver's university webpage (which currently - Dec 2012 - no longer contains the files).

My edition is generally not as good as the PDF edition. The main disadvantage is that the footnotes aren't hyper-linked. However, it has the advantage of containing all the prefaces to the various editions that Cleaver has written over the years. It is current as of the preface to the German translation of November 2011. (I excluded the 2011 Polish preface as it is very similar to the German preface.) In that respect, it's the most complete version. I've also done some minor editing.

The formats that you can download are:
Below are some quotes that I found illuminating:

[...] the continuing spread of Taylorist and Fordist deskilling produced such an alienation of young workers from work that, by the 1960s, the desire to take over work and make it less alienating was being more and more replaced by its simple refusal. They didn’t want control; they wanted out.

For Marx, value was only understandable within the context of surplus value. It was not just a form, separable from its content. Value does have a form, exchange value, but it also has a content: imposed labor and the link between value and surplus value is that in the normal course of capital accumulation, the capitalists only impose labor when they can impose surplus labor.

The capitalists are capitalists, not when they consume the surplus, but when they invest it, i.e., when they impose more work. And this is exactly what the socialist critique of capitalist development fails to deal with. By focusing uniquely on the question of who owns or controls the surplus and demanding workers' control, it fails to come to grips with the substance of value and surplus value: endlessly imposed work.

Why did Marx hate money so much? Because it is the quintessential distillation of homogenized labor, of the reduction of all of human life to labor.

Rather than the usual Marxist image of the capitalist with a whip, better the image of would-be managers riding the tiger's back trying to coerce or cajole their mount along different lines of development, frequently coming within a hair's breath of falling off when the tiger rears or comes to a sudden halt, always in danger of the tiger turning around and ripping these upstarts from its back.

To the degree any group of people ruptures capitalist command and carves out their own space, capital responds by doing its best to isolate that space, to sever its connections with the rest of the system, to prevent it from drawing on the productivity of global social production and forcing it to rely on its own limited resources.

[...] the wage is not the only form through which the reduction of humans to abstract labor under capital is accomplished. Not in the Third World, not in the First. In all worlds where it holds sway the central problem for capital is the imposition of work, how it manages to do that is purely secondary.

But what, some may ask, of the peasants who produce a surplus they sell on the market? Are these not petty bourgeois producers and outside the working class? The answer is that they are still very much part of the working class if the result of their work is only self-reproduction. It does not even matter if they hire waged labor, if they are only earning subsistence. These peasants are essentially piece workers for capital and the per-unit price they obtain for their agricultural products is their piece rate.

It quickly becomes apparent to anyone who has read Engels and Stalin that Althusser and friends have added almost nothing to the original discussions of historical materialism except a more obscure vocabulary and a deeper scientific gloss. We are still left with a lifeless sociological taxonomy of modes of production, the unresolvable problems of the interactions between the base/superstructure dualism, the mystery of the articulation of modes, the absence of class struggle, and a fetishism of production that justifies contemporary socialism.

[...] despite the originality and usefulness of their research into the mechanisms of capitalist domination in both the economic and cultural spheres, and indeed precisely in the formulation of those mechanisms as one-sidedly hegemonic, Critical Theorists have remained blind to the ability of working-class struggles to transform and threaten the very existence of capital. Their concept of domination is so complete that the "dominated" virtually disappears as an active historical subject. In consequence, these philosophers have failed to escape the framework of mere ideological critique of capitalist society.

As Tronti pointed out, under the conditions of the unskilled mass worker, work itself could only be seen as a means of social control to be abolished, not upgraded. This understanding led directly to the realization that the basic characteristic of working-class struggle in this period is not only an escape from capital but also an escape from existence as working class. The aim of the mass worker is to cease to be a worker, not to make a religion of work.

[Quoting Marx:] "Bourgeois economy thus provides the key to the economy of antiquity, etc. But it is quite impossible [to gain this insight] in the manner of those economists who obliterate all historical differences and who see in all social phenomena only bourgeois phenomena. If one knows rent, it is possible to understand tribute, tithe, etc., but they do not have to be treated as identical."

Thursday, November 15, 2012

Aufheben, Fortunati and Federici


I read Aufheben's review of the Arcane of Reproduction (by Fortunati) years ago. Even though I thought it was a generally correct analysis of a terrible book (or a terrible translation), I thought Aufheben's conclusions were false. I recently read Federici's latest book, Revolution at Point Zero: Housework, Reproduction, and Feminist Struggle. I think I can now effectively say why Aufheben are incorrect.

Aufheben's conclusion about value and housework is:
So then, does housework create value, or not? We have seen in the previous sections that the answer is: no. Housework does not produce commodities, and the labour involved in it cannot be abstracted and measured as abstract labour, as a contribution to value. But we have also seen the value supposedly created by housework cannot be pinned down anywhere.
[Aufheben, The arcane of reproductive production]
I agree that without commodities at some point in the production process, it's impossible to have value. Nevertheless, housework definitely produces and reproduces labour-power. Labour-power can be sold as a commodity. The fact that Aufheben disputes this is ridiculous. Every new generation of worker for the factory, office or farm is created and maintained by house-work. What the hell do they think pregnancy, childbirth, feeding, clothing, caring for, teaching is if it isn't the production of labour-power? What is cooking, ironing, cleaning, washing, sex, etc., if it isn't the reproduction of existing labour-power? This work remains largely un-waged, mostly done by women. Is it relevant that it isn't immediately realised as a wage for it to contain value? It isn't relevant if you accept Tronti's idea of the social factory, as expanded by Federici:
Work appears as just one compartment of our lives, taking place only in certain times and spaces. The time we consume in the “social factory,” preparing ourselves for work or going to work, restoring our “muscles, nerves, bones and brains” with quick snacks, quick sex, movies, all this appears as leisure, free time, individual choice.
[Federici, Silvia (2012-09-01). Revolution at Point Zero: Housework, Reproduction, and Feminist Struggle (Common Notions) (pp. 35-36). Independent Publishers Group. Kindle Edition.]
One way to think of house-work is to understand that the value of house-work is bound-up in the waged-worker and realised when they receive their pay. It's not some sort of secret/hidden extra thing like Fortunati would have you believe, but it's a realisation that people aren't atomic individuals that can be separated out like little units (like bourgeoisie ideology would have us believe).

On the topic of commodity production and who produces them, Marx is clear that it doesn't matter who does it or how it is done once the world-market has been established.
No matter whether commodities are the output of production based on slavery, of peasants (Chinese, Indian ryots), of communes (Dutch East Indies), of state enterprise (such as existed in former epochs of Russian history on the basis of serfdom) or of half-savage hunting tribes, etc. — as commodities and money they come face to face with the money and commodities in which the industrial capital presents itself and enter as much into its circuit as into that of the surplus-value borne in the commodity-capital, provided the surplus-value is spent as revenue; hence they enter in both branches of circulation of commodity-capital. The character of the process of production from which they originate is immaterial. They function as commodities in the market, and as commodities they enter into the circuit of industrial capital as well as into the circulation of the surplus-value incorporated in it. It is therefore the universal character of the origin of the commodities, the existence of the market as world-market, which distinguishes the process of circulation of industrial capital.
[Marx, Capital Volume 2, Chapter 4, "The Three Formulas of the Circuit"]
[...] a commodity produced by a capitalist does not differ in any way from that produced by an independent labourer or by communities of working-people or by slaves.
[Marx, Capital Volume 2, Chapter 19, "Former Presentations of the Subject"]
Once the world-market exists, pretty much everything becomes subject to its rules. A tribe of savages could collectively work together to produce a commodity. Why is a marriage not treated in the same way? The nuclear family expends the labour-power that is realised as exchange-value in the form of the waged-worker's pay cheque. It's a simple as that.

The value of housework can be most clearly revealed through contemporary history. This is because housework is moving from being entirely hidden through the naturalised forms of love and marriage to the waged form.
As the participation of women in waged work has immensely increased, especially in the North, large quotas of housework have been taken out of the home and reorganized on a market basis through the virtual boom of the service industry, which now constitutes the dominant economic sector from the viewpoint of wage employment. This means that more meals are now eaten out of the home, more clothes are washed in laundromats or by dry-cleaners, and more food is bought already prepared for consumption.
[Federici, Silvia (2012-09-01). Revolution at Point Zero: Housework, Reproduction, and Feminist Struggle (Common Notions) (pp. 107). Independent Publishers Group. Kindle Edition.]
Aufheben are incorrect. There is an immense secret being kept - even with generations of feminism from the 1960s until the 2010s and certainly within Marxism - that a huge proportion of the Earth's wealth is generated by unwaged (generally women's) work. Does this work create value? In Fortunati's sense, no. In Marx' sense, definitely.

Thursday, November 8, 2012

The Society of the Spectacle

I recently re-read The Society of the Spectacle. I read the Knabb translation.

There is a pdf of the book online and physical copies are available. I needed it for my Kindle, however, so I downloaded the HTML, cleaned up the document and converted it to a mobi format.

UPDATE: Notes from the Sinister Quarter has created a superior version of this book. Go and get it from their website.

Below are some interesting quotes I found during this reading:

Kennedy survived as an orator to the point of delivering his own funeral oration, since Theodore Sorenson continued to write speeches for his successor in the same style that had contributed so much toward the dead man’s public persona.

Wherever abundant consumption is established, one particular spectacular opposition is always in the forefront of illusory roles: the antagonism between youth and adults. But real adults — people who are masters of their own lives — are in fact nowhere to be found.

Like the old religious fetishism, with its convulsionary raptures and miraculous cures, the fetishism of commodities generates its own moments of fervent exaltation. All this is useful for only one purpose: producing habitual submission.

The plain facts of history, however, are that the “Asiatic mode of production” (as Marx himself acknowledged elsewhere) maintained its immobility despite all its class conflicts; that no serf uprising ever overthrew the feudal lords; and that none of the slave revolts in the ancient world ended the rule of the freemen. The linear schema loses sight of the fact that the bourgeoisie is the only revolutionary class that has ever won;

Imprisoned in a flattened universe bounded by the screen of the spectacle that has enthralled him, the spectator knows no one but the fictitious speakers who subject him to a one-way monologue about their commodities and the politics of their commodities. The spectacle as a whole serves as his looking glass. What he sees there are dramatizations of illusory escapes from a universal autism.

Tuesday, October 30, 2012

The most annoying thing about Windows 7...

is when your application goes off screen and is unreachable. How can that even be possible? I would have thought that Windows would have something to detect and prevent this occurring. I just found a fix, however, so it isn't too difficult to deal with.

Thursday, August 30, 2012

VB.NET cheat sheet

I've been doing quite a bit of programming in VB.NET recently. It's almost exactly the same as C# but a few things have caught me out. I've written up a small cheat sheet with the noticeable differences (plenty of websites will give you a huge list of irrelevant differences).

Keywords

C#VB.NET
thisMe
baseMyBase
abstractMustOverride/MustInherit
virtualOverridable
sealedNotInheritable
class Class : InterfaceImplements (statement)
internalFriend
staticShared
typeof()GetType()

If you want a static class in VB.NET, you'll need to use the Module keyword.

(One thing to note here is how much more intelligible some of the VB.NET keywords are.)

Logic

C#VB.NET
&&AndAlso
||OrElse

There is no equivalent for And and Or in C#.

Numeric type suffixes

C#VB.NET
12.34M (for Money)12.34D (for Decimal)
12.34D (for Double)12.34R (for Real)

Lambdas

C#apples.Single(x => x.Colour = "red")
VB.NETapples.Single(Function(x) x.Colour = "red")

Initialising lists and objects

C#var apple = new Fruit { Colour = "green" };
VB.NETDim apple = New Fruit With {.Colour = "green"}

C#var apples = new List { new Fruit { Colour = "red" }, new Fruit { Colour = "green" } };
VB.NETDim apples = New List(Of Fruit) From {New Fruit With {.Colour = "red"}, New Fruit With {.Colour = "green"}}

Anonymous types

C#apples.Select(x => new { Colour = x.Colour });
VB.NETapples.Select(Function(x) New With {.Colour = x.Colour})

Nulls and Nothing

If you're coming from C#, the Nothing keyword does not do what you'd expect. What would you expect the following code to do?

Dim value = ""
If value = Nothing OrElse value Is Nothing Then
    Throw New Exception()
End If

If you said "not throw an exception" you'd be wrong. Weirdly, the first condition is true but the second condition is false, so it throws. Compare with similar C# code:

var value = "";
if (value == null)
    throw new Exception();



In this case, the exception doesn't get thrown.

Monday, August 27, 2012

Barrett is an idiot

I spent 1.5 hours of my life last week listening to people talk about the "Seven Levels of Consciousness".

Richard Barrett, a man lacking wits but making up for it with entrepreneurial enthusiasm, has improved the old pyramid model of Maslow (the hierarchy of needs) by creating an hourglass model.

Old:

Improved:


One will instantly see the superiority of this new model. For one thing, it's symmetrical. And it has circles. If there is anything more scientific than pyramids, it's circles. And the number seven.

I have to say how impressed I am. Barrett has taken a relatively meaningless concept, the hierarchy of needs - wholly unproven and unprovable - and improved it by extension and inversion via the science of the Vedas. If it's science you're after, an ancient holy text is the best place to look. He's melded religious myth and pseudo-science and made a business out of it, selling it to morons world-wide.
Vedic science specifies seven levels of consciousness. These are waking, sleeping, dreaming, soul consciousness, cosmic consciousness, God consciousness and unity consciousness. It appeared to me that the descriptions of the last four of these levels of consciousness described the underlying features of self-actualisation. (From Maslow to Barrett)
One could wonder how this sort of garbage could become such a integral part of corporate consciousness, especially at the management level. But it's not an anomaly. Business is full of unproven ideas and myth. Modern myth may appear to be especially good targets of ridicule but old myths are no less absurd, merely more accepted because they've been around longer.

Friday, August 17, 2012

Euler problem 19

I started writing this blog entry a year ago. It's about an Euler problem I solved in F#. The code makes more sense to me now than it did a year ago and I haven't touched F# since then. I guess I'm just way smarter now.



Solving Euler problem no. 19 is the solution I'm most proud of. It's the first problem that I solved in F# with no assistance by the 'net.

The problem:
How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
It isn't an overly complex problem but there a couple of tricky aspects. The approach that I used was to start on the first Sunday of 1901 (6th Jan) and add seven days over and over (i.e., only counting Sundays) until the end of 2000. I could have used the .NET DateTime type to solve this problem very easily, but I decided to see if I could solve the problem using my own date type.

I solved the problem by using a few F# features, namely:
  • pattern matching
  • tuple
  • record
  • list
The first problem was February. February is a prickly month. Pattern matching will solve it! The febDays function accepts a year as a parameter and returns the number of days that February has.

    let febDays y = match y with
                            | y when y % 400 = 0 -> 29
                            | y when y % 100 = 0 -> 28
                            | y when y % 4 = 0 -> 29
                            | _ -> 28

After February was ready, I needed to know the number of days in any month, given the month (as a number) and the year. I used pattern matching again. Therefore,

    let daysInMonth (m, y) =
            match m with
            | 2 -> febDays y
            | 4 | 6 | 9 | 11 -> 30
            | _ -> 31

The other interesting function was to be able to add a day to a date. I did:

    let addDay date =
        match date.day with
        | d when d < 1 || d > daysInMonth(date.month, date.year) -> failwith "Not a valid day of the month."
        | d when d = daysInMonth(date.month, date.year) -> match date.month with
                                      | m when m < 1 || m > 12 -> failwith "Not a valid month."
                                      | m when m = 12 -> { day = 1; month = 1; year = date.year + 1}
                                      | _ -> { day = 1; month = date.month + 1; year = date.year}
        | _ -> { day = date.day + 1; month = date.month; year = date.year}

The code above isn't the whole solution, but it's the interesting parts. As you can see, I pretty much pattern matched the whole solution. It's a shame that C# doesn't have pattern matching because it's a really powerful language concept.

Wednesday, August 15, 2012

Flat Earth vs Climate Change

The following is an exchange between me and someone I'll call Matt. He has some interesting ideas about climate change... After his response, I didn't think I could take the discussion anywhere else. He's clearly a downer and therefore not amenable to reason.



Well constructed and very much in line with what I think on the topic, particularly the part about The vested interests and the role of the big ball of burning gas above our heads in global warming.

http://www.theage.com.au/opinion/climate-change-science-is-a-load-of-hot-air-and-warmists-are-wrong-20120801-23fdv.html

Gee I’m glad I get to give an extra 500 per year to the government though.

Matt



Matt, I think this debate is distracting you from a much more significant dispute. The real controversy is between those that believe in the Ice Wall and the downers – those believing in the Waterfall. They both have photographic evidence:

Ice Wall:
     







Waterfall:









But whose testimonial can we believe? Personally, I think a British Naval Officer’s account is very convincing:
It would be impossible to conceive a more solid-looking mass of ice; not the smallest appearance of any rent or fissure could we discover throughout its whole extent, and the intensely bright sky beyond it but too plainly indicated the great distance to which it reached southward.
This debate is not simply an Antarctic concern, it has global ramifications that also impacts on the “theory” of global warming. If warmists are correct, the implications of an ice wall is extremely concerning. I think downers are drawn towards their “theory” more because of alarmist fear-mongering than they are by empirical evidence.

It’s even possible that their photo could have been faked!

Patrick



Hi Partick,

Agreed, global warming in all of its various extremist incarnations is distracting us all from much more significant debates and issues.

It is far more relevant deciding what to have for dinner tonight and we can all really make a difference here.

In light of my own experimentation and investigation it is just not possible for me to deny that the earth is warming. Just this morning I had to take about 2mil of ice off my car windows. This time last year, it was probably more like 3mil.

My position is more in line with that of the author of this article.

The question that seems to be supressed at every debate on the issue is:

How much is man kind contributing and how much is a natural cosmic or environmental cycle?

The very idea that man kind may not be directly responsible for global warming is considered heresy! In science! According to our politicians - the science of climate, the most chaotic system known to man, is decided, and we're all to blame.

In truth, what makes me most concerned is that people are tired of hearing about it and cannot fathom the thought that perhaps they have been misled to such a gargantuan degree the very world will never be the same.

It all just makes me so HAPppy!

This article was all about the global ramifications of warmist theories and the rampant misuse/misinterpretation of so called "empircal" data so I very much agree with you - individuals will use populist interpretations of statistics to prove whatever wacky theory pops into their heads.

84% of all people know that.

Friday, August 10, 2012

Computer Othello, Part 5: Resources

This post lists the best info I could find on how to write a computer version of Othello.

General

http://en.wikipedia.org/wiki/Reversi#Rules
Rules for Othello/Reversi

http://chessprogramming.wikispaces.com/Othello
Details on bitboards, hashes, deep-first searches and transposition tables. Contains source code (generally in C or C++)

http://www.radagast.se/othello/howto.html
A description of what is required to implement a better than average computer player.

https://skatgame.net/mburo/ps/compoth.pdf
A paper that describes the best Othello computer players from the 80s and 90s (IAGO, BILL and LOGISTELLO)

Strategy (human and computer)

http://radagast.se/othello/Help/strategy.html
http://www.samsoft.org.uk/reversi/strategy.htm

Implementation

http://users.informatik.uni-halle.de/~jopsi/dass4/
A break-down of the tasks involved in creating an Othello game. Has info on implementing the rules and how the minimax search works.

http://www.dcs.gla.ac.uk/~daw/masters-projects/dissertations/Colquhoun.2008.pdf
Computer science student's paper.

http://www.cs.kent.edu/~jmelnyk/othello/
A description of someone's attempts to write-up Othello depth-first searches (alpha-beta, negascout, MTD(f), Multi-ProbCut, etc.)

Computer player

http://samsoft.org.uk/reversi/openings.htm
A list of the standard Othello openings.

http://xenon.stanford.edu/~lswartz/cs221/desdemona_writeup.pdf
Description of various evaluation strategies.

http://othello.dk/book/index.php/Thor_Database
The Thor database was the only archive of Othello games that I could find on the net.

Finally

If you want to see what I did with this information, there is my source code for Othello. It's fairly well written, the UI looks okay and is easy to use and the computer player plays well. I implemented most things you'd do in a world-class computer player. However, you'd have to make it a lot more efficient, if you wanted to take on those players.

It was interesting, frustrating and fun to try to write a decent Othello game. I learnt a huge amount too.

Thursday, August 9, 2012

Best films I've seen this year

I don't see many new great films anymore. I watched most of the backlog years ago. Only one or two new noteworthy films are released every year. However, I've managed to watch some really good films this year. They are:

El Norte: About Guatemalans that escape to the US via Mexico. Probably the best film I've ever seen about a typical experience of an asylum seeker.

12 Angry Men: A jury discuss a murder they're to give a verdict on. They're stuck in a hot room debating the various accounts of the witnesses. The film must be every liberals favourite film, but that doesn't stop it from being a really exciting unravelling of preconceived ideas. "Nobody wears eyeglasses to bed."

Night of the Living Dead: Original zombie film. It has a simple but really effective plot. Extremely tense.

The Lady Eve: It's a rom com. There are a few cheesy bits, but it's generally pretty funny and endearing.

Frozen Planet (not a film): A nature documentary series about life in the Arctic and Antarctic. It made me appreciate just how utterly brutal life in the natural environment is for every living creature except (most) humans (and some pets). Nature is cruel, violent, and completely indifferent. Creatures spend their lives hungry, hunted, cold and alone.

It made fully realise that rather than trying to emulate (bourgeois rhetoric on markets), admire (people who like natural/organic products), or lament the loss of nature (millenarian and some Green movements) we should thank our lucky stars that we're somewhat removed from that pitiless existence. We should do everything we can to reject the laws of nature (that doesn't, in turn, threaten our existence).

Saturday, August 4, 2012

Hardcore Minecraft

We played multiplayer Minecraft again tonight, after many moons. This time we played in hardcore mode; no re-spawn. It played like the game I've always wanted Minecraft to be. Challenging, tense and satisfying. I definitely want to play more.

A majestic canyon

A field of sheep

Mana from Heaven

My companion's remains. The rock fell out from under him, into lava. He followed.
It was a disturbing, saddening and somewhat guilt-ridden experience.

Friday, August 3, 2012

Troubles with Unity and Mono

Using Unity for my Othello game was not without issues. The biggest issue I experienced related to Unity's use of Mono. Here is why:

A depth-first search generates a lot data. Oridinally, in .NET, that would be fine. You create the data, process it and forget about it - the .NET garbage collector (GC) will release the data from memory when required. That isn't true of Mono 2.6. The garbage collector in Mono 2.6 is kind of rubbish. (See what I did there?) Mono 2.8 has a new garbage collector, but Unity 3.5 uses Mono 2.6. And my Othello game uses Unity 3.5.

For my Othello implementation, every turn by the computer player was a new search. It leaked memory all over the place because the GC wasn't dumping the data. It could easily use a gig of RAM over a game, even with shallow searches (depths of 5 or less).

To resolve this issue, I - though Andrew came up with the idea - used a struct instead of a class for the objects used in the search (EvaluationNode and GameState). I re-used memory by storing search results in arrays where the indexes were reset every turn of the game. This negated the need for garbage collection. In the source code, the classes that manage this process are called the EvaluationNodeBuffer and EvaluationNodeCollection.

These changes turned out to be a really good use and re-use of memory. It is also an excellent example to demonstrate the differences between a struct and a class. It also allowed me to search to much greater depths for the computer player.

A problem with this technique is that it makes it very difficult to write code to re-use part of the search tree between turns. Finding which parts of the tree to prune and to then re-organise the arrays and indexes would be technically tricky and CPU intensive. Therefore, for now, the computer player continues to re-searche all game states between turns. Furthermore, any sort of parallel programming to speed-up the search would be hindered by this approach.

What about Unity 4? That's out soon. Will that support the newer version of Mono? Unfortunately not.
We will be shipping Mono 2.6 with Unity 4.0. This will allow the same subsets of .NET features as in Unity 3, depending on the profile you choose in your player settings. (Unity 4 FAQ)

Thursday, August 2, 2012

The Lello-Lea Hypothesis

The Ice-Wall of Antarctica
A report from the Society:

The standard flat-Earth model (SFEM) postulates an ice-wall beyond Antarctica. SFEM supersedes waterfall theories of other flat Earth models and replaces the controversial spherical-earth conjecture's (SEC) notion of Antarctica as an island continent.

The Lello Hypothesis states: "the universe is a series of flat earths stacked within a vast crystalline cylinder folded back on itself to form a never ending torus. I.e., a cosmic, hollow, ice-donut." The Lea Modification, sometimes known as the Lello-Lea Hypothesis, states that: "interspersed with crystalline water (H2O), exists an abundance of naturally occurring granular material composed of finely divided rock and mineral particulates forming 'deserts' - similar to observable regions on Earth."

It should be noted that these hypotheses are not to be confused with the weaker and frankly implausible set of ideas that A. Hayes has expounded in which a series of flat earths are distributed across the inner surface of a torus of indeterminate extent. Hayes is also known for the infinite cylinder hypothesis (ICH). ICH is perhaps even more unlikely than his inside-out donut.

The Society for the Lello-Lea Toroid Flat Earths Hypothesis is searching for intelligent life on other flat earths. First contact will provide the empirical evidence, and hence proof, of the Lello-Lea Hypothesis. Meanwhile, scientists are formulating a mathematical proof for the minimum quantity of flat earths that must exist.

Chalmers' recent work (unpublished, in correspondence with the author) has yielded a breakthrough on the topic, establishing deep relationships with elliptic curve theory and the calculus of manifolds, while raising the lower bound on the number of flat earths that must exist to -4. We are assured that more revelatory findings are to follow.

It is not expected that the combined forces of the Society and scientists will be able to provide the actual number of flat earths in our toroidal universe. However, we believe that within the next ten years, we will be able to prove that:
  1. We do indeed live in a multi-earth, toroidal universe (i.e., SEC is fallacy.)
  2. There are at least 3 flat earths.
A. Hayes, and others, have proposed expeditions to the Ice-Wall to conduct experimental drilling. A small party would also test a radical SFEM speculation of going "beyond the Ice-Wall." Funding and applications for strategic and/or technical approaches is being sought.

Friday, July 27, 2012

Computer Othello, Part 4: Trials and Transposition Tables

By the time I implemented transposition tables for my computer player in Othello, I'd finished most of the components of what's required for a decent Othello computer player. I didn't really need to add a transposition table, but I really wanted to understand and implement all the aspects of a computer player for these sorts of games.

A transposition table is used to help speed-up a depth-first search. It does this by keeping track of game states that it has already searched. Along with the game state, it records the value it found for that state in the evaluation function. (Therefore, a suitable data-type for a transposition table in C# is a Dictionary<gamestate,float>. GameState overrides the GetHashCode method to provide an unique as possible hash of the game state. The float holds the value from the evaluation function.) If the search finds the same game state again (via a different path), it uses the value in the transposition table rather than re-calculating it. This saves time.

Intuitively, I wouldn't have thought Othello would have many ways in which different sequences of plays could result in the same game state. Any reading about computer Othello says otherwise, however. In practice, I managed to wipe a couple seconds off a search by using a transposition table.

When I began writing my transposition table I looked for a good way to hash a game state. I found a description of the Zobrist hash:
One useful method for hashing positions in games like Othello and Chess is Zobrist hashing [12]. A Zobrist hash consists of an XOR sum of several bitstrings. For each square on the board, there is one randomly generated bitstring representing a black piece and another representing a white piece. A position's Zobrist hash is formed by XORing together the appropriate bitstrings. The primary benefit of Zobrist hashing is that it can be incrementally updated very quickly by XORing it with the bitstrings for the pieces that have changed. Zobrist hashes also have the advantage of uniform distribution. (Applications of Arti ficial Intelligence and Machine Learning in Othello)
I implemented a Zobrist Hash for Othello, created a dictionary of type Dictionary<ulong,float>, then wondered why I was getting so many bad results. The problem? When you add a key to a dictionary it'll call GetHashCode on the object to retrieve the hash. What happens when you add a hash as a key to a dictionary? The same thing. I was double hashing! Not only that, I was going from a 64-bit Zobrist hash to a 32-bit .NET hash. I was burning time in creating the hash as well as losing information and most likely increasing the number of collisions between different game states. All pretty ugly stuff. The solution, outlined above, was very simple: ditch the Zobrist hash, override the GameState GetHashCode to have:
        public override int GetHashCode()
        {
            return (PlayerPieces | OpponentPieces).GetHashCode();
        }
and change the dictionary to have GameState as the key. The result isn't as fast as if I had implemented my own type of hashtable with my own hash type, but it was a lot easier to do.

In the end, adding a transposition table to my game was relatively easy to do, though I took a long and unnecessary detour to achieve it.

Monday, July 23, 2012

The Walking Dead review

Fashionable zombie pop-culture bores me. I have a negative interest in anything to do with zombies. And yet... there is DayZ and now Telltale's latest adventure game series, The Walking Dead.

The Walking Dead is the only adventure game in the last fifteen years that simply must be played. Why?
  • The narrative and plot are compelling
  • The script is good
  • The characterisation is generally quite good
  • The puzzles are a balance between tricky, frustrating and satisfying
  • The art style is really good
  • The interface is one of the best I've seen in an adventure game
But importantly, it's because
  • It appears to have meaningful choices at almost every node of the dialog tree
  • What you need to do to survive is a great blend of disgust and grotesque fascination. (I think I've said "Oh my God!" more times playing The Walking Dead than any other game!)
Many dialog trees in the game have a timer on them. You often need to respond in moments. This is the most fantastic innovation in adventures games since the dialog tree was created. I doubt The Walking Dead was the first to use it, but it uses it extremely well. It's so tense. I was often locked in indecision. Occasionally, I simply couldn't decide, resulting in awkward silence. I love how not saying anything is an option! Of course, no matter what you say, it can't matter too much, yet it doesn't feel like that at the time. And that's the important thing.

Often events don't go the way I wanted or how I expected, but I just went with it. It's part of the story and it all seems meaningful. Only once have I re-started a section because of the way things turned out. This is great in two ways; 1) even though things don't necessarily go the way you wanted, it's not necessarily bad enough to force you to rewind and 2) I care enough about some events that I simply can't allow the game to continue after an event that was simply too wrong for me to be happy with. That might sound contradictory, but isn't.

The reason why DayZ and The Walking Dead are such good zombie games is because they're not really zombie games. DayZ is about the other people you play with, whether other survivors or bandits that hunt you. The Walking Dead is all about the other characters in the game. The zombies are there in a way that function almost as a relief. Zombies are simple. All you have to do is kill them (again). It's everyone else you have to be worried about. (But that would make a great twist, if zombies weren't exactly as we assume. If they transitioned from a Nazi SS officer to an Itialian fascist infantryman, then you'd have a whole new depth of narrative to explore.)

Episodal format? Seems like a dodgy way to get people to pay for a game that isn't finished. Episodal gaming is a bit of a relic in the era of kickstarter. It's proto-kickstarter, where some of the risks are put onto the consumer rather than all. In effect, I don't mind at all. In fact, I think I prefer it. I don't have the desire or time to sit down and play a game for hour on end. This way I can play it in chunks over a period of months. At episode two of six, I feel like I've gotten all I thought I would get from this game and I'm not even halfway. If quality drops by the end of the season, I don't think it matters. It's already been a whole lot better than many games I've played recently (looking at you Diablo 3).

This is the first game in years that I want everyone to play. I'm not just talking about my friends that don't play games anymore now that they've "grown up." I mean, my mum. She should play it. Sure, it's horrific, but it's done so horrifically well.

Friday, July 20, 2012

Computer Othello, Part 3: Othello computer opponent

After working on the game archive stats, I was ready to create a computer player. Previously, the computer player had played randomly (even Andrew was able to beat it!) To create a computer opponent, I needed to do two things; create an evaluation method and plug-in a search algorithm to find the best estimated play to make.

Evaluation

One of the trickiest things to do with the computer opponent is to evaluate the current game state. Given any arrangement of pieces, you need to be able to determine which of the possible plays is the best. You need an heuristic to do this. An heuristic is an estimation of what you think is a good play to make. The factors that I used to evaluate the state of the game were:

* Number of pieces
* Number of playable squares (usually called "mobility")
* Number of empty squares next to the player's piece ("the frontier", or "potential mobility")
* Various corner and edge patterns (edges and corners are usually better moves)

Pieces and mobility

The most naive heuristic is to count the number of pieces each side has. Ultimately, this is the only measure, piece count determines the winner. However, until the end game, it has little to do with who is going to win.

A less naive approach is to count how many plays can be made. A state where 7 plays are possible is almost certainly better than one where you have to skip your turn because you can't make a play. I had already calculated where a player could place a piece in their turn as part of the user interface. Therefore, I got the mobility measure for nothing.

Finding the empty squares next to a player's pieces was also relatively simple to implement. It was little more than a variation on the mobility algorithm.

Patterns

Image that elucidates where the X and
C-Squares are on an Othello board.
Implementing the patterns was relatively easy to do but it was one of the last additions to the evaluation function that I made. I had previously dismissed this approach as too simplistic to provide much of an improvement to the evaluation. I couldn't have been more wrong. Once I had coded the patterns, the computer player beat me easily. I've since beaten it once or twice, but it went from a disgustingly below average player to a better than average player.

The patterns that I check for are:
  • Corners (a good play for the current player)
  • X-Squares (bad play)
  • C-Squares (bad)
  • Corners and X-Squares (good)
  • Corners and C-Squares (good)
  • Edges (good)
Furthermore, I check for lots of combinations of these patterns. I.e., not only does a game state get points for a play on a corner, but gets even more points for the multiple corners. I didn't check to see if this approach improved play, but I suspect it would.

Piece stability and parity

There were a couple of major components of a good Othello evaluation function that I didn't include. These were piece stability and parity. Piece stability, i.e., finding the pieces that cannot be flipped, is one of the trickier things to determine. There is a good description of how to do it here. I couldn't think of a really efficient way to implement stability, so I left it out.

Parity, i.e., determining who plays last, was relatively simple to implement in its basic form. By default, white will always play last, and therefore has an advantage. For black to play last, someone has to miss a turn. The basic approach to parity didn't really seem to impact the performance of the computer player, so I left it out of the evaluation. A sophisticated form of parity - one where isolated parts of the board are evaluated for parity (an isolated section is one that is surrounded by pieces and edges) - seemed too tricky to implement, so I never tried.

Depth-First Search

I took my negamax, alpha-beta pruning negamax and negascout search methods from my noughts and crosses source code and adapted it to work for Othello. That was fairly easy to do, although my original code was a bit rubbish.

Initially, I thought I'd use negascout for Othello as it is the best of the three. However, for it to work effectively (i.e., better than an alpha-beta pruning negamax), it needs to do shallow searches of the game tree, or find some other way to have a pretty good attempt at pre-ordering the plays from best to worst. Negascout generally does a mini-search within a normal negamax search. It was a more involved task than I suspected. Once I had implemented the patterns approach to the evaluation function, I realised that my computer player was pretty good. Therefore, I decided not to pursue a negascout algorithm for Othello.

Opening book

With all the work that I did to be able to display the history of games to the human player (percentage of games that made a play, percentage of those where black wins), I was serendipitously writing the code for the computer player. The computer opponent uses this information in a similar way as a human.

End game search

One of the things that I didn't do for the computer player was an put any work into an end-game search. This sort of search is much deeper and tries to get search until the end of the game. Once a computer has this information, it'll know if it has won and exactly which moves to make to ensure victory. Until the end-game search, all other plays are calculated guessing. All I did to the computer player approaching end game was increase the search depth.

Conclusion

I completely underestimated how difficult it would be to create a competent computer player. I now have a much greater respect for people who managed to create computer players that are vastly superior to mine on machines that are vastly inferior to today's technology. It's true that .NET is not really up to the challenge (unmanged code like C and assembler would be much more suitable), but you'd think a modern processor using .NET could get close to Pentium using C. From my experience, it didn't. But in truth, it was the algorithms that weren't good enough. I would have many more things to do to be able to compete with other computer Othello players. E.g., stability detection, parity, better potential mobility, negascout, Multi-ProCut, end-game solving, much deeper searching, training and machine learning etc. There is an immensity of improvements that I didn't even touch on. I'm not unhappy with what I achieved, more very impressed that people have done so much better.

Friday, July 13, 2012

Computer Othello, Part 2: Game archive as trainer

I wanted to create a computer game of Othello that did more than simply defeat the human player. I thought of trying to provide a story to the player to help them learn and improve against others. One idea was to process the Thor archive and create stats to apply to each potential play. In that way, the player can see how many people have played the position in the past and how well they did. However, with 100,000 games in the archive, doing this efficiently was tricky.

Initially, I tried using a trie data structure. It seemed like an appropriate structure. However, performance was poor and programming against it wasn't overly intuitive. I tried changing how the data was stored to try to improve performance. Instead of using a human readable notation (i.e., algebraic notation, such as "E6"), I stored each play as a single Unicode character. With 60 possible plays, I used the alphanumeric set, capital letters and symbols. I did this by simply taking a numeric board position (0 to 63), adding 48 to it (to move it into the alphanumeric area of Unicode) and converting it to a char type. This improved things, but performance using the trie was still terrible.

I ditched the trie and wrote LINQ statements against a list of strings. Performance improved, but it was still poor. I switched the search from LINQ to use the BinarySearch method of a list. For a binary search to work, I had to order the data. I was surprised to find that the LINQ OrderBy method didn't sort my data the way I needed. I suspect that it doesn't distinguish case and can't cope with unusual characters. I switched to Array.Sort. Even that didn't work without the StringComparer.Ordinal option. I also needed StringComparer.Ordinal option for the BinarySearch method. All interesting little hurdles.

After all that (plus some more optimisations discovered by using Performance Analyzer in Visual Studio), performance was massively improved but still not perfect. I decided to process the calculations on a separate thread so that it didn't hang the user interface.

I was done. Stats appeared either instantly or within half a second and either way the user interface was not impacted. Yet, I still wasn't done!

Othello is a highly symmetrical game. The first play, a choice of four possible positions, is symmetrically equivalent. No matter where black plays on the first move, one could rotate the board and the board would look the same as any other play. The people who made the Thor database understood this. That's why they standardised the archive to have E6 as the first play for all games. I needed to display the same info on the C4, D3 and F5 tiles that I displayed on E6. Otherwise, the less knowledgeable player may wonder why 100% of games are played at E6.

To be able to display stats on a non-standardised position, I needed to test for symmetry in the game board. I found methods to flip and rotate bitboards. That solved half the problem. I could check if one game state was the same as another. Next, I rotated the stats from a standardised to a non-standardised board. I generated lookup dictionaries to be able to rotate the indices of the board positions. For example, position E6 would become position C4 on a rotated board.
Display of game stats for black.
The blue highlighted square displays black played there in 0.027% of games and won 10% of those games.
After all that, I had a well working set of stats that I could display to the player to assist them in learning where the best opening moves are. It doesn't really provide any sort of story for the player, but at least it gives an indication of where a good play might be.

Later, I also used this data to help the computer player make its opening moves. But that's for another day.

Wednesday, July 11, 2012

Julia Kristeva

On Anthony's visit to Melbourne, he mentioned something about Julia Kristeva that I simply had to know more about. It was the idea that Kristeva suggests we move away from the scientific binary logic of false and true (0 and 1) to a poetic logic of 0 and 2. I was astounded to hear that. It seemed completely absurd (it's been a while since I read any post-modernism). I got the document and found the quote. Here it is:
The polyvalent logic presupposing an infinite number of values in the interval false-true 0  x  1 is a part of bivalent (0-1), Aristotelian logic. Poetic logic is inscribed on a different surface. It remains indebted to Aristotelian logic not in being a part thereof, but insofar as it contains and transgresses that logic. Since poetic unity is constructed in relation to an other as double, the problem of truth (of the 1) does not concern it. The poetic paragram bypasses the one, and its logical space is 0-2, the 1 existing only virtually. (pg 44, Towards a Semiology of Paragrams)
Admittedly, I didn't read all of the document. What I read, I didn't understand. I'm taking Kristeva out of context because I don't understand the context. Nevertheless, I got questions:
  1. How is polyvalent logic "part of" bivalent logic? The inverse (bivalent part of polyvalent) seems more reasonable to me. Yet, polyvalent and bivalent seem to have quite different logical rules.
  2. Unlike polyvalent logic, Kristiva claims that poetic logic (what's that?!) has a logical space of 0-2. It's therefore still bivalent, but because it doesn't contain 1 (truth) it need not concern itself with truth. Hm... but isn't the "1" merely a symbol to represent "truth"? Couldn't "2" also represent "truth"? Or "0" for that matter? In fact, you could be really crazy and suggest "√-1" to be the symbol for "truth". It wouldn't matter, would it?
I will leave you with another quote from earlier in the document. I find it entirely incomprehensible, though it does appear to contradict the above by saying that paragrammatic numerology (which I think is the same as poetic numerology) is "two" and "all" rather than "0" and "2". I like the "The zero is two which are one" statement, though that is very similar to another phrasing I know (i.e., the doctrine of the trinity - god, son and holy ghost are three that are one.) I'm not sure that the bible is a good source for learning logic, however...
The zero as non-sense does not exist in the paragrammatic network. The zero is two which are one: in other words, the one as indivisible and the zero as nothingness are excluded from the paragram, whose minimal unity is both an (empty) all and an (oppositional) two. We shall examine more closely this paragrammatic numerology, where there is no 'one' or 'zero' but only 'two' and 'all'. Unity is empty, does not count, the one is zero but it signifies: it controls the space of the paragram, it is there to fix the centre, but the paragram does not give it a value, a stable meaning. This 'unity' is not the synthesis of A and B; but it has the value of one because it is all, and at the same time it cannot be distinguished from two, because within this unity come together all the contrasting semes, both opposed to each other and united. At once unity and couple, the oppositional dyad, to apply a spatial expression, is realized in the three dimensions of volume. (pg 37, Towards a Semiology of Paragrams)