-
Notifications
You must be signed in to change notification settings - Fork 0
/
move.java
81 lines (70 loc) · 2.51 KB
/
move.java
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
import java.util.ArrayList;
/*------------------------------------------------------------------------------
Move Class:
Purpose:
The move class is used in the recursive look forward piece of the tic tac
toe game. It tracks a row, a column, and, most importantly a score.
After the recursion is done, the computer picks the highest score.
Instructions:
This program is a class designed to be run with playTicTacToe.java and
CPUPlayer.java.
------------------------------------------------------------------------------*/
public class move {
//member variables
public int row;
public int col;
public int score = 0;
//***************************************************************************
//constructor(int,int)
//***************************************************************************
public move(int r, int c){
setMove(r,c);
}
//***************************************************************************
//setMove(int, int)
//initialize variables
//***************************************************************************
public void setMove(int r, int c){
row = r;
col = c;
score = 0;
}
//***************************************************************************
//set score(void)
//update score member variable
//***************************************************************************
public void setScore(int s){
score = s;
}
//***************************************************************************
//getScore(void)
//return score member variable
//***************************************************************************
public int getScore(){
return score;
}
//***************************************************************************
// findAvailableMoves(game)
// return an arraylist of all possible moves. In this case, all open squares
//***************************************************************************
private ArrayList<move> findAvailableMoves(ticTacToe game){
System.out.println("Adding moves at level 2!");
ArrayList<move> movesToMake = new ArrayList<move>();
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++){
if(game.getBoardVal(i, j) == 1){
move newMove = new move(i,j);
movesToMake.add(newMove);
}
}
}
return movesToMake;
}
//***************************************************************************
//toString
//overwrite toString function
//***************************************************************************
public String toString(){
return "(" + row + "," + col + ")";
}
}