GeneThello Home

net.sf.genethello.applet
Class Game

java.lang.Object
  extended by net.sf.genethello.applet.Game
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.util.EventListener, IGame

public class Game
extends java.lang.Object
implements IGame, java.beans.PropertyChangeListener

Console program to play othello evolved using genetic algorithm.

Author:
Bowo

Field Summary
 GameTheory blackBrain
          Brain of black player.
 IBoard board
          Board used in the game.
 GameTheory whiteBrain
          Brain of white player.
 
Constructor Summary
Game(Chromosome black, Chromosome white, int blackTime, int whiteTime, IMessage gui, boolean network)
          Creates a new instance of Game.
 
Method Summary
 void cancelWorker()
          Cancels thinking process by brain.
 int getBlackDepth()
          Gets thinking depth of black player.
 int getBlackTime()
          Gets time quota of black player in seconds.
 IBoard getBoard()
          Gets board.
 int getCol(java.lang.String str)
          Gets column number from column notation, e.g.
 long getElapsed()
          Gets thinking time of last move.
 int getFlips()
          Get the last number of flipped discs.
 int getPlayer(int index)
          Gets player (MAN or MACHINE) for each color (BLACK or WHITE)
 int getResult()
          Gets result of game, positive value indicates black wins with result number of discs, otherwise white wins.
 int getScore()
          Gets score of last best move.
 int getStep()
          Gets number of step.
 Move[][] getTranscript()
          Gets transcript of game in matrix of moves, e.g.

(BLACK)(WHITE) d3c3 b3e3 ....
 int getTurn()
          Gets current color fo player to turn.
 int getWhiteDepth()
          Gets thinking depth of white player.
 int getWhiteTime()
          Gets time quota of white player in seconds.
 void mainRoutine(Move mv)
          Main routine of the game while using graphical user interface.
static java.lang.String moveString(int idx)
          Construct coordinate notation of move from index of board, e.g.
static java.lang.String moveString(int col, int row)
          Construct coordinate notation of move from column and row number, e.g.
static void print(java.lang.String msg)
          Prints message to standar output.
 void printBoard()
          Prints current board position to standard output.
static void printf(java.lang.String fmt, int arg)
          Print formmated integer to standard output.
static void printf(java.lang.String fmt, java.lang.String arg)
          Prints formatted message to standard output.
 void propertyChange(java.beans.PropertyChangeEvent evt)
          Handle of PropertyChangeEvent, gets fired after each move of MAN and MACHINE in mainRoutine when using GUI.
 void replayingRoutine(Move mv)
          Main routine of the game while replaying game.
 void setBlackDepth(int depth)
          Sets thinking depth of black player.
 void setBlackTime(int blackTime)
          Sets time quota of black player in seconds.
 void setPlayer(int index, int player)
          Sets player (MAN or MACHINE) for each color (BLACK or WHITE)
 void setTranscript(Move[][] transcript)
          Sets transcript of game in Move arrays.
 void setTurn(int turn)
          Sets current color turn to play.
 void setWhiteDepth(int depth)
          Sets thinking depth of white player.
 void setWhiteTime(int whiteTime)
          Sets time quota of white player in seconds.
 void startGUI()
          Starts game using graphical user interface.
 void startReplay(Move[][] tr)
          Starts replaying game using graphical user interface.
 java.lang.String toTranscript()
          Constructs transcript of game in string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

blackBrain

public GameTheory blackBrain
Brain of black player.


whiteBrain

public GameTheory whiteBrain
Brain of white player.


board

public IBoard board
Board used in the game.

Constructor Detail

Game

public Game(Chromosome black,
            Chromosome white,
            int blackTime,
            int whiteTime,
            IMessage gui,
            boolean network)
Creates a new instance of Game.

Parameters:
black - chromosome of black player
white - chromosome of white player
blackTime - time quota for black player in seconds
whiteTime - time quota for white player in seconds
gui - GUI to print message
network - if true use network, or not otherwise
Method Detail

startGUI

public void startGUI()
Starts game using graphical user interface.


startReplay

public void startReplay(Move[][] tr)
Starts replaying game using graphical user interface.


mainRoutine

public void mainRoutine(Move mv)
Main routine of the game while using graphical user interface.

Parameters:
mv - move

replayingRoutine

public void replayingRoutine(Move mv)
Main routine of the game while replaying game.

Parameters:
mv - move

setPlayer

public void setPlayer(int index,
                      int player)
Sets player (MAN or MACHINE) for each color (BLACK or WHITE)

Parameters:
index - color of disc: Game.BLACK, Game.WHITE
player - player: Game.MAN, Game.MACHINE

getPlayer

public int getPlayer(int index)
Gets player (MAN or MACHINE) for each color (BLACK or WHITE)

Parameters:
index - color of disc: Game.BLACK, Game.WHITE
Returns:
player, 0:MAN, 1:MACHINE

setTurn

public void setTurn(int turn)
Sets current color turn to play.

Specified by:
setTurn in interface IGame
Parameters:
turn - color to play: Game.BLACK, Game.WHITE

print

public static void print(java.lang.String msg)
Prints message to standar output.

Parameters:
msg - message to print

printf

public static void printf(java.lang.String fmt,
                          java.lang.String arg)
Prints formatted message to standard output.

Parameters:
fmt - format
arg - message to print

printf

public static void printf(java.lang.String fmt,
                          int arg)
Print formmated integer to standard output.

Parameters:
fmt - format
arg - integer to print

getBlackDepth

public int getBlackDepth()
Gets thinking depth of black player.

Returns:
thinking depth

getWhiteDepth

public int getWhiteDepth()
Gets thinking depth of white player.

Returns:
thinking depth

setBlackDepth

public void setBlackDepth(int depth)
Sets thinking depth of black player.

Parameters:
depth - thinking depth

setWhiteDepth

public void setWhiteDepth(int depth)
Sets thinking depth of white player.

Parameters:
depth - thinking depth

moveString

public static java.lang.String moveString(int col,
                                          int row)
Construct coordinate notation of move from column and row number, e.g. a1, b2, c3.. etc.

Parameters:
col - column number of move
row - row number of move
Returns:
coordinate notation

moveString

public static java.lang.String moveString(int idx)
Construct coordinate notation of move from index of board, e.g. a1, b2, c3.. etc.

Parameters:
idx - index of board
Returns:
coordinate notation

getTurn

public int getTurn()
Gets current color fo player to turn.

Specified by:
getTurn in interface IGame
Returns:
color to turn: Game.BLACK, Game.WHITE

getScore

public int getScore()
Gets score of last best move.

Returns:
score

getElapsed

public long getElapsed()
Gets thinking time of last move.

Returns:
thinking time

printBoard

public void printBoard()
Prints current board position to standard output.

Specified by:
printBoard in interface IGame

getCol

public int getCol(java.lang.String str)
Gets column number from column notation, e.g. a, b, c etc.

Parameters:
str - column notation
Returns:
column number

cancelWorker

public void cancelWorker()
Cancels thinking process by brain.


getFlips

public int getFlips()
Get the last number of flipped discs.

Returns:
number of flipped discs

getTranscript

public Move[][] getTranscript()
Gets transcript of game in matrix of moves, e.g.

(BLACK)(WHITE)
d3c3
b3e3
....

Returns:
transcript of game

toTranscript

public java.lang.String toTranscript()
Constructs transcript of game in string.

Returns:
transcript of game

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
Handle of PropertyChangeEvent, gets fired after each move of MAN and MACHINE in mainRoutine when using GUI.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
evt - event

getBoard

public IBoard getBoard()
Gets board.

Specified by:
getBoard in interface IGame
Returns:
board

setBlackTime

public void setBlackTime(int blackTime)
Sets time quota of black player in seconds.


setWhiteTime

public void setWhiteTime(int whiteTime)
Sets time quota of white player in seconds.


getResult

public int getResult()
Gets result of game, positive value indicates black wins with result number of discs, otherwise white wins.

Returns:
result of game

getBlackTime

public int getBlackTime()
Gets time quota of black player in seconds.

Returns:
time quota of black player

getWhiteTime

public int getWhiteTime()
Gets time quota of white player in seconds.

Returns:
time quota of white player

setTranscript

public void setTranscript(Move[][] transcript)
Sets transcript of game in Move arrays.

Parameters:
transcript - transcript of game

getStep

public int getStep()
Gets number of step.

Returns:
step number

GeneThello Home

Get GeneThello: Genetic Othello at SourceForge.net. Fast, secure and Free Open Source software downloads