[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: computer-go: Sharing Go modules: exchanging board-arrays



I've come to a decision on how I'd like to exchange board-arrays between my
modules. Below is the code for the interface that I have in mind. I think
it's both flexible enough to be used both for 1-dimensional arrays and
2-dimensional arrays and will pose little performance problems when all my
modules just only implement 1-dimensional arrays. It's still a compromise
and it makes a few assumptions about the actual representation of the board,
but that can't be helped.

It looks like I won't be able to finish the pattern-matching module before
the end of this weekend. After that I won't have any spare time for a little
while so there's plenty of time to get input from others on what they think
of this scheme. The other modules are just about ready, they don't need this
interface.

I don't think any Go programmer should rush and start using this scheme as
well, but if anyone is just starting they might think about using it so they
will get the full benefit from my modules in the future.

Here's the code for the ByteArray interface. Similar interfaces will be
defined for integers etc.

package Tesuji.games.go;

/**
 	Interface for defining an array for a Go program that
 	can be used both as a 1-dimensional array and as a
 	2-dimensional array.<br><br>

 	The rule is that the index in the 1-dimensional can be
 	computed from the 2-dimensional array as follows:<br>
 		<code>xy = x+y*getWidth()</code><br><br>

 	Notes:<lu>
 	<li>The first point is the 1,1 point and not the 0,0 point.</li>
 	<li>The size of the 1-dimensional array is always at least
 		getWidth()*(getWidth()+1)</li>
 	<li>For the moment these arrays are always considerad as read-only.
 		Therefore the behaviour of getSingleArray()[0] = 1 is
undefined.</li></lu>

 	<br><br>Creation date: (19-May-01 12:58:15 PM)<br><br>

	Copyright 2001 (c) Tesuji Software<br>
	All rights reserved.<br><br>

	@author: Mark
*/
public interface ByteArray
{
	/**
	 	Get an element from the array using a 1-dimensional coordinate.
	*/
	public byte get(int xy);

	/**
	 	Get an element from the array using a 2-dimensional coordinate.
	*/
	public byte get(int x, int y);

	/**
	 	Get the board-size for this array.
	*/
	public int getBoardSize();

	/**
	 	Get the array as a 2-dimensional array.
	*/
	public byte[][] getDoubleArray();

	/**
	 	Get the array as a 1-dimensional array.
	*/
	public byte[] getSingleArray();

	/**
	 	Get the width that is used to do the coordinate
	 	conversion between 1-dimensional and 2-dimensional.
	*/
	public int getWidth();
}