MCPcopy Create free account
hub / github.com/candybox2/candybox2.github.io / playTicTacToe_evaluateLine

Method playTicTacToe_evaluateLine

code/main/ATree.ts:136–184  ·  view source on GitHub ↗
(board: ATreeTicTacToeSign[][], row1: number, col1: number, row2: number, col2: number, row3: number, col3: number)

Source from the content-addressed store, hash-verified

134 }
135
136 private playTicTacToe_evaluateLine(board: ATreeTicTacToeSign[][], row1: number, col1: number, row2: number, col2: number, row3: number, col3: number): number{
137 // The score
138 var score: number = 0;
139
140 // First cell
141 if(board[row1][col1] == ATreeTicTacToeSign.O) // If the first cell is the squirrel
142 score = 1;
143 else if (board[row1][col1] == ATreeTicTacToeSign.X) // Else if it's the player
144 score = -1;
145
146 // Second cell
147 if(board[row2][col2] == ATreeTicTacToeSign.O){ // If the second cell is the squirrel
148 if(score == 1) // If the first cell was the squirrel
149 score = 10;
150 else if(score == -1) // Else, if the first cell was the player
151 return 0;
152 else // Else, the first cell was empty
153 score = 1;
154 }
155 else if(board[row2][col2] == ATreeTicTacToeSign.X){ // If the second cell is the player
156 if(score == 1) // If the first cell was the squirrel
157 return 0;
158 else if(score == -1) // Else, if the first cell was the player
159 score = -10;
160 else // Else, the first cell was empty
161 score = -1;
162 }
163
164 // Third cell
165 if(board[row3][col3] == ATreeTicTacToeSign.O){ // If the third cell is the squirrel
166 if(score > 0) // If the first and/or the second cell is the squirrel
167 score *= 10;
168 else if(score < 0) // Else, if the first and/or the second cell is the player
169 return 0;
170 else // Else, the first and the second cells are empty
171 score = 1;
172 }
173 else if(board[row3][col3] == ATreeTicTacToeSign.X){ // Else, if the third cell is the player
174 if(score > 0) // If the first and/or the second cell is the squirrel
175 return 0;
176 else if(score < 0) // Else, if the first and/or the second cell is the player
177 score *= 10;
178 else // Else, the first and the second cells are empty
179 score = -1;
180 }
181
182 // Return the score
183 return score;
184 }
185
186 private playTicTacToe_minimax(board: ATreeTicTacToeSign[][], playerSign: ATreeTicTacToeSign, depth: number = 2): ATreeTicTacToeMinimaxReturnValue{
187 // Variables

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected