API game (bug possible)
This commit is contained in:
99
2024-25/javaAPI/fr/iut_fbleau/GameAPI/AbstractBoard.java
Normal file
99
2024-25/javaAPI/fr/iut_fbleau/GameAPI/AbstractBoard.java
Normal file
@@ -0,0 +1,99 @@
|
||||
package fr.iut_fbleau.GameAPI;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Deque;
|
||||
|
||||
/**
|
||||
* An abstract class implementing the interface IBoard.
|
||||
*
|
||||
* used to implement some things to do with the update of the next player
|
||||
* which is the same for all games and provides also a minimal
|
||||
* implantation of the history mechanism.
|
||||
*/
|
||||
public abstract class AbstractBoard implements IBoard{
|
||||
|
||||
private Player currentPlayer ;
|
||||
|
||||
private Deque<AbstractPly> history;
|
||||
|
||||
private void setNextPlayer(){
|
||||
if (this.currentPlayer==Player.PLAYER1){
|
||||
this.currentPlayer= Player.PLAYER2;
|
||||
}
|
||||
else
|
||||
this.currentPlayer= Player.PLAYER1;
|
||||
}
|
||||
|
||||
// Beware not checking if move is legal.
|
||||
// To be used in do(AbstractPly c)
|
||||
private void addPlyToHistory(AbstractPly c){
|
||||
this.history.addLast(c);
|
||||
}
|
||||
|
||||
// Beware not checking if history is not empty
|
||||
// To be used in undo()
|
||||
private void removePlyFromHistory(){
|
||||
return this.history.removeLast();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the current player
|
||||
*/
|
||||
public Player getcurrentPlayer(){
|
||||
return this.currentPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the game status
|
||||
*
|
||||
* @return true iff the game is over
|
||||
*/
|
||||
public abstract boolean isGameOver();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the result (null if not over)
|
||||
*/
|
||||
public abstract Result getResult();
|
||||
|
||||
/**
|
||||
* checker of legal moves from this position
|
||||
*
|
||||
* @throws NullPointerException if the game is over
|
||||
* @return the iterator
|
||||
*/
|
||||
public abstract boolean isLegal(AbstractPly c);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* constructor of Iterator over legal moves from this position
|
||||
*
|
||||
* @throws NullPointerException if the game is over
|
||||
* @return the iterator
|
||||
*/
|
||||
public abstract Iterator<AbstractPly> iterator();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Plays a given move on the plateau.
|
||||
* Should update history using
|
||||
* @throws IllegalArgumentException if the move is always illegal (say from the wrong game)
|
||||
* @throws IllegalStateException if the move is not legal in this position
|
||||
*
|
||||
* @param AbstractPly to be played
|
||||
*
|
||||
*/
|
||||
public abstract void doPly(AbstractPly c);
|
||||
|
||||
/**
|
||||
* Resets the plateau to the position before the last move.
|
||||
*
|
||||
* @throws IllegalStateException if nothing to undo in history
|
||||
*
|
||||
*/
|
||||
public abstract void undoPly();
|
||||
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
package fr.iut_fbleau.GameAPI;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* The abstract class for a game Player.
|
||||
*/
|
||||
public abstract class AbstractGamePlayer {
|
||||
|
||||
// not a band, but which type of player I am in the game (PLAYER1 or PLAYER2).
|
||||
private iAm Player;
|
||||
|
||||
// Le joueur réel pourrait avoir besoin de connaître un constructeur de coup?
|
||||
// pas pour l'instant.
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @throws UnsupportedOperationException if the method is not yet implemented
|
||||
*
|
||||
* @throws IllegalStateException if the Situation is already in the bookmarks
|
||||
*/
|
||||
public abstract AbstractPly (IBoard p);
|
||||
|
||||
}
|
5
2024-25/javaAPI/fr/iut_fbleau/GameAPI/AbstractPly.java
Normal file
5
2024-25/javaAPI/fr/iut_fbleau/GameAPI/AbstractPly.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package fr.iut_fbleau.GameAPI;
|
||||
|
||||
public abstract class AbstractPly {
|
||||
private Player joueur;
|
||||
}
|
69
2024-25/javaAPI/fr/iut_fbleau/GameAPI/IBoard.java
Normal file
69
2024-25/javaAPI/fr/iut_fbleau/GameAPI/IBoard.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package fr.iut_fbleau.GameAPI;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* The interface Board.
|
||||
*/
|
||||
public interface IBoard {
|
||||
|
||||
|
||||
/**
|
||||
* @return the current player
|
||||
*/
|
||||
public Player getcurrentPlayer();
|
||||
|
||||
/**
|
||||
* Returns the game status
|
||||
*
|
||||
* @return true iff the game is over
|
||||
*/
|
||||
public boolean isGameOver();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the result (null if not over)
|
||||
*/
|
||||
public Result getResult();
|
||||
|
||||
/**
|
||||
* checker of legal moves from this position
|
||||
*
|
||||
* @throws NullPointerException if the game is over
|
||||
* @return the iterator
|
||||
*/
|
||||
public boolean isLegal(AbstractPly c);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* constructor of Iterator over legal moves from this position
|
||||
*
|
||||
* @throws NullPointerException if the game is over
|
||||
* @return the iterator
|
||||
*/
|
||||
public Iterator<AbstractPly> iterator();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Plays a given move on the plateau.
|
||||
* Should update history using
|
||||
* @throws IllegalArgumentException if the move is always illegal (say from the wrong game)
|
||||
* @throws IllegalStateException if the move is not legal in this position
|
||||
*
|
||||
* @param AbstractPly to be played
|
||||
*
|
||||
*/
|
||||
public void doPly(AbstractPly c);
|
||||
|
||||
/**
|
||||
* Resets the plateau to the position before the last move.
|
||||
*
|
||||
* @throws IllegalStateException if nothing to undo in history
|
||||
*
|
||||
*/
|
||||
public void undoPly();
|
||||
|
||||
|
||||
}
|
6
2024-25/javaAPI/fr/iut_fbleau/GameAPI/Player.java
Normal file
6
2024-25/javaAPI/fr/iut_fbleau/GameAPI/Player.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package fr.iut_fbleau.GameAPI;
|
||||
|
||||
public enum Player {
|
||||
PLAYER1,
|
||||
PLAYER2
|
||||
}
|
11
2024-25/javaAPI/fr/iut_fbleau/GameAPI/Result.java
Normal file
11
2024-25/javaAPI/fr/iut_fbleau/GameAPI/Result.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package fr.iut_fbleau.GameAPI;
|
||||
|
||||
/**
|
||||
* To output the result of a 2 player game that is symmetric.
|
||||
* from the perspective of the player PLAYER1.
|
||||
*/
|
||||
public enum Result {
|
||||
WIN,
|
||||
DRAW,
|
||||
LOSS;
|
||||
}
|
Reference in New Issue
Block a user