Commit a33c9f65 authored by Mehmet Duhan Tercüman's avatar Mehmet Duhan Tercüman
Browse files

Tests und ähnliches

parent 9a39523d
......@@ -10,8 +10,6 @@ import java.util.Arrays;
public class Draw extends PApplet {
GameEngine game = new GameEngine();
private int gameMode;
boolean menu=true;
boolean bot = false;
boolean drawGame=false;
public static void main(String[] args) {
......@@ -69,15 +67,16 @@ public class Draw extends PApplet {
y += 100;
}
if (game.isWin(game.playerBoard[0])) {
background(0);
background(3, 90, 252);
textSize(50);
fill(255);
text("Player 1 WON", 400, 400);
} else if (game.isWin(game.playerBoard[1])) {
background(0);
textSize(50);
background(3, 90, 252);
textSize(30);
fill(255);
text("Player 2 WON", 400, 400);
if(bot) text("Bot WON", 200, 230);
else text("Player 2 WON", 200,230);
}
}
......
......@@ -29,7 +29,6 @@ public class GameEngine implements GameInterface{
if(moves.isEmpty()) return 0;
int randomMove = moves.get(rnd.nextInt(moves.size()));
board.makeMove(randomMove);
value = board.isWin(board.playerBoard[0]) ? 1 : board.isWin(board.playerBoard[1]) ? -1 : 0;
}
return value;
......@@ -39,7 +38,6 @@ public class GameEngine implements GameInterface{
int[] counter = {0,0,0};
int count = board.count;
while (number > 0){
//////// CLONE
GameEngine test = new GameEngine();
test.playerBoard = Arrays.copyOf(board.playerBoard, board.playerBoard.length); // NUR CLONE
test.move = Arrays.copyOf(board.move, board.move.length);
......@@ -63,7 +61,6 @@ public class GameEngine implements GameInterface{
return values;
}
public int chooseBestMove(GameEngine board, int number){
ArrayList<Integer> moves = board.listMoves();
ArrayList<int[]> evaluate = board.evaluateMoves(board,number);
......@@ -71,9 +68,7 @@ public class GameEngine implements GameInterface{
for(int i = 0; i<evaluate.size();i++){
int turn = (board.count & 1) == 0 ? 1 : -1;
values[i] = evaluate.get(i)[2] * turn;
}
int maxValue = Arrays.stream(values).max().getAsInt();
int bestIndex = -1;
for(int j = 0; j<values.length; j++){
......@@ -89,7 +84,7 @@ public class GameEngine implements GameInterface{
int[] directions = {1, 7, 6, 8};
long bb;
for(int direction : directions) {
bb = board& (board >> direction);
bb = board & (board >> direction);
if ((bb & (bb >> (2 * direction))) != 0) return true;
}
return false;
......
......@@ -3,12 +3,32 @@
*/
package PIS_HU1;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.*;
public class AppTest {
@Test public void testAppHasAGreeting() {
App classUnderTest = new App();
assertNotNull("app should have a greeting", classUnderTest.getGreeting());
private GameEngine game = new GameEngine();
//gewinnen möglich
//methodes work
//listMoves
//make Move
// win
// undoMove
// falscher Zug
//board
//is legal
//is playable
// ungefülltes board
@Test
public void emptyBoard(){
Assert.assertArrayEquals(game.playerBoard,new long[]{0L,0L});
}
@Test
public void testMove(){
game.makeMove(1);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment