-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoard.java
More file actions
122 lines (111 loc) · 1.74 KB
/
Copy pathBoard.java
File metadata and controls
122 lines (111 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* Class name: Board
* Object to represent tic tac toe board
*
* @author Christian Autor
* @version 1.0
* @since 3/30/2021
*/
import java.util.*;
public class Board
{
protected char[] boardState;
/**
* Board constructor
*
* @param none
* @return none
*/
public Board()
{
boardState = new char[9];
Arrays.fill(boardState,'-');
}
/**
* Board constructor
*
* @param char c[]
* @return none
*/
public Board(char[] c)
{
boardState = c.clone();
}
/**
* getSpot method
*
* @param int i
* @return char
*/
protected char getSpot(int i)
{
if(i>=0 && i<9)
return boardState[i];
return '-';
}
/**
* makeMove method
*
* @param char c, int i
* @return none
*/
protected void makeMove(char c, int i)
{
boardState[i] = c;
}
/**
* returnMove method
*
* @param char c, int i
* @return Board
*/
protected Board returnMove(char c, int i)
{
Board makeBoardState = new Board(boardState.clone());
makeBoardState.makeMove(c, i);
return makeBoardState;
}
/**
* toString method
*
* @param none
* @return String
*/
public String toString()
{
String S = "";
for(int i = 0; i<boardState.length; i++)
S += boardState[i];
return S;
}
/**
* printBoard method
*
* @param none
* @return none
*/
protected void printBoard()
{
for(int i = 0; i<boardState.length; i++)
{
if(i%3 == 0)
System.out.print("\n");
System.out.print(boardState[i]);
}
}
/**
* contains method
*
* @param char c
* @return boolean
*/
protected boolean contains(char c)
{
for(int i = 0; i<boardState.length; i++)
{
if(boardState[i] == c)
return true;
}
return false;
}
}