I am creating the board game Tic Tac Toe in Java.
A cell will have three states: empty, X or O.
What is the best practice for representing this in Java? Should I create its own Cell class or just use integers (0/1/2) to represent the three states? If it had two states then I could use for example boolean to represent the two states, is there a similar already defined class for something with three states?
Three-state logic From Wikipedia, the free encyclopedia In digital electronics three-state, tri-state, or 3-state logic allows an output or input pin/pad to assume a high impedance state, effectively removing the output from the circuit, in addition to the 0 and 1 logic levels.
The three of my closest objects that describe me are my iPod, my trunk and my Rubik’s Cube. The first object of mine that I would use to define me would be my iPod. As we all know, an iPod contains music that can lighten up different situations and people.
Matter can be classified as solid, liquid and gas on the basis of inter-molecular forces and the arrangement of particles. These three forms of matter can be converted from one state of matter to another state by increasing or decreasing pressure and temperature. For example, Ice can be converted from solid state to liquid state by...
] In digital electronics three-state, tri-state, or 3-state logic allows an output port to assume a high impedance state, effectively removing the output from the circuit, in addition to the 0 and 1 logic levels .
I would use an enum for this:
enum CellState {
EMPTY,
X,
O
}
And then in your code:
public static void main(String[] args) {
CellState[][] cellStates = new CellState[3][3];
cellStates[0][0] = CellState.X;
// Do other stuff
}
I just defined the board structure as CellState[][]
as example but this can be whatever.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With