@@ -20,7 +20,7 @@ BoardState::BoardState()
2020 }
2121}
2222
23- std::vector<BoardState*> BoardState::GetPossibleMoves () const
23+ std::vector<BoardState*> BoardState::GetPossibleMoves (SquareState player ) const
2424{
2525 std::vector<BoardState*> retVal;
2626
@@ -32,7 +32,7 @@ std::vector<BoardState*> BoardState::GetPossibleMoves() const
3232 if (mBoard [row][col] == BoardState::Empty)
3333 {
3434 retVal.emplace_back (new BoardState (*this ));
35- retVal.back ()->mBoard [row][col] = BoardState::Red ;
35+ retVal.back ()->mBoard [row][col] = player ;
3636 break ;
3737 }
3838 }
@@ -96,7 +96,7 @@ bool BoardState::IsFull() const
9696
9797int BoardState::GetFourInARow () const
9898{
99- // Returns 1 if yellow wins, - 1 if red wins, 0 otherwise
99+ // Returns - 1 if yellow wins, 1 if red wins, 0 otherwise
100100
101101 // Check if there's a row with four in a row
102102 for (int row = 0 ; row < 6 ; row++)
@@ -109,11 +109,11 @@ int BoardState::GetFourInARow() const
109109 {
110110 if (mBoard [row][col] == BoardState::Yellow)
111111 {
112- return 1 ;
112+ return - 1 ;
113113 }
114114 else if (mBoard [row][col] == BoardState::Red)
115115 {
116- return - 1 ;
116+ return 1 ;
117117 }
118118 }
119119 }
@@ -130,11 +130,11 @@ int BoardState::GetFourInARow() const
130130 {
131131 if (mBoard [row][col] == BoardState::Yellow)
132132 {
133- return 1 ;
133+ return - 1 ;
134134 }
135135 else if (mBoard [row][col] == BoardState::Red)
136136 {
137- return - 1 ;
137+ return 1 ;
138138 }
139139 }
140140 }
@@ -144,18 +144,18 @@ int BoardState::GetFourInARow() const
144144 for (int col = 0 ; col < 4 ; col++)
145145 {
146146 for (int row = 0 ; row < 3 ; row++)
147- {
147+ {
148148 if (mBoard [row][col] == mBoard [row + 1 ][col + 1 ] &&
149149 mBoard [row][col] == mBoard [row + 2 ][col + 2 ] &&
150150 mBoard [row][col] == mBoard [row + 3 ][col + 3 ])
151151 {
152152 if (mBoard [row][col] == BoardState::Yellow)
153153 {
154- return 1 ;
154+ return - 1 ;
155155 }
156156 else if (mBoard [row][col] == BoardState::Red)
157157 {
158- return - 1 ;
158+ return 1 ;
159159 }
160160 }
161161 }
@@ -172,11 +172,11 @@ int BoardState::GetFourInARow() const
172172 {
173173 if (mBoard [row][col] == BoardState::Yellow)
174174 {
175- return 1 ;
175+ return - 1 ;
176176 }
177177 else if (mBoard [row][col] == BoardState::Red)
178178 {
179- return - 1 ;
179+ return 1 ;
180180 }
181181 }
182182 }
@@ -209,7 +209,7 @@ bool TryPlayerMove(BoardState* state, int column)
209209void CPUMove (BoardState* state)
210210{
211211 // For now, this just randomly picks one of the possible moves
212- std::vector<BoardState*> moves = state->GetPossibleMoves ();
212+ std::vector<BoardState*> moves = state->GetPossibleMoves (BoardState::Red );
213213
214214 int index = Random::GetIntRange (0 , moves.size () - 1 );
215215
0 commit comments