Lozza – Javascript chess

INTRODUCTION

Lozza is a simple Javascript chess engine still in active development and currently rated about 2380 ELO.  You can play, analyse and train with Lozza via the website link below and developers can also integrate it into their own projects.

HOW TO INTEGRATE LOZZA

The Lozza engine itself is self-contained in a single Javascript file and typically runs in a web worker.  A controlling program  can communicate with Lozza using the string based UCI protocol over the JSON web worker interface.  The “Play Lozza online” link above being an example using my own user interface code.

Below is a very simple example (live link) to fire up Lozza in a web worker and ask it to find the best move for a 10 ply search, sending all output to a HTML element called #dump using jQuery:-

var lozza = new Worker('lozza.js');

lozza.onmessage = function (e) {
  $('#dump').append(e.data);
};

lozza.postMessage('uci');             // get build etc
lozza.postMessage('ucinewgame');      // reset TT
lozza.postMessage('position startpos');
lozza.postMessage('go depth 10');     // 10 ply search

Lozza can auto-detect if it’s running in a node.js context to allow seamless use online in a browser or offline in node.  This allows Lozza run both online and offline on pretty much any platform, including Windows, Linux and Mac.

For example here is a dump of the same 10 ply search using node from the Windows command line:-

Capture

The “info string debug *” lines show overall time and node count etc and are not strictly part of the UCI protocol.  You can either filter them out or change this.debugging to false in the UCI class.

Lozza can be used outside of a web worker by including lozza.js in your HTML file and then using the loz* classes directly.  This is useful for profiling etc.

Please feel free to use Lozza in any chess based projects with the condition of a link back to here. The Play UI  is a good choice to see a more complete example of how to fire up Lozza in a web worker and then communicate with it.    Please also feel free to send me queries: op12no2@gmail.com.

Source:-

http://op12no2.me/toys/lozza/lozza.js

There is a not-necessarily-stable coalface version here:-

http://op12no2.me/toys/lozzadev
http://op12no2.me/toys/lozzadev/lozza.js

ACKNOWLEDGEMENTS

I would very much like to thank these people for help during the (continuing) development of Lozza.

Isms

I think I’m starting to understand how all the …isms fit together thanks to Maajid Nawaz​.

Islam is a religion. There is a spectrum of personal interpretations of the underlying texts based on increasing ideological commitment (literalism), from hyper-moderates to fundamentalists.

Groups of people with similar interpretations may or may not want to impose their ideology on society to create a caliphate (very generic definition). The probability of that increases with literalism as does the likely degree of violence utilised in the methodology.  i.e. its unlikely that hyper-moderates would want to create a caliphate and even if they did it would most likely be by political means rather than violence.  Similarly not all fundamentalists necessarily want to create a caliphate but if they do it seems that violence is more likely because of their increasingly literal interpretation.

So if you draw a graph with ideological commitment (maybe I should have labelled it Literalism) on one axis and caliphate methodology on the other you can mark places where certain groups exist and they will tend to exist on something like the line drawn (I think) which also doubles as the implied probability of a desired caliphate (really a third axis should be use for probability but it seems to collapses fairly reasonably) .

caliphate

Generic labels can be marked for Islamism (the attempt to impose an Islamic ideology on society by political means to create a caliphate) and Jihadism (the attempt to impose an Islamic ideology on society by violent means to create a caliphate – e.g. IS).

Bottom line: Islamophobia is bigotry – it inclusively addresses personal ideology whereas one should address the area under the graph – the activation of those ideologies into processes impacting negatively on society – and with the appropriate means – i.e. social/political pressure against Islamism.

We are not at war with Islam or Islamism or Islamists or even Fundamentalism and Fundamentalists – rather with Jihadism and Jihadists.

Vax preventable outbreaks

The Council for Foreign Relations published an interesting page recently showing  vaccine preventable disease outbreaks 2006 – 2015.   The data they used can be downloaded, so I used it in a very simple way to experiment with a Google WebGL globe.  Click the image below to see it.

Capture

All the outbreaks, regardless of date and disease (mostly measles, mumps, rubella, pertussis and polio) are shown in blue with attacks shown in yellow-ish.  The size of the spike is linearly proportional to the number of cases, but it’s capped at 40000.  The actual maximum number of cases is 130000 in one instance but including  that reduces the smaller outbreaks to just dots.

The WebGL globe was very easy to work with but could do with some documentation!

The WHO report that in 2013 there were 13 deaths every hour from measles.

Indirect protection demo

Clip1

A little demo to show how people are indirectly protected in an epidemic when enough people are vaccinated – herd immunity.

It should work on touch and non touch devices including phones; the layout being responsive to screen size.

The demo is not suitable for thinking about the elimination of a disease in an endemic steady state.  It is rooted in an epidemic context.

Description

This demo executes an epidemic SIR model in real time as sliders change the vaccination rate V (blue) and basic reproduction number R0 (green).  All standard SIR model assumptions hold.  The purpose is to show that as the vaccination rate increases, the number of people indirectly protected from disease increases non-linearly and steeply as the vaccination rate approaches the herd immunity threshold (1-1/R0), as depicted in this sketch:-

See also figure 4 here.  A single infection is used as the trigger.  The total number of people in the population (T) remains the same through the model.

The vaccine is assumed to be 100% seroprotective and long lasting – such that all those who are in the vaccinated fraction of the population are considered immune (and not infectious).  It would be easy to additionally model vaccine seroconversion rates, but essentially one can do the same by just lowering V.

The initial values for the SIR model are calculated as follows:-

S = T(1-V)
I = 1
R = T-I-S

i.e. the population is completely susceptible (S), other than: those vaccinated (who are assumed to be immune in R) and a single index case I.

The values of the three bars are then calculates as:-

VACCINATED  = V * 100%
INFECTED = (SIR(S,I,R,R0) / T) * 100%
PROTECTED = 100% – VACCINATED – INFECTED

For small values of R0, PROTECTED will have a value even when V=0, because of the low force of infection.  This is noted in the help tips rather than a whole new UI element introduced.  I tried to keep the UI very simple.

The model uses an elementary method to try and detect the end of the epidemic which typically converges in 20-100 iterations.  There is a safety limit of 2000 iterations, which is never hit using the constraints of the UI.  The SIR function itself is is defined as:-

function sir(t,i0,s0,b,k) {
  var r0 = t-s0-i0;
  var s1 = s0;
  var i1 = i0;
  var r1 = r0;
  var cnt = 0;
  var itot = i0;
  var safe = 0;
  while(1) {
    safe++;
    if (safe > 2000) {
      $('#debug').html('oops');
      break;
    }
    var inew = s1*i1*b;
    itot += inew;
    var rnew = k*i1;
    var s2 = s1 - inew;
    var i2 = i1 + inew - rnew;
    var r2 = r1 + rnew;
    if (inew < 0.1) {
      cnt++;
      if (cnt > 10)
        break;
    }
    else {
      cnt = 0;
    }
    s1=s2;
    i1=i2;
    r1=r2;
  }
  return itot;
}

Note that R0 is parameterised as b and k as per standard SIR model formulations.  b being the contact rate per capita and k the recovery rate.  b is calculated as kR0 and k is fixed at 0.125.  This may seem like a limitation, but it is a property of SIR models that they behave similarly depending on b/k (R0), so the model need not be complicated by considering different recovery rates – it’s all implicit in R0 (*).    Ditto for population size.

Link

http://op12no2.me/toys/protect

URL Initialisation

Parameters v (initial vaccination rate as a percentage) and r (initial R0) can be added to the URL to override the default values of nil and 7 respectively.  For example:-

http://op12no2.me/toys/protect?r=16

http://op12no2.me/toys/protect?v=87&r=6

http://op12no2.me/toys/protect?r=20&v=100

 This method allows R0 to be specified outside of the UI constraints.

(*)The inverse scenario – solving an empirical infection curve to parameterise a model, suffers from this problem – its one thing finding R0 but quite another to resolve out b and k.

Lozza mate-in-1 trainer

Lozza home

You must solve 10 mate-in-1 puzzles against the clock.  Time penalties are added for illegal and wrong moves.  You must drag the piece to the mating square to solve the puzzle.  The puzzles are loaded at random from a large collection sourced from here.

Click the image to use the trainer.

Capture2

NB: All the puzzles are loaded to your computer the first time you play.  It can take a little while depending on the speed of your internet connection.

Please let me know if you’d like to see any other trainers.

Lozza acknowledgements

Lozza home

Edmund Moshammer for the indispensable jsUCI.

Norbert Raimund Leisner for designing Lozza logos.

Silvian Ruxy for testing Lozza.

Graham Banks for testing Lozza and including her in the CCRL ratings.  Also for an alternative Lozza logo.

Chris Oakman for the lovely chessboard.js UI.

David Bau for seedrandom.js which I use to seed the Zobrist hashes.

Jeff Hlywa for the fab chess.js.

Jason Tiscione for his 3D chessboard.

Harm Geert Muller for discussions and running the fun and useful monthly online tournaments that Lozza participates in.

CPW for algorithms.

CCC for algorithms and discussion.

There are some more specific acknowledgements in the code.

Using Lozza offline

Lozza home

These notes apply to most chess user interfaces.  The Arena UI is used as an example.

Lozza needs a Javascript engine to live in.  Usually this is a web browser, but a web browser just embeds a Javascript engine, so other applications can too.  The most common are mentioned below.

Windows

Download Edmund Moshammer’s jsUCI (embeds Google’s V8 Javascript engine) to a folder of your choice. Download lozza.js and place it in the same folder as jsUCI.

Console use:-

cd <jsuci folder>
.\jsuci_1_2.exe lozza.js

Arena use:-

Capture

You don’t have to use the same folders, it was just an example.  If lozza.js is in a different folder to jsUCI you need to specify the path on the command line and in the UI – absolutely or relative to jsUCI.

Linux/Mac

Download and install node.js (embeds V8).  node.js adds itself to your path. Download lozza.js to a folder of your choice.

Console use:-

cd <lozza folder>
node lozza.js

Arena use:-

Capture

You can use node.js on Windows too instead of jsUCI.  When using node.js you can add Google Chrome V8 options to the command line to see the real time optimisation etc.

jxCore

jxCore is a multi-threaded arrangement of node.js and also has a very nice packaging facility to turn the Lozza into an executable (this is how I generate executables for CCRL).  It can also target Mozilla’s Spider Monkey as an alternative to Google’s V8 engine as used by node.js and jcUCI.

The packaging facility creates an executable suitable for running on the platform doing the packaging.  So if you want Windows 64 and Linux executables, you need to package separately on each of those platforms.  It is however an effortless operation.  Put lozza.js into an otherwise empty folder, then from that folder do:-

jx package lozza.js lozza -native

That’s it.  The Javascript code itself must detect (see lozza.js) it’s in a node.js context and do the appropriate IO – which is different to the IO needed in a web worker or jsUCI context.

Lozza analysis UI

Lozza home

http://op12no2.me/toys/lozza/fen.htm

Optional URL parameters:-

fen=fen – Load the specified FEN.

act=ana – Auto start an analysis.  Be a little bit careful about using this as some people do not like their computer to use a lot of CPU time on an analysis without them starting it explicitly.

act=eva – auto start an evaluation.

Example:-

http://op12no2.me/toys/lozza/fen.htm?fen=5k2/p7/3R4/2p3p1/1bP3P1/5N1P/3p1PK1/3r4 b – -&act=eva

Lozza UCI console UI

Lozza home

http://op12no2.me/toys/lozza/console.htm

This UI allows you to type UCI commands in a console-like manner.

COMMAND EXTENSIONS

In addition to the standard UCI protocol , the following commands can be used:-

stop

Stop the Lozza engine.   Useful to stop a long perft or analysis.  What actually happens is that the web worker containing Lozza is killed.  You’ll need to restart one.

start

Start Lozza.  i.e. create a new web worker containing the Lozza.  After a start the following are automatically sent:-

uci
ucinewgame
position startpos
board

A start command is issued when the console UI starts.

clear

Clear the previous output.

board

Display a textual (FEN) and graphical representation of the current position.

perft depth d [moves m] [inner 1|0]

Perform a perft analysis to a depth of d ply based on the current position.  m is the expected number of moves and is optional, defaulting to 0.  inner 1 will show inner node counts with the default being inner 0.

eval

Show how the static evaluation of the current position is constructed.

id id

Attach an identification label to the current position.  Only relevant if UCI debugging is on.

ping

Check that the engine is alive.

SHORTCUTS

u == ucinewgame

q == quit

p == position

p s == position startpos

g == go

g d = go depth

b == board

NOTES

  1. An explicit ucinewgame is needed to reset the transposition tables; and is required before the first position.  It is optional during a game since it has no effect other than to clear the TT.
  2. Lozza plays it’s best move  when a  go completes, changing the current position.
  3. The current position is unchanged after a perft.
  4. The start, stop and clear commands are not be available when using Lozza offline; for example with node.js.  Similarly only the textual board representation is shown.

Stop the Australian (Anti)Vaccination Network

Clip1

The Australian (Anti)Vaccination Network is a menace to Australian public health.    This infection model joins StopAVN in a way only infection models can!

CLICK HERE to see the model run…

Landscape is best.  It can take a few minutes depending on screen size and processor power.  It’s a classical model too:-

Clip1

 

Agent based infection model

pox

