TesujiGoFramework/Neighbours

Sub-page of TesujiGoFramework

Neighbours

I've squeezed this into the 'advanced' section, even though it's very simple in principle. What the Neighours class does is keeping track how many occupied neighbours a point has. And it also keeps record how many are Black and how many are White.

What I want to illustrate here is the intended use of BoardModel and BoardModelListener. In the previous section ChainAdministration you can already see that it keeps a BoardModel. Other classes can register there so that whenever something changes on the board they get a notification. ChainAdministration was designed to update its structures incrementally to save work. This we'll see more often as a pattern. But when computing something incrementally, we'll need to record what changed with respect to the previous situation. This is where the BoardModel pattern comes in. The relation between the board kept by ChainAdministration and the Neighbours datastructure is pretty obvious. And the fact that the Neighbours can be updated solely based on local changes to the board as well. So by simply listening to changes in the BoardModel of ChainAdministration the Neighbours module can stay updated.

The relation will not always be so obvious, and not always as direct. These BoardModels will often be chained, so module B listens to changes in module A. Module C listens to changes in module B. Another module D may also listen to changes in module A again. And module E may listen to changes in both C and D. So we'll get a whole web of dependencies. But the source of origin will always be the board of stones, since that is ultimately the only information that everything is based on in the game of Go.

This may seem like a complicated way to update something as simple as a Neighbours data-structure. But as stated above, there will be many more modules that will be listening to changes to the board. So the mechanism is needed anyway. We can squeeze in the Neihbours at little extra cost.

The other thing I hope to accomplish with this structure is that it will become very easy to chain all kinds of different modules together. We could have different compositions for different purposes or even with completely different modules for different engines.


This is a copy of the living page "TesujiGoFramework/Neighbours" at Sensei's Library.
(OC) 2011 the Authors, published under the OpenContent License V1.0.
[Welcome to Sensei's Library!]
StartingPoints
ReferenceSection
About