Added functionality to keep track of moves.
This commit is contained in:
parent
fe89cf76af
commit
489ee0a50c
@ -33,7 +33,7 @@ public class BoardGenerator {
|
||||
|
||||
}
|
||||
|
||||
// Checks if the board is solveable.
|
||||
// Checks if the board is solvable.
|
||||
Board generated = new Board(pieces);
|
||||
if (isSolvable(generated)) {
|
||||
return generated;
|
||||
|
@ -1,7 +1,6 @@
|
||||
package Assignments.A1.models;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Jonathan Turner
|
||||
@ -9,8 +8,6 @@ import java.util.List;
|
||||
*/
|
||||
public class EightPuzzle {
|
||||
|
||||
private List<Board> boards = new ArrayList<>();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
49
src/Assignments/A1/models/Move.java
Normal file
49
src/Assignments/A1/models/Move.java
Normal file
@ -0,0 +1,49 @@
|
||||
package Assignments.A1.models;
|
||||
|
||||
/**
|
||||
* Used to keep track of moves in either a stack or queues.
|
||||
*
|
||||
* @author Jonathan Turner
|
||||
* @version Spring 2024
|
||||
*/
|
||||
public class Move {
|
||||
|
||||
private Board board;
|
||||
private final Pair<Integer> points;
|
||||
private boolean used;
|
||||
|
||||
/**
|
||||
* Creates a new move with the given points.
|
||||
*
|
||||
* @precondition none
|
||||
* @postcondition a new move is created.
|
||||
* @param firstpoint the first point
|
||||
* @param secondpoint the second point
|
||||
*/
|
||||
public Move(int firstpoint, int secondpoint) {
|
||||
this.points = new Pair<>(firstpoint, secondpoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a move was used.
|
||||
* @precondition none
|
||||
* @postcondition none
|
||||
* @return whether the move was used.
|
||||
*/
|
||||
public boolean used() {
|
||||
return used;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the points for the move and marks it as used.
|
||||
*
|
||||
* @precondition none
|
||||
* @postcondition used == true
|
||||
* @return the pair of points.
|
||||
*/
|
||||
public Pair<Integer> traverse() {
|
||||
used = true;
|
||||
return points;
|
||||
}
|
||||
}
|
||||
|
29
src/Assignments/A1/models/Pair.java
Normal file
29
src/Assignments/A1/models/Pair.java
Normal file
@ -0,0 +1,29 @@
|
||||
package Assignments.A1.models;
|
||||
|
||||
/**
|
||||
* Used to pair two points for moves.
|
||||
* @author Jonathan Turner
|
||||
* @version Spring 2024
|
||||
* @param <E> the type of the pair.
|
||||
*/
|
||||
public class Pair<E> {
|
||||
|
||||
/* the first and second points */
|
||||
public E first;
|
||||
public E second;
|
||||
|
||||
/**
|
||||
* Creates and sets the first and second point of the pair.
|
||||
*
|
||||
* @precondition none
|
||||
* @postcondition a pair is created.
|
||||
*
|
||||
* @param first the first point of the pair
|
||||
* @param second the second point of the pair
|
||||
*/
|
||||
public Pair(E first, E second) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user