Packagecom.lookbackon.ds
Classpublic class NumberBoard
InheritanceNumberBoard Inheritance Object

The numbers in this array are labels on the winnable n-in-a-row areas of the board. This is useful so that when a piece is dropped into an arbitrary board position, the algorithm can determine very quickly which n-in-a-row areas have become more likely destined for a win for the player, and, as importantly, which n-in-a-row areas are no longer possibilities for the opposing player. The numbers in the map[x][y] array are indexes into a pair of parallel single-dimensional arrays which keep track of how likely each n-in-a-row area is to be the winning area for each player. I call this the stats array. The "score" of a player is merely the sum of the stats array of the player. Subtracting one score from another determines how well a player is doing relative to the opposing player. You throw these numbers into your general run-of-the-mill minimax algorithm, throw in some alpha-beta cutoff logic for efficiency, and that, in a nutshell, is the secret to my algorithm. The original connect-4 algorithm created by Keith Pomakis(pomakis.at.pobox.com),aslo I(youngwelle.at.gmail.com) get this right to translate to AS3 version.

See also

http://www.pomakis.com/c4/


Public Properties
 PropertyDefined By
  backwardDiagonalLabels : Array
[read-only]
NumberBoard
  forwardDiagonalLabels : Array
[read-only]
NumberBoard
  horizontalLabels : Array
[read-only]
NumberBoard
  magicWinNumber : uint
[read-only]
NumberBoard
  numOfWinPlaces : int
[read-only] This function returns the number of possible win positions on a board of dimensions x by y with n being the number of pieces required in a row in order to win.
NumberBoard
  verticalLabels : Array
[read-only]
NumberBoard
  z : int
[read-only] Each n-in-a-row area on the board in which a winning connection can be made is given a unique number from 0 to z-1.
NumberBoard
Public Methods
 MethodDefined By
  
NumberBoard(x:int, y:int, n:int, h:Boolean, v:Boolean, f:Boolean, b:Boolean)
A magic number board data structure, mixed number labels' permutation and combination.
NumberBoard
  
getConnex(board:Array2, len:int, pattern:Function):Array
Should keep the providing board as the same size of numberboard.
NumberBoard
  
hasConnex(x:int, y:int, ref:Array, dir:String):Boolean
The referenced source's connex determined by number board's label with direction and the length of connection;
NumberBoard
  
toString():String
NumberBoard
Protected Methods
 MethodDefined By
  
NumberBoard
  
NumberBoard
  
NumberBoard
  
setupMap():void
an array in which each element is a list specifying, for each corresponding board space, which n-in-a-row areas it is part of.
NumberBoard
  
NumberBoard
Public Constants
 ConstantDefined By
  BACKWARD_DIAGONAL : String = B
[static]
NumberBoard
  FORWARD_DIAGONAL : String = F
[static]
NumberBoard
  HORIZONTAL : String = H
[static]
NumberBoard
  VERTICAL : String = V
[static]
NumberBoard
Property Detail
backwardDiagonalLabelsproperty
backwardDiagonalLabels:Array  [read-only]


Implementation
    public function get backwardDiagonalLabels():Array
forwardDiagonalLabelsproperty 
forwardDiagonalLabels:Array  [read-only]


Implementation
    public function get forwardDiagonalLabels():Array
horizontalLabelsproperty 
horizontalLabels:Array  [read-only]


Implementation
    public function get horizontalLabels():Array
magicWinNumberproperty 
magicWinNumber:uint  [read-only]


Implementation
    public function get magicWinNumber():uint
numOfWinPlacesproperty 
numOfWinPlaces:int  [read-only]

This function returns the number of possible win positions on a board of dimensions x by y with n being the number of pieces required in a row in order to win.


Implementation
    public function get numOfWinPlaces():int
verticalLabelsproperty 
verticalLabels:Array  [read-only]


Implementation
    public function get verticalLabels():Array
zproperty 
z:int  [read-only]

Each n-in-a-row area on the board in which a winning connection can be made is given a unique number from 0 to z-1. Each space on the board is told which n-in-a-row areas it is part of. This is done with the array...


Implementation
    public function get z():int
Constructor Detail
NumberBoard()Constructor
public function NumberBoard(x:int, y:int, n:int, h:Boolean, v:Boolean, f:Boolean, b:Boolean)

A magic number board data structure, mixed number labels' permutation and combination.

Parameters
x:int — the width of map.
 
y:int — the height of map.
 
n:int — the connection number in some direction.
 
h:Boolean — whether horizontal connection.
 
v:Boolean — whether vertical connection.
 
f:Boolean — whether forward diagonal connection.
 
b:Boolean — whether backward diagonal connection.
Method Detail
backwardDiagonalFillIn()method
protected function backwardDiagonalFillIn():void

forwardDiagonalFillIn()method 
protected function forwardDiagonalFillIn():void

getConnex()method 
public function getConnex(board:Array2, len:int, pattern:Function):Array

Should keep the providing board as the same size of numberboard. Partial with flag object to indentify the connex elements. Return the connex results,such as z[0]-horizontally,z[1]-vertically,z[2]-forwardDiagonal,z[3]-backwardDiagonal

Parameters

board:Array2 — the board resource;
 
len:int — the length of connex;
 
pattern:Function — the connex's match pattern function with parameter such as('RRR','BBB','RBR','RRB'...);

Returns
Array — the calculated connections categoried by array;
hasConnex()method 
public function hasConnex(x:int, y:int, ref:Array, dir:String):Boolean

The referenced source's connex determined by number board's label with direction and the length of connection;

Parameters

x:int — the x coordinate.
 
y:int — the y coordinate.
 
ref:Array — the referenced source.
 
dir:String — the direction label.

Returns
Boolean — whether the connex label on the direction existed.
horizontalFillIn()method 
protected function horizontalFillIn():void

setupMap()method 
protected function setupMap():void

an array in which each element is a list specifying, for each corresponding board space, which n-in-a-row areas it is part of.

toString()method 
public function toString():String

Returns
String
verticalFillIn()method 
protected function verticalFillIn():void

Constant Detail
BACKWARD_DIAGONALConstant
public static const BACKWARD_DIAGONAL:String = B

FORWARD_DIAGONALConstant 
public static const FORWARD_DIAGONAL:String = F

HORIZONTALConstant 
public static const HORIZONTAL:String = H

VERTICALConstant 
public static const VERTICAL:String = V