Skip to content

Content of file GstTest.java

package de.fhdw.gaming.ipspiel23.gst.impl;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

import de.fhdw.gaming.core.domain.Move;
import de.fhdw.gaming.ipspiel23.gst.domain.TttMove;
import de.fhdw.gaming.ipspiel23.gst.domain.impl.GstKopplungsMoveCalculator;
import de.fhdw.gaming.ipspiel23.gst.strategies.impl.GstKopplungNegaMax;
import de.fhdw.gaming.ipspiel23.gst.strategies.impl.GstKopplungNegaMaxMultithreading;

/**
 * .
 *
 * @author Dave
 *
 */
class GstTest {

    /**
     * .
     */
    private final String PLAYER_A = "PlayerA";
The final field name 'PLAYER_A' doesn't match '[a-z][a-zA-Z0-9]*'.
Configurable naming conventions for field declarations. This rule reports variable declarations which do not match the regex that applies to their specific kind ---e.g. constants (static final), enum constant, final field. Each regex can be configured through properties. By default this rule uses the standard Java naming convention (Camel case), and uses the ALL_UPPER convention for constants and enum constants.
    
        
            
            class Foo {
                int myField = 1; // This is in camel case, so it's ok
                int my_Field = 1; // This contains an underscore, it's not ok by default
                                  // but you may allow it, or even require the "my_" prefix

                final int FinalField = 1; // you may configure a different convention for final fields,
                                          // e.g. here PascalCase: [A-Z][a-zA-Z0-9]*

                interface Interface {
                    double PI = 3.14; // interface "fields" use the constantPattern property
                }