An agent based  infection model.  No maths!  The  outcome is implicit in the movement and contact properties.

A classic iterative SEIR model can be replicated by using infinite distance as the potential connection criteria and a per person exponential distribution for the average Exposed and Infected state lengths.

WIP…

Link:-

http://op12no2.me/toys/pox

 

Children’s Immunisation Centre

A few days ago a friend noted that this claim

which appears on this website

Children’s Immunisation Centre

looked almost like a warranty for their single measles vaccine.  It’s also indirectly implying that MMR does cause autism.

As they correctly state elsewhere on their site, the rate of autism is about 1 in 100 and the standard childhood vaccine for measles (and rubella and mumps) is MMR. Thus selling an alternative single measles vaccine and claiming “no autism” is just another way to say MMR causes autism.

MMR does not cause autism of course.  But there is still a lingering doubt in some parents’ minds, even though the ultimate source of that doubt, Andrew Wakefield, has been struck off and his work shown to be fraudulent.

By indirectly implicating MMR with autism the CIC prey on this doubt, persuading some parents to part with £160 for a single measles vaccine when faced with a real threat of infection, like during the Swansea measles epidemic for example.

Intrigued as to how they know “No autism in 10 years” (*) and living in Swansea and as Martine would say, “tamping”, I phoned them to find out:-

Hi, I’d like to make an appointment for a single measles vaccine.

OK, are you registered with us?

Nope.

OK, it’s £50 for the registration and private prescription and £110 for the vaccine.

OK.

Where do you live?

Swansea.

OK, we have a satellite clinic there.  Let me check…  Ah, sorry there are no slots left for Swansea.  I can fit you in somewhere elsewhere, say…

It’s OK. I’m not too concerned, but if one had been available locally that would have been great.

Well, we can fit you in elsewhere, say…

Actually can I ask you a question?

Sure.

I was impressed that your website says “No autism in 10 years”.  How do you actually know that?  Presumably you won’t be able to check my patient records; so how do you find out?

That’s right, we can’t access your medical records, but our patients tell us.

They tell you?

Yes, well wouldn’t you? [indignantly]. We ask you tell us if you have an adverse reaction within a few days of the vaccine.

A few days?

Yes.

OK, Thanks very much, bye.

Bye.

So there we have it, “No autism in over 10 years” because patients don’t get back within a few days to tell them.

See also:-

Fear mongering and responsibilties – UK private vaccine clinic fuels MMR fears

Clinic quizzed over single jab claims

AM expresses concerns about company targeting Swansea with single measles vaccine

(*) CIC say:-

6) To our knowledge, based on our own experience and from discussions with the other clinics, there have been no cases of parents reporting autism incidents, following on from single measles vaccinations.

Based on reporting within what time period?  Over 10 years, and at least 18,000 vaccinations and a 1 in 100 autism rate, it must be short to claim “no autism” – but how short? and why don’t they state it?  And just maybe they could proactively check via patient records but don’t.

21 Aug 2013. Update.  The ASA have upheld complaints against CIC.  Also reported in The Guardian.

 

vaxfax.me search engine

vaxfax.me is a project oriented around a google custom search engine.  It searches hundreds of science/evidence based websites (and only those websites) for reliable vaccination information.

Link:-

http://vaxfax.me

It was created primarily with parents and parents-to-be in mind – to help them navigate past the mass of vaccine misinformation on the internet.

The advantage of this method over the original “myth busting” static site is that the content is always fresh, relevant and accurate.  New information automatically appears in the search results as a natural consequence of being a search engine – for example the JCVI’s recent decision to vaccinate pregnant women for pertussis in the UK.

It also helps from a personal perspective.  I am a vaccine advocate, not a vaccine expert.  I have no right writing authoritatively on the subject – and in fact used to lose sleep over it – even though I had most of the content checked by experts.

The search results can be filtered by a number of tabs, currently:-

WHO approved sites
Hospitals
Research
Blogs
Favourites (sites I think are super awesome as opposed to just awesome).

Certain words and phrases trigger “promotions” – prominent links to selected sites.  For example any search  that has “scotland” in it shows a promotion for the main Scottish vaccination website for parents.

Update: ncbi/pubmed etc are not included because they list some seriously crappy studies that can be cherry picked.  Wikipedia is not included because it tended to dominate.

Update: Sadly, had to remove the IoM site because they post the anti-vax content of meetings with anti-vaxxers on their site without context! – which made it look like the IoM endorse the AV nonsense posted. Also had to remove some official Canadian Government health sites because weirdly they were overtly pro homeopathy!