cs4099
Class Interpreter

java.lang.Object
  extended by cs4099.Interpreter

public class Interpreter
extends java.lang.Object

This class interprets an XML file for use in the main program. If the XML file does not conform to the expected format, an error message will be displayed.

The purpose of the code is to construct a root state from which a game is to be played.

Author:
David Newton
See Also:
State

Constructor Summary
Interpreter()
           
 
Method Summary
 boolean booleanRead(org.w3c.dom.NamedNodeMap piledata, java.lang.String property, boolean defaultvalue)
          Method to read a boolean property from the XML and to return it if it exists.
 boolean getBool(java.lang.String string)
          This method converts a String into a boolean, returning true if the contents of the String are equal to "true", and false if the contents are anything else.
 int intRead(org.w3c.dom.NamedNodeMap piledata, java.lang.String property, int defaultvalue)
          Method to read an int property from the XML and to return it if it exists.
 java.util.LinkedList makedecks(int deckstogenerate)
          Sets up the initial set of cards to use - a number of packs specified by the file.
 State setupGame(java.lang.String filename)
          A large method to go through the entire process of reading the properties of the XML file (game, piles, fixed cards and tactics) and storing them in a State ready for use by the program.
 java.util.LinkedList shufflepack(java.util.LinkedList pack, int shuffledepth)
          Shuffles a given array of cards, by repeatedly swapping two positions chosen at random.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Interpreter

public Interpreter()
Method Detail

setupGame

public State setupGame(java.lang.String filename)
A large method to go through the entire process of reading the properties of the XML file (game, piles, fixed cards and tactics) and storing them in a State ready for use by the program.

Parameters:
filename - The file to interpret.
Returns:
A state matching the specification given in the file.

makedecks

public java.util.LinkedList makedecks(int deckstogenerate)
Sets up the initial set of cards to use - a number of packs specified by the file.

Returns:
A LinkedList consisting of a multiple of 52 Card objects, 13 values of each of the 4 suits.

shufflepack

public java.util.LinkedList shufflepack(java.util.LinkedList pack,
                                        int shuffledepth)
Shuffles a given array of cards, by repeatedly swapping two positions chosen at random.

Parameters:
pack - The array of cards to be shuffled.
shuffledepth - The number of swaps to perform.
Returns:
The shuffled pack.

booleanRead

public boolean booleanRead(org.w3c.dom.NamedNodeMap piledata,
                           java.lang.String property,
                           boolean defaultvalue)
Method to read a boolean property from the XML and to return it if it exists. If an exception is encountered, the default value is returned instead.

Parameters:
piledata - The node map from which to get data.
property - The name of the property to search for.
defaultvalue - The default value if the property is not found.
Returns:
The boolean value of the property.

getBool

public boolean getBool(java.lang.String string)
This method converts a String into a boolean, returning true if the contents of the String are equal to "true", and false if the contents are anything else.

Parameters:
string - The string to examine.
Returns:
True if and only if the string is "true".

intRead

public int intRead(org.w3c.dom.NamedNodeMap piledata,
                   java.lang.String property,
                   int defaultvalue)
Method to read an int property from the XML and to return it if it exists. If an exception is encountered, the default value is returned instead.

Parameters:
piledata - The node map from which to get data.
property - The name of the property to search for.
defaultvalue - The default value if the property is not found.
Returns:
The value of the property, as an int.