Skip to content

Content of file C4GSTMoveStrategy.java

package de.fhdw.gaming.ipspiel23.c4.gststrategy;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Optional;

import de.fhdw.gaming.core.domain.GameException;
import de.fhdw.gaming.core.domain.Move;
import de.fhdw.gaming.ipspiel23.c4.domain.IC4Player;
import de.fhdw.gaming.ipspiel23.c4.domain.IC4State;
import de.fhdw.gaming.ipspiel23.c4.moves.IC4Move;
import de.fhdw.gaming.ipspiel23.c4.moves.factory.IC4MoveFactory;
import de.fhdw.gaming.ipspiel23.c4.strategies.IC4Strategy;
import de.fhdw.gaming.ipspiel23.gst.domain.ICalculatorKopplung;
import de.fhdw.gaming.ipspiel23.gst.domain.IKopplung;
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;



/**
 * GSTMoveStrategy for C4 Game.
 */
public class C4GSTMoveStrategy implements IC4Strategy {

    
    
    
    /**
     * The calculator used for computing the next move.
     */
    private ICalculatorKopplung<IC4Player, IC4State> calc;
    
    
    /**
     * The MoveFactory.
     */
    private IC4MoveFactory moveFactory;
Private field 'moveFactory' could be made final; it is only initialized in the declaration or constructor.
Reports non-final fields whose value never changes once object initialization ends, and hence may be marked final. Note that this rule does not enforce that the field value be deeply immutable itself. An object can still have mutable state, even if all its member fields are declared final. This is referred to as shallow immutability. For more information on mutability, see *Effective Java, 3rd Edition, Item 17: Minimize mutability*. Limitations: We can only check private fields for now.
    
        

public class Foo {
  private int x; // could be final
  public Foo() {
      x = 7;
  }
  public void foo() {
     int a = x + 2;
  }
}

        
    
See PMD documentation.
/** * The C4-GST-Kopplung. */ private IKopplung<IC4Player, IC4State> c4Kopplung; /** * . */ private GstKopplungNegaMaxMultithreading<IC4Player, IC4State> negamax; //private GstKopplungNegaMax<IC4Player, IC4State> negamax; /** * Creates new C4GSTMoveStrategy with given MoveFactory. * @param moveFactory */ public C4GSTMoveStrategy(IC4MoveFactory moveFactory) { this.moveFactory = moveFactory; this.c4Kopplung = new C4GSTKopplung(moveFactory); //this.negamax = new GstKopplungNegaMax<>(); this.negamax = new GstKopplungNegaMaxMultithreading<>(); this.calc = new GstKopplungsMoveCalculator<>(); } @Override public Optional<IC4Move> computeNextMove(int gameId, IC4Player player, IC4State state) throws GameException, InterruptedException { //final Collection<Move<IC4Player, IC4State>> possibleMoves = c4Kopplung.getPossibleMoves(state).get(); return Optional.of((IC4Move) calc.calculateMove(c4Kopplung, state, 1000, negamax)); } @Override public String toString() { return C4GSTMoveStrategy.class.getSimpleName(); } }