Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

cgsuite
Class CanonicalGame  view CanonicalGame download CanonicalGame.java

java.lang.Object
  extended bycgsuite.CanonicalGame
All Implemented Interfaces:
java.lang.Comparable, Game, java.io.Serializable, StopperGame

public final class CanonicalGame
extends java.lang.Object
implements StopperGame, java.lang.Comparable

A short combinatorial game in canonical form. Every option of a CanonicalGame is again a CanonicalGame. In addition, it is guaranteed that:

The CanonicalGame class guarantees that at most one copy of each CanonicalGame resides in memory at any given time. This is a global constraint that permits a large number of space and time optimizations. In order to enforce this constraint, CanonicalGame contains no public constructors. To construct a CanonicalGame, use one of the from* methods. The from* method will return a reference to the specified object, if it already exists; otherwise it will privately construct a new one.

Version:
$Revision: 1.18 $ $Date: 2003/12/12 20:38:57 $

Nested Class Summary
private static class CanonicalGame.NusKey
           
private static class CanonicalGame.OperationKey
           
private static class CanonicalGame.OptionsKey
           
 
Field Summary
private  int birthday
           
private static java.util.Map gameCache
           
private  int id
           
private static java.util.List idCatalog
           
private  CanonicalGame inverse
           
private  CanonicalGame[] leftOptions
           
private static CanonicalGame MINUS_TWO
           
private static int nextID
           
private static java.util.Map nusCache
           
private  CanonicalGame.NusKey nusKey
           
private  CanonicalGame[] rightOptions
           
static CanonicalGame STAR
          A static reference to the game *.
private  Thermograph thermograph
           
private static CanonicalGame TWO
           
private static CanonicalGame UP
           
private static CanonicalGame UP_STAR
           
static CanonicalGame ZERO
          A static reference to the game 0.
 
Fields inherited from interface cgsuite.Game
SIMPLIFY_COOL, SIMPLIFY_FREEZE, SIMPLIFY_HEAT, SIMPLIFY_ORDINAL_SUM_G, SIMPLIFY_ORDINAL_SUM_H, SIMPLIFY_OVERHEAT, SIMPLIFY_PRODUCT_G, SIMPLIFY_PRODUCT_U, SIMPLIFY_SUM
 
Constructor Summary
private CanonicalGame()
           
 
Method Summary
private static boolean arrayContains(CanonicalGame[] array, CanonicalGame g)
           
private static CanonicalGame[] bypassReversibleOptionsL(CanonicalGame[] leftOptionArray, CanonicalGame[] rightOptionArray)
           
private static CanonicalGame[] bypassReversibleOptionsR(CanonicalGame[] leftOptionArray, CanonicalGame[] rightOptionArray)
           
 CanonicalGame canonicalize()
          Returns this.
 int compareTo(java.lang.Object obj)
          Compares this object to another CanonicalGame based on an an arbitrary, instance-dependent total ordering.
 CanonicalGame conwayProduct(CanonicalGame h)
          Calculates the Conway product of this game and h.
private  CanonicalGame cool(CanonicalGame t)
           
 CanonicalGame cool(DyadicRational temperature)
          Cools this game by temperature and returns the resulting CanonicalGame.
static java.lang.String createReport()
           
private  void detectShortcuts()
           
 Game dissociate()
          Calculates the Norton thermal dissociation of this game.
private  boolean dominantAtTemperature(Thermograph[] therms, boolean left, int i, DyadicRational temp)
           
private static void eliminateDominatedOptions(CanonicalGame[] options, boolean eliminateSmallerOptions)
           
private static void eliminateDuplicateOptions(CanonicalGame[] options)
           
 boolean equals(java.lang.Object obj)
          Determine whether this Object is semantically equal to another Object.
private  CanonicalGame[] findOrthodoxOptions(CanonicalGame[] options, boolean left)
           
 CanonicalGame freeze()
          Cools this game by its temperature and returns the resulting CanonicalGame.
