mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
fix: minimax test
This commit is contained in:
@@ -1,77 +1,77 @@
|
|||||||
//
|
|
||||||
// import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
// import org.toop.game.tictactoe.*;
|
import org.toop.game.tictactoe.*;
|
||||||
//
|
|
||||||
// import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
//
|
|
||||||
// class MinMaxTicTacToeTest {
|
class MinMaxTicTacToeTest {
|
||||||
//
|
|
||||||
// // makegame makes a board situation so we can test the AI. that's it really, the rest is easy to follow id say
|
// makegame makes a board situation so we can test the AI. that's it really, the rest is easy to follow id say
|
||||||
// private TicTacToe makeGame(String board, int currentPlayer) {
|
private TicTacToe makeGame(String board, int currentPlayer) {
|
||||||
// TicTacToe game = new TicTacToe("AI", "Human");
|
TicTacToe game = new TicTacToe("AI", "Human");
|
||||||
// // Fill the board
|
// Fill the board
|
||||||
// for (int i = 0; i < board.length(); i++) {
|
for (int i = 0; i < board.length(); i++) {
|
||||||
// char c = board.charAt(i);
|
char c = board.charAt(i);
|
||||||
// game.grid[i] = c;
|
game.grid[i] = c;
|
||||||
// if (c != ' ') game.movesLeft--;
|
if (c != '-') game.movesLeft--;
|
||||||
// }
|
}
|
||||||
// game.currentPlayer = currentPlayer;
|
game.currentPlayer = currentPlayer;
|
||||||
// return game;
|
return game;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Test
|
@Test
|
||||||
// void testFindBestMove_AIImmediateWin() {
|
void testFindBestMove_AIImmediateWin() {
|
||||||
// TicTacToe game = makeGame("XX OO ", 0);
|
TicTacToe game = makeGame("XX-OO----", 0);
|
||||||
// MinMaxTicTacToe ai = new MinMaxTicTacToe();
|
MinMaxTicTacToe ai = new MinMaxTicTacToe();
|
||||||
// int bestMove = ai.findBestMove(game);
|
int bestMove = ai.findBestMove(game);
|
||||||
// assertEquals(2, bestMove, "AI has to take winning move at 2");
|
assertEquals(2, bestMove, "AI has to take winning move at 2");
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Test
|
@Test
|
||||||
// void testFindBestMove_BlockOpponentWin() {
|
void testFindBestMove_BlockOpponentWin() {
|
||||||
// TicTacToe game = makeGame("OO X ", 0); // 0 = AI's turn
|
TicTacToe game = makeGame("OO-X----", 0); // 0 = AI's turn
|
||||||
// MinMaxTicTacToe ai = new MinMaxTicTacToe();
|
MinMaxTicTacToe ai = new MinMaxTicTacToe();
|
||||||
// int bestMove = ai.findBestMove(game);
|
int bestMove = ai.findBestMove(game);
|
||||||
// assertEquals(2, bestMove, "AI should block opponent win at 2");
|
assertEquals(2, bestMove, "AI should block opponent win at 2");
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Test
|
@Test
|
||||||
// void testFindBestMove_ChooseDrawIfNoWin() {
|
void testFindBestMove_ChooseDrawIfNoWin() {
|
||||||
// TicTacToe game = makeGame("XOXOX O ", 0);
|
TicTacToe game = makeGame("XOXOX-O--", 0);
|
||||||
// MinMaxTicTacToe ai = new MinMaxTicTacToe();
|
MinMaxTicTacToe ai = new MinMaxTicTacToe();
|
||||||
// int bestMove = ai.findBestMove(game);
|
int bestMove = ai.findBestMove(game);
|
||||||
// assertTrue(bestMove == 6 || bestMove == 8, "AI should draw");
|
assertTrue(bestMove == 6 || bestMove == 8, "AI should draw");
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Test
|
@Test
|
||||||
// void testMinimax_ScoreWin() {
|
void testMinimax_ScoreWin() {
|
||||||
// TicTacToe game = makeGame("XXX ", 0);
|
TicTacToe game = makeGame("XXX------", 0);
|
||||||
// MinMaxTicTacToe ai = new MinMaxTicTacToe();
|
MinMaxTicTacToe ai = new MinMaxTicTacToe();
|
||||||
// int score = ai.doMinimax(game, 5, false);
|
int score = ai.doMinimax(game, 5, false);
|
||||||
// assertTrue(score > 0, "AI win scored positively");
|
assertTrue(score > 0, "AI win scored positively");
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Test
|
@Test
|
||||||
// void testMinimax_ScoreLoss() {
|
void testMinimax_ScoreLoss() {
|
||||||
// TicTacToe game = makeGame("OOO ", 1);
|
TicTacToe game = makeGame("OOO ", 1);
|
||||||
// MinMaxTicTacToe ai = new MinMaxTicTacToe();
|
MinMaxTicTacToe ai = new MinMaxTicTacToe();
|
||||||
// int score = ai.doMinimax(game, 5, true);
|
int score = ai.doMinimax(game, 5, true);
|
||||||
// assertTrue(score < 0, "AI loss is negative");
|
assertTrue(score < 0, "AI loss is negative");
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Test
|
@Test
|
||||||
// void testMinimax_ScoreDraw() {
|
void testMinimax_ScoreDraw() {
|
||||||
// TicTacToe game = makeGame("XOXOXOOXO", 0);
|
TicTacToe game = makeGame("XOXOXOOXO", 0);
|
||||||
// MinMaxTicTacToe ai = new MinMaxTicTacToe();
|
MinMaxTicTacToe ai = new MinMaxTicTacToe();
|
||||||
// int score = ai.doMinimax(game, 5, true);
|
int score = ai.doMinimax(game, 5, true);
|
||||||
// assertEquals(0, score, "Draw should be zero!");
|
assertEquals(0, score, "Draw should be zero!");
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Test
|
@Test
|
||||||
// void testMiniMax_MultipleMoves() {
|
void testMiniMax_MultipleMoves() {
|
||||||
// TicTacToe game = makeGame(" X OX O ", 0);
|
TicTacToe game = makeGame(" X-OX--O-", 0);
|
||||||
// MinMaxTicTacToe ai = new MinMaxTicTacToe();
|
MinMaxTicTacToe ai = new MinMaxTicTacToe();
|
||||||
// int bestMove = ai.findBestMove(game);
|
int bestMove = ai.findBestMove(game);
|
||||||
// assertTrue(bestMove == 0 || bestMove == 2, "Can look at multiple moves!");
|
assertTrue(bestMove == 0 || bestMove == 2, "Can look at multiple moves!");
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user