                enum AnEnum {
                    ORG, NET, COM; // These use a separate property but are set to ALL_UPPER by default
                }
            }
            
        
    
See PMD documentation.
/** * . */ private final String PLAYER_B = "PlayerB"; /** * . */ private GstKopplungsMoveCalculator<TttPlayer, TttState> calc; /** * . */ private TttKopplung kopplung; /** * . */ private TttPlayer playerA; /** * . */ private TttPlayer playerB; /** * . */ @Test void currentPlayerWinsMoveTest() { /* * 00 = X, 20 = X, 11 = O, 22= 0 * * X to move, 01 is a winning move. * */ this.calc = new GstKopplungsMoveCalculator<>(); this.playerA = new TttPlayer(PLAYER_A, 1); this.playerB = new TttPlayer(PLAYER_B, -1); this.kopplung = new TttKopplung(); final TttState state = new TttState(this.playerA, this.playerB); state.getBoard()[0][0] = this.playerA.getPlayerSymbolValue(); state.getBoard()[2][0] = this.playerA.getPlayerSymbolValue(); state.getBoard()[1][1] = this.playerB.getPlayerSymbolValue(); state.getBoard()[2][2] = this.playerB.getPlayerSymbolValue(); final Move<TttPlayer, TttState> move = this.calc.calculateMove(this.kopplung, state, 500, new GstKopplungNegaMax<>()); final TttMove tttMove = (TttMove) move; final TttMove bestMove = new TttPlaceMarkMove(0, 1); assertEquals(bestMove, tttMove); } /** * . */ @Test void currentPlayerWinsBeforeNextPlayerTest() { /* * /* * 00 = X, 20 = X, 02 = O, 22= 0 * * X to move, 01 is a winning move. * O could win with 12, but because X is to move, X needs to win. * */ this.calc = new GstKopplungsMoveCalculator<>(); this.playerA = new TttPlayer(PLAYER_A, 1); this.playerB = new TttPlayer(PLAYER_B, -1); this.kopplung = new TttKopplung(); final TttState state = new TttState(this.playerA, this.playerB); state.getBoard()[0][0] = this.playerA.getPlayerSymbolValue(); state.getBoard()[2][0] = this.playerA.getPlayerSymbolValue(); state.getBoard()[0][2] = this.playerB.getPlayerSymbolValue(); state.getBoard()[2][2] = this.playerB.getPlayerSymbolValue(); final Move<TttPlayer, TttState> move = this.calc.calculateMove(this.kopplung, state, 500, new GstKopplungNegaMax<>()); final TttMove tttMove = (TttMove) move; final TttMove bestMove = new TttPlaceMarkMove(1, 0); assertEquals(bestMove, tttMove); } /** * . */ @Test void currentPlayerPreventsOtherPlayersWinTest() { /* * 00 = X, 11 = X, 02 = O, 22= 0 * * X to move, 12 is a prevention move. * O could win with 12, but because X is to move, X needs to prevent that win. * */ this.calc = new GstKopplungsMoveCalculator<>(); this.playerA = new TttPlayer(PLAYER_A, 1); this.playerB = new TttPlayer(PLAYER_B, -1); this.kopplung = new TttKopplung(); final TttState state = new TttState(this.playerA, this.playerB); state.getBoard()[0][0] = this.playerA.getPlayerSymbolValue(); state.getBoard()[1][1] = this.playerA.getPlayerSymbolValue(); state.getBoard()[0][2] = this.playerB.getPlayerSymbolValue(); state.getBoard()[2][2] = this.playerB.getPlayerSymbolValue(); final Move<TttPlayer, TttState> move = this.calc.calculateMove(this.kopplung, state, 500, new GstKopplungNegaMax<>()); final TttMove tttMove = (TttMove) move; final TttMove bestMove = new TttPlaceMarkMove(1, 2); assertEquals(bestMove, tttMove); } /** * . */ @Test void currentPlayerWinsMoveTestMT() { /* * 00 = X, 20 = X, 11 = O, 22= 0 * * X to move, 01 is a winning move. * */ this.calc = new GstKopplungsMoveCalculator<>(); this.playerA = new TttPlayer(PLAYER_A, 1); this.playerB = new TttPlayer(PLAYER_B, -1); this.kopplung = new TttKopplung(); final TttState state = new TttState(this.playerA, this.playerB); state.getBoard()[0][0] = this.playerA.getPlayerSymbolValue(); state.getBoard()[2][0] = this.playerA.getPlayerSymbolValue(); state.getBoard()[1][1] = this.playerB.getPlayerSymbolValue(); state.getBoard()[2][2] = this.playerB.getPlayerSymbolValue(); final Move<TttPlayer, TttState> move = this.calc.calculateMove(this.kopplung, state, 500, new GstKopplungNegaMaxMultithreading<>()); final TttMove tttMove = (TttMove) move; final TttMove bestMove = new TttPlaceMarkMove(0, 1); assertEquals(bestMove, tttMove); } /** * . */ @Test void currentPlayerWinsBeforeNextPlayerTestMT() { /* * /* * 00 = X, 20 = X, 02 = O, 22= 0 * * X to move, 01 is a winning move. * O could win with 12, but because X is to move, X needs to win. * */ this.calc = new GstKopplungsMoveCalculator<>(); this.playerA = new TttPlayer(PLAYER_A, 1); this.playerB = new TttPlayer(PLAYER_B, -1); this.kopplung = new TttKopplung(); final TttState state = new TttState(this.playerA, this.playerB); state.getBoard()[0][0] = this.playerA.getPlayerSymbolValue(); state.getBoard()[2][0] = this.playerA.getPlayerSymbolValue(); state.getBoard()[0][2] = this.playerB.getPlayerSymbolValue(); state.getBoard()[2][2] = this.playerB.getPlayerSymbolValue(); final Move<TttPlayer, TttState> move = this.calc.calculateMove(this.kopplung, state, 500, new GstKopplungNegaMaxMultithreading<>()); final TttMove tttMove = (TttMove) move; final TttMove bestMove = new TttPlaceMarkMove(1, 0); assertEquals(bestMove, tttMove); } /** * . */ @Test void currentPlayerPreventsOtherPlayersWinTestMT() { /* * 00 = X, 11 = X, 02 = O, 22= 0 * * X to move, 12 is a prevention move. * O could win with 12, but because X is to move, X needs to prevent that win. * */ this.calc = new GstKopplungsMoveCalculator<>(); this.playerA = new TttPlayer(PLAYER_A, 1); this.playerB = new TttPlayer(PLAYER_B, -1); this.kopplung = new TttKopplung(); final TttState state = new TttState(this.playerA, this.playerB); state.getBoard()[0][0] = this.playerA.getPlayerSymbolValue(); state.getBoard()[1][1] = this.playerA.getPlayerSymbolValue(); state.getBoard()[0][2] = this.playerB.getPlayerSymbolValue(); state.getBoard()[2][2] = this.playerB.getPlayerSymbolValue(); final Move<TttPlayer, TttState> move = this.calc.calculateMove(this.kopplung, state, 500, new GstKopplungNegaMaxMultithreading<>()); final TttMove tttMove = (TttMove) move; final TttMove bestMove = new TttPlaceMarkMove(1, 2); assertEquals(bestMove, tttMove); } }