private static CanonicalGame fromCanonicalOptions(CanonicalGame[] leftOptionArray, CanonicalGame[] rightOptionArray)
           
static CanonicalGame fromGNth(CanonicalGame g, int n)
          Returns the canonical form of gn.
static CanonicalGame fromGToNth(CanonicalGame g, int n)
          Returns the canonical form of g→n.
static CanonicalGame fromID(int id)
           
static CanonicalGame fromInteger(int number)
          Returns the CanonicalGame corresponding to number.
static CanonicalGame fromMiny(CanonicalGame g)
          Returns the CanonicalGame corresponding to miny-g.
static CanonicalGame fromNumberUpStar(DyadicRational number, int upMultiple, int nimber)
          Returns a CanonicalGame equal to the sum of a number, a nimber, and arbitrarily many copies of up.
(package private) static CanonicalGame fromOptions(CanonicalGame[] leftOptionArray, CanonicalGame[] rightOptionArray)
           
static CanonicalGame fromOptions(CanonicalGame leftOption, CanonicalGame rightOption)
          Returns a CanonicalGame based on a single left option and a single right option.
static CanonicalGame fromOptions(java.util.Collection leftOptions, java.util.Collection rightOptions)
          Returns a CanonicalGame based on collections of options.
static CanonicalGame fromSuperstar(int[] exponents)
          Returns the superstar with the specified exponents.
static CanonicalGame fromTiny(CanonicalGame g)
          Returns the CanonicalGame corresponding to tiny-g.
private  boolean geqArrays(CanonicalGame[] leftOptionArray, CanonicalGame[] rightOptionArray)
           
 CanonicalGame getAtomicWeight()
          Calculates the atomic weight of this game.
 int getBirthday()
          Gets the birthday of this game.
private  int getFarStar()
           
 int getID()
           
 CanonicalGame[] getIncentives()
          Gets the incentives of this game.
 Game getInverse()
          Gets the inverse of this game.
 CanonicalGame[] getLeftIncentives()
          Gets the left incentives of this game.
 CanonicalGame getLeftOption(int n)
          Gets the nth left option of this game.
 java.util.Collection getLeftOptions()
          Gets a Collection containing all left options of this game.
 Stop getLeftStop()
          Calculates the left stop of this game.
 DyadicRational getMean()
          Calculates the mean value of this game.
private  CanonicalGame getNaiveAtomicWeight()
           
 int getNimberPart()
          Gets the nimber part of a number-up-star.
 DyadicRational getNumberPart()
          Gets the number part of a number-up-star.
 int getNumLeftOptions()
          Gets the number of left options of this game.
 int getNumRightOptions()
          Gets the number of right options of this game.
 CanonicalGame getRcf()
          Calculates the reduced canonical form of this game.
 CanonicalGame[] getRightIncentives()
          Gets the right incentives of this game.
 CanonicalGame getRightOption(int n)
          Gets the nth right option of this game.
 java.util.Collection getRightOptions()
          Gets a Collection containing all right options of this game.
 Stop getRightStop()
          Calculates the right stop of this game.
private  CanonicalGame getStarProjection()
           
 DyadicRational getTemperature()
          Calculates the temperature of this game.
 Thermograph getThermograph()
          Gets the thermograph of this game.
 int getUpMultiplePart()
          Gets the up multiple part of a number-up-star.
 CanonicalGame heat(CanonicalGame t)
          Heats this game by t and returns the resulting CanonicalGame.
 boolean isAllSmall()
          Returns true if this game is all small.
 boolean isInfinitesimal()
          Tests whether this game is an infinitesimal.
 boolean isInteger()
          Tests whether this game is an integer.
 boolean isNimber()
          Tests whether this game is a nimber.
 boolean isNumber()
          Tests whether this game is a number.
 boolean isNumberTiny()
          Tests whether this game is equal to a number plus a tiny.
 boolean isNumberUpStar()
          Tests whether this game is the sum of a number, a nimber, and a multiple of up.
 boolean isShortGame()
          Returns true if this game is a short game.
 boolean isStar()
          Tests whether this game is equal to STAR 55 .
 boolean isSwitch()
          Tests whether this game is a switch.
 boolean isZero()
          Tests whether this game is equal to ZERO 55 .
 boolean leq(CanonicalGame h)
           
private  boolean leqArrays(CanonicalGame[] leftOptionArray, CanonicalGame[] rightOptionArray)
           
 CanonicalGame minus(CanonicalGame h)
          Calculates the difference of this game and h and returns the resulting CanonicalGame.
 CanonicalGame nortonProduct(CanonicalGame u)
          Calculates the Norton product of this game by the unit u.
 CanonicalGame orthodoxForm()
           
 CanonicalGame[] orthodoxLeftOptions()
           
 CanonicalGame[] orthodoxRightOptions()
           
 CanonicalGame overheat(CanonicalGame s, CanonicalGame t)
          Overheats this game from s to t and returns the resulting CanonicalGame.
private static CanonicalGame[] pack(CanonicalGame[] options)
           
 CanonicalGame plus(CanonicalGame h)
          Calculates the sum of this game and h and returns the resulting CanonicalGame.
 Game simplify()
          Calculates a simplified form of this game.
 Game simplifyExpression(int simplifyType, Game[] args)
          Calculates a simplified form of the indicated expression.
 java.lang.String toString()
          Convert this Object to a human-readable String.
private  java.lang.String toString(int[] height, boolean bracketAll)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nusCache

private static java.util.Map nusCache

gameCache

private static java.util.Map gameCache

idCatalog

private static java.util.List idCatalog

nextID

private static int nextID

ZERO

public static CanonicalGame ZERO
A static reference to the game 0.


STAR

public static CanonicalGame STAR
A static reference to the game *.


TWO

private static CanonicalGame TWO

MINUS_TWO

private static CanonicalGame MINUS_TWO

UP

private static CanonicalGame UP

UP_STAR

private static CanonicalGame UP_STAR

leftOptions

private CanonicalGame[] leftOptions

rightOptions

private CanonicalGame[] rightOptions

nusKey

private CanonicalGame.NusKey nusKey

birthday

private int birthday

id

private int id

inverse

private CanonicalGame inverse

thermograph

private Thermograph thermograph
Constructor Detail

CanonicalGame

private CanonicalGame()
Method Detail

fromID

public static CanonicalGame fromID(int id)

fromInteger

public static CanonicalGame fromInteger(int number)
Returns the CanonicalGame corresponding to number.


fromNumberUpStar

public static CanonicalGame fromNumberUpStar(DyadicRational number,
                                             int upMultiple,
                                             int nimber)
Returns a CanonicalGame equal to the sum of a number, a nimber, and arbitrarily many copies of up. Specifically, the return value is equal to the sum of:
  • The dyadic rational number,
  • upMultiple copies of up, and
  • The nimber of order nimber.
For example, fromNumberUpStar(DyadicRational.ZERO, -2, 1) would return double-down-star.


fromTiny

public static CanonicalGame fromTiny(CanonicalGame g)
Returns the CanonicalGame corresponding to tiny-g. The return value is equal to the canonical form of {0||0|-g}.


fromMiny

public static CanonicalGame fromMiny(CanonicalGame g)
Returns the CanonicalGame corresponding to miny-g. The return value is equal to the canonical form of {g|0||0}.


fromGNth

public static CanonicalGame fromGNth(CanonicalGame g,
                                     int n)
Returns the canonical form of gn. g must be of the form {0|h}.

gn is defined as follows:

g0 = -h
gn = {0|h-g→n-1} = {0|-g0-g1-...-gn-1}


fromGToNth

public static CanonicalGame fromGToNth(CanonicalGame g,
                                       int n)
Returns the canonical form of g→n. g must be of the form {0|h}.

g→n is defined as follows:

g→0 = 0
g→n = {g→n-1|h} = g1+g2+...+gn-1


fromSuperstar

public static CanonicalGame fromSuperstar(int[] exponents)
Returns the superstar with the specified exponents. This is defined as

a,b,c,... = {0,*,...,*m | *a,*b,*c,...} where m = mex{a,b,c,...}.


fromOptions

public static CanonicalGame fromOptions(java.util.Collection leftOptions,
                                        java.util.Collection rightOptions)
Returns a CanonicalGame based on collections of options. The specified options need not be in canonical form; however, fromOptions will canonicalize them by calling each option's canonicalize method.


fromOptions

static CanonicalGame fromOptions(CanonicalGame[] leftOptionArray,
                                 CanonicalGame[] rightOptionArray)

fromCanonicalOptions

private static CanonicalGame fromCanonicalOptions(CanonicalGame[] leftOptionArray,
                                                  CanonicalGame[] rightOptionArray)

fromOptions

public static CanonicalGame fromOptions(CanonicalGame leftOption,
                                        CanonicalGame rightOption)
Returns a CanonicalGame based on a single left option and a single right option. This is a convenience method equivalent to fromOptions(Collections.singleton(leftOption), Collections.singleton(rightOption)).


compareTo

public int compareTo(java.lang.Object obj)
Compares this object to another CanonicalGame based on an an arbitrary, instance-dependent total ordering.

Specified by:
compareTo in interface java.lang.Comparable

equals

public boolean equals(java.lang.Object obj)
Description copied from class: java.lang.Object
Determine whether this Object is semantically equal to another Object.

There are some fairly strict requirements on this method which subclasses must follow:

  • It must be transitive. If a.equals(b) and b.equals(c), then a.equals(c) must be true as well.
  • It must be symmetric. a.equals(b) and b.equals(a) must have the same value.
  • It must be reflexive. a.equals(a) must always be true.
  • It must be consistent. Whichever value a.equals(b) returns on the first invocation must be the value returned on all later invocations.
  • a.equals(null) must be false.
  • It must be consistent with hashCode(). That is, a.equals(b) must imply a.hashCode() == b.hashCode(). The reverse is not true; two objects that are not equal may have the same hashcode, but that has the potential to harm hashing performance.

This is typically overridden to throw a java.lang.ClassCastException if the argument is not comparable to the class performing the comparison, but that is not a requirement. It is legal for a.equals(b) to be true even though a.getClass() != b.getClass(). Also, it is typical to never cause a java.lang.NullPointerException.

In general, the Collections API (java.util) use the equals method rather than the == operator to compare objects. However, java.util.IdentityHashMap is an exception to this rule, for its own good reasons.

The default implementation returns this == o.


toString

private java.lang.String toString(int[] height,
                                  boolean bracketAll)

toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).


getLeftOptions

public java.util.Collection getLeftOptions()
Description copied from interface: Game
Gets a Collection containing all left options of this game.

Specified by:
getLeftOptions in interface Game

getRightOptions

public java.util.Collection getRightOptions()
Description copied from interface: Game
Gets a Collection containing all right options of this game.

Specified by:
getRightOptions in interface Game

getInverse

public Game getInverse()
Description copied from interface: Game
Gets the inverse of this game.

Specified by:
getInverse in interface Game

isShortGame

public boolean isShortGame()
Description copied from interface: Game
Returns true if this game is a short game.

Specified by:
isShortGame in interface Game

canonicalize

public CanonicalGame canonicalize()
Returns this.

Specified by:
canonicalize in interface Game

simplify

public Game simplify()
Description copied from interface: Game
Calculates a simplified form of this game. The simplified form need not be canonical or "simplest." This method is used by the Combinatorial Game Suite interface to determine the best way to display output. As an example, the ExplicitGame given by {1,1/2|-1} would be simplified to the CanonicalGame given by {1|-1}.

There are two key differences between simplify and canonicalize 55 . First, canonicalize always returns a CanonicalGame, while simplify may return any game at all. Second, simplify is called automatically by the Combinatorial Game Suite user interface when output is ready to be displayed, while canonicalize is usually called only by explicit user request. For this reason, it is advisable for simplify to execute rapidly in most circumstances.

It is permissible for simplify to return this when no obvious simplifications are possible, but it should never return null.

Specified by:
simplify in interface Game

simplifyExpression

public Game simplifyExpression(int simplifyType,
                               Game[] args)
Description copied from interface: Game
Calculates a simplified form of the indicated expression. This method is for advanced users and is rarely needed by plug-ins. Most implementations of Game should simply return null.

Specified by:
simplifyExpression in interface Game

getID

public int getID()

getBirthday

public int getBirthday()
Gets the birthday of this game. The birthday of G is defined recursively by

Birthday(G) = Max(Birthday(GL), Birthday(GR)) + 1.


cool

public CanonicalGame cool(DyadicRational temperature)
Cools this game by temperature and returns the resulting CanonicalGame.


cool

private CanonicalGame cool(CanonicalGame t)

freeze

public CanonicalGame freeze()
Cools this game by its temperature and returns the resulting CanonicalGame. This is a convenience method and is equivalent to cool(getTemperature()).


heat

public CanonicalGame heat(CanonicalGame t)
Heats this game by t and returns the resulting CanonicalGame.

Heating by an arbitrary CanonicalGame is permitted. Note that heating a game by a negative number corresponds to the "unheating" operation.


overheat

public CanonicalGame overheat(CanonicalGame s,
                              CanonicalGame t)
Overheats this game from s to t and returns the resulting CanonicalGame.

Overheating by arbitrary CanonicalGames is permitted.


plus

public CanonicalGame plus(CanonicalGame h)
Calculates the sum of this game and h and returns the resulting CanonicalGame.


minus

public CanonicalGame minus(CanonicalGame h)
Calculates the difference of this game and h and returns the resulting CanonicalGame.

minus(h) is equivalent to plus((CanonicalGame) h.getInverse()).


getLeftStop

public Stop getLeftStop()
Calculates the left stop of this game.

Specified by:
getLeftStop in interface StopperGame

getRightStop

public Stop getRightStop()
Calculates the right stop of this game.

Specified by:
getRightStop in interface StopperGame

getFarStar

private int getFarStar()

getAtomicWeight

public CanonicalGame getAtomicWeight()
Calculates the atomic weight of this game. If this game is all small, the standard definition of atomic weight is used. Otherwise, we use the following algorithm, suggested by David Wolfe:

Apply the standard definition of atomic weight, even if the game is not all small. Then check that the difference between g and G.↑ is sufficiently small. Specifically, check that

g-e <= G.^ <= g+e

where e is the difference between ↑* and a long kite. The value G will be returned regardless, and a warning will be generated if the check fails.


getNaiveAtomicWeight

private CanonicalGame getNaiveAtomicWeight()

dissociate

public Game dissociate()
Calculates the Norton thermal dissociation of this game.

Every game is equal to its mean value plus the sum of heated infinitesimals, and this representation is unique.


getStarProjection

private CanonicalGame getStarProjection()

getRcf

public CanonicalGame getRcf()
Calculates the reduced canonical form of this game. The reduced canonical form of g is the simplest game infinitesimally close to g.


leq

public boolean leq(CanonicalGame h)

getLeftIncentives

public CanonicalGame[] getLeftIncentives()
Gets the left incentives of this game.


getRightIncentives

public CanonicalGame[] getRightIncentives()
Gets the right incentives of this game.


getIncentives

public CanonicalGame[] getIncentives()
Gets the incentives of this game.


nortonProduct

public CanonicalGame nortonProduct(CanonicalGame u)
Calculates the Norton product of this game by the unit u.

If this game is an integer n, the result is equal to the sum of n copies of u. A binary sum algorithm is used for efficient calculation when n is large.

If this game is not an integer, the result is equal to...


conwayProduct

public CanonicalGame conwayProduct(CanonicalGame h)
Calculates the Conway product of this game and h. The Conway product is defined and discussed in ONAG.


isAllSmall

public boolean isAllSmall()
Returns true if this game is all small.


orthodoxLeftOptions

public CanonicalGame[] orthodoxLeftOptions()

orthodoxRightOptions

public CanonicalGame[] orthodoxRightOptions()

orthodoxForm

public CanonicalGame orthodoxForm()

findOrthodoxOptions

private CanonicalGame[] findOrthodoxOptions(CanonicalGame[] options,
                                            boolean left)

dominantAtTemperature

private boolean dominantAtTemperature(Thermograph[] therms,
                                      boolean left,
                                      int i,
                                      DyadicRational temp)

getNumLeftOptions

public int getNumLeftOptions()
Gets the number of left options of this game.


getLeftOption

public CanonicalGame getLeftOption(int n)
Gets the nth left option of this game.


getNumRightOptions

public int getNumRightOptions()
Gets the number of right options of this game.


getRightOption

public CanonicalGame getRightOption(int n)
Gets the nth right option of this game.


isZero

public boolean isZero()
Tests whether this game is equal to ZERO 55 .


isStar

public boolean isStar()
Tests whether this game is equal to STAR 55 .


isNumber

public boolean isNumber()
Tests whether this game is a number.


isInteger

public boolean isInteger()
Tests whether this game is an integer.


isNumberUpStar

public boolean isNumberUpStar()
Tests whether this game is the sum of a number, a nimber, and a multiple of up.


isNimber

public boolean isNimber()
Tests whether this game is a nimber.


isInfinitesimal

public boolean isInfinitesimal()
Tests whether this game is an infinitesimal.


isNumberTiny

public boolean isNumberTiny()
Tests whether this game is equal to a number plus a tiny.


isSwitch

public boolean isSwitch()
Tests whether this game is a switch. A switch is a game with the same number of left and right options, in which every left option is the inverse of a right option.


getNumberPart

public DyadicRational getNumberPart()
Gets the number part of a number-up-star. Note that isNumberUpStar() must be true in order to call this method.


getUpMultiplePart

public int getUpMultiplePart()
Gets the up multiple part of a number-up-star. Note that isNumberUpStar() must be true in order to call this method.


getNimberPart

public int getNimberPart()
Gets the nimber part of a number-up-star. Note that isNumberUpStar() must be true in order to call this method.


createReport

public static java.lang.String createReport()

leqArrays

private boolean leqArrays(CanonicalGame[] leftOptionArray,
                          CanonicalGame[] rightOptionArray)

geqArrays

private boolean geqArrays(CanonicalGame[] leftOptionArray,
                          CanonicalGame[] rightOptionArray)

arrayContains

private static boolean arrayContains(CanonicalGame[] array,
                                     CanonicalGame g)

eliminateDuplicateOptions

private static void eliminateDuplicateOptions(CanonicalGame[] options)

eliminateDominatedOptions

private static void eliminateDominatedOptions(CanonicalGame[] options,
                                              boolean eliminateSmallerOptions)

bypassReversibleOptionsL

private static CanonicalGame[] bypassReversibleOptionsL(CanonicalGame[] leftOptionArray,
                                                        CanonicalGame[] rightOptionArray)

bypassReversibleOptionsR

private static CanonicalGame[] bypassReversibleOptionsR(CanonicalGame[] leftOptionArray,
                                                        CanonicalGame[] rightOptionArray)

pack

private static CanonicalGame[] pack(CanonicalGame[] options)

detectShortcuts

private void detectShortcuts()

getMean

public DyadicRational getMean()
Calculates the mean value of this game.


getTemperature

public DyadicRational getTemperature()
Calculates the temperature of this game.


getThermograph

public Thermograph getThermograph()
Gets the thermograph of this game.