public class TicTacToeHashCode extends Board
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategyjava.awt.Container.AccessibleAWTContainer| Modifier and Type | Field | Description |
|---|---|---|
private static java.lang.String |
BOARD_TITLE |
The title of the board
|
private static java.lang.String |
COLLISION_OCCURRED |
The message if a collision occurs
|
private static int |
DELAY |
The delay between each display of a TicTacToe String
|
private static int |
ERROR_CODE |
The integer used as a parameter for System.exit() as a result of an error
|
private static char |
O |
A char holding an o
|
private static int[] |
POWERS_OF_THREE |
A lookup table with powers of three where the each spot holds three ^ index
|
private static char |
SPACE |
A char holding a space
|
private static java.lang.String |
TEST_FILE |
The name of the file holding the TicTacToe tests
|
private static java.lang.String |
TEST_FILE_NOT_FOUND |
The message if the file with the test strings is not found
|
private static java.lang.String |
WINNER_FILE |
The name of the file containing the winning TicTacToe Strings
|
private static java.lang.String |
WINNER_FILE_NOT_FOUND |
The message if the file with the winning strings is not found
|
private boolean[] |
winners |
A boolean array where a TicTacToe String's hash code directly corresponds
to a boolean value (if true, the TicTacToe string is a winner, and if false,
a loser)
|
private static char |
X |
A char holding an x
|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTCROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR| Constructor | Description |
|---|---|
TicTacToeHashCode(java.lang.String boardTitle) |
This creates a TicTacToeHashCode by calling the Board constructor
with boardTitle and instantiating and filling the winners array
with true at the correct indexes (which are the corresponding hash codes for
the winning TicTacToe strings)
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
displayTicTacToe(java.lang.String ticTacToe,
int validity) |
Displays a TicTacToe on the board including changing the
buttons representing the board and the labels with the hash code
and whether the String is a winner or a loser
|
boolean |
isWin() |
Returns whether boardString is a winner or loser using
the winners array and myHashCode method.
|
boolean |
isWin(java.lang.String s) |
Returns whether a TicTacToe board is a winner or loser using
the winners array and myHashCode method.
|
static void |
main(java.lang.String[] args) |
|
int |
myHashCode() |
Returns a hash code for the current board string using the charAt method.
|
int |
myHashCode(java.lang.String str) |
Returns a hash code for str.
|
actionPerformed, charAt, charAt, displayRandomString, getBoardString, resetBoardString, setBoardString, setHashCodeLabel, setupPanelOne, setWinnerLabel, setWinnerLabel, showaction, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setMixingCutoutShape, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycleadd, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validate, validateTreeaddNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setBackground, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setOpacity, setResizable, setShape, setState, setTitle, setUndecoratedaddImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, updateclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, setVisible, show, toBack, toFrontprivate boolean[] winners
private static final int[] POWERS_OF_THREE
private static final int ERROR_CODE
private static final int DELAY
private static final char SPACE
private static final char X
private static final char O
private static final java.lang.String WINNER_FILE
private static final java.lang.String TEST_FILE
private static final java.lang.String BOARD_TITLE
private static final java.lang.String WINNER_FILE_NOT_FOUND
private static final java.lang.String TEST_FILE_NOT_FOUND
private static final java.lang.String COLLISION_OCCURRED
TicTacToeHashCode(java.lang.String boardTitle)
boardTitle - the title of the boardpublic int myHashCode()
myHashCode in class Boardpublic int myHashCode(java.lang.String str)
str - the String for which the hash code is to be createdpublic boolean isWin(java.lang.String s)
public boolean isWin()
public void displayTicTacToe(java.lang.String ticTacToe,
int validity)
ticTacToe - the String to be evaluated and displayedvalidity - 0 means invalid generally, 1 means valid generally, 2 means valid possibility
but invalid game result (all xos and os and 9 characters but not valid in
terms of game is resolved); if it's 0 it will say hash code is not
applicable (represented by -1) and the status will say invalidpublic static void main(java.lang.String[] args)
throws java.lang.InterruptedException
java.lang.InterruptedException