Skip to content

Commit

Permalink
Merge branch 'dev' into minesweeper
Browse files Browse the repository at this point in the history
  • Loading branch information
charlestian23 authored May 5, 2024
2 parents 30b6e5e + 58eba41 commit ecfbff6
Show file tree
Hide file tree
Showing 83 changed files with 3,435 additions and 679 deletions.
47 changes: 0 additions & 47 deletions bin/main/edu/rpi/legup/legup/config

This file was deleted.

22 changes: 22 additions & 0 deletions puzzles files/binary/6x6 easy/089764562
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Legup version="2.0.0">
<puzzle name="Binary">
<board height="6" width="6">
<cells>
<cell value="0" x="2" y="0"/>
<cell value="1" x="5" y="0"/>
<cell value="1" x="0" y="1"/>
<cell value="0" x="2" y="1"/>
<cell value="0" x="3" y="1"/>
<cell value="1" x="1" y="2"/>
<cell value="1" x="4" y="3"/>
<cell value="1" x="2" y="4"/>
<cell value="0" x="5" y="4"/>
<cell value="0" x="0" y="5"/>
<cell value="0" x="1" y="5"/>
<cell value="1" x="3" y="5"/>
</cells>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>
21 changes: 21 additions & 0 deletions puzzles files/binary/6x6 easy/128903434
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Legup version="2.0.0">
<puzzle name="Binary">
<board height="6" width="6">
<cells>
<cell value="0" x="1" y="0"/>
<cell value="1" x="0" y="1"/>
<cell value="0" x="3" y="1"/>
<cell value="0" x="4" y="1"/>
<cell value="0" x="4" y="2"/>
<cell value="0" x="0" y="3"/>
<cell value="1" x="3" y="3"/>
<cell value="0" x="2" y="4"/>
<cell value="1" x="1" y="5"/>
<cell value="0" x="5" y="5"/>

</cells>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>
25 changes: 25 additions & 0 deletions puzzles files/binary/6x6 easy/876868768
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Legup version="2.0.0">
<puzzle name="Binary">
<board height="6" width="6">
<cells>
<cell value="1" x="0" y="0"/>
<cell value="0" x="3" y="0"/>
<cell value="0" x="2" y="1"/>
<cell value="0" x="3" y="1"/>
<cell value="1" x="5" y="1"/>
<cell value="0" x="1" y="2"/>
<cell value="0" x="2" y="2"/>
<cell value="1" x="5" y="2"/>
<cell value="0" x="0" y="4"/>
<cell value="0" x="1" y="4"/>
<cell value="1" x="3" y="4"/>
<cell value="1" x="1" y="5"/>
<cell value="0" x="4" y="5"/>
<cell value="0" x="5" y="5"/>

</cells>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>
28 changes: 28 additions & 0 deletions puzzles files/binary/6x6 easy/927364891
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Legup version="2.0.0">
<puzzle name="Binary">
<board height="6" width="6">
<cells>
<cell value="1" x="0" y="0"/>
<cell value="1" x="2" y="0"/>
<cell value="1" x="3" y="0"/>
<cell value="0" x="5" y="0"/>
<cell value="0" x="1" y="1"/>
<cell value="1" x="0" y="2"/>
<cell value="0" x="3" y="2"/>
<cell value="0" x="5" y="2"/>
<cell value="1" x="0" y="3"/>
<cell value="1" x="4" y="3"/>
<cell value="0" x="5" y="3"/>
<cell value="1" x="1" y="4"/>
<cell value="1" x="3" y="4"/>
<cell value="0" x="0" y="5"/>
<cell value="0" x="2" y="5"/>
<cell value="1" x="4" y="5"/>
<cell value="1" x="5" y="5"/>

</cells>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>
5 changes: 3 additions & 2 deletions puzzles files/treetent/8x8 TreeTent Easy/1646651
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Legup version="2.0.0">
<Legup version="3.0.0">
<saved/>
<puzzle name="TreeTent">
<board height="8" width="8">
<cells>
Expand Down Expand Up @@ -38,5 +39,5 @@
</axis>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
<solved isSolved="false" lastSaved="2024-03-12 17:29:25"/>
</Legup>
18 changes: 17 additions & 1 deletion src/main/java/edu/rpi/legup/model/PuzzleImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import edu.rpi.legup.model.rules.Rule;
import edu.rpi.legup.model.tree.*;
import edu.rpi.legup.save.InvalidFileFormatException;

import java.lang.reflect.Array;
import java.util.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -130,6 +132,19 @@ public void initializePuzzle(Node node) throws InvalidFileFormatException {
public abstract void initializeBoard(String[] statements)
throws UnsupportedOperationException, IllegalArgumentException;

/**
* Used to check that elements in the proof tree are saved properly.
* <p> Make sure the list elements are lowercase
*
* @return A list of elements that will change when solving the puzzle
* * e.g. {"cell"}, {"cell", "line"}
*/
public List<String> getImporterElements() {
List<String> elements = new ArrayList<>();
elements.add("cell");
return elements;
}

/**
* Creates the proof for building
*
Expand Down Expand Up @@ -379,7 +394,8 @@ protected void makeTransitionChanges(TreeTransition transition, Node transElemen
NodeList cellList = transElement.getChildNodes();
for (int i = 0; i < cellList.getLength(); i++) {
Node node = cellList.item(i);
if (node.getNodeName().equalsIgnoreCase("cell")) {
List<String> elements = getImporterElements();
if (elements.contains(node.getNodeName().toLowerCase())) {
Board board = transition.getBoard();
PuzzleElement cell = puzzle.getFactory().importCell(node, board);

Expand Down
71 changes: 71 additions & 0 deletions src/main/java/edu/rpi/legup/puzzle/binary/Binary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package edu.rpi.legup.puzzle.binary;

import edu.rpi.legup.model.Puzzle;
import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.rules.ContradictionRule;

public class Binary extends Puzzle {
public Binary() {
super();

this.name = "Binary";

this.importer = new BinaryImporter(this);
this.exporter = new BinaryExporter(this);

this.factory = new BinaryCellFactory();
}

/** Initializes the game board. Called by the invoker of the class */
@Override
public void initializeView() {
boardView = new BinaryView((BinaryBoard) currentBoard);
boardView.setBoard(currentBoard);
addBoardListener(boardView);
}

/**
* Generates a random edu.rpi.legup.puzzle based on the difficulty
*
* @param difficulty level of difficulty (1-10)
* @return board of the random edu.rpi.legup.puzzle
*/
@Override
public Board generatePuzzle(int difficulty) {
return null;
}

// /**
// * Determines if the given dimensions are valid for Binary
// *
// * @param rows the number of rows
// * @param columns the number of columns
// * @return true if the given dimensions are valid for Binary, false otherwise
// */
// @Override
// public boolean isValidDimensions(int rows, int columns){
// return rows >= 2 && rows % 2 == 0 && columns >= 2 && columns % 2 == 0;
// }

@Override
public boolean isBoardComplete(Board board) {
BinaryBoard binaryBoard = (BinaryBoard) board;

for (ContradictionRule rule : contradictionRules) {
if (rule.checkContradiction(binaryBoard) == null) {
return false;
}
}
for (PuzzleElement data : binaryBoard.getPuzzleElements()) {
BinaryCell cell = (BinaryCell) data;
if (cell.getType() == BinaryType.UNKNOWN) {
return false;
}
}
return true;
}

@Override
public void onBoardChange(Board board) {}
}
84 changes: 84 additions & 0 deletions src/main/java/edu/rpi/legup/puzzle/binary/BinaryBoard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package edu.rpi.legup.puzzle.binary;

import edu.rpi.legup.model.gameboard.GridBoard;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import java.awt.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

public class BinaryBoard extends GridBoard {
private int size;

public BinaryBoard(int width, int height) {
super(width, height);
this.size = width;
}

public BinaryBoard(int size) {
super(size, size);
this.size = size;
}

@Override
public BinaryCell getCell(int x, int y) {
if (y * dimension.width + x >= puzzleElements.size()
|| x >= dimension.width
|| y >= dimension.height
|| x < 0
|| y < 0) {
return null;
}
return (BinaryCell) super.getCell(x, y);
}

public Set<BinaryCell> getRowCells(int rowNum) {
Set<BinaryCell> row = new HashSet<>();
for (int i = 0; i < size; i++) {
BinaryCell cell = getCell(i, rowNum);
row.add(cell);
}
return row;
}

public ArrayList<BinaryType> getRowTypes(int rowNum) {
ArrayList<BinaryType> row = new ArrayList<BinaryType>();
for (int i = 0; i < size; i++) {
BinaryCell cell = getCell(i, rowNum);
row.add(cell.getType());
}
return row;
}

public ArrayList<BinaryType> getColTypes(int colNum) {
ArrayList<BinaryType> col = new ArrayList<BinaryType>();
for (int i = 0; i < size; i++) {
BinaryCell cell = getCell(colNum, i);
col.add(cell.getType());
}
return col;
}

public Set<BinaryCell> getCol(int colNum) {
Set<BinaryCell> col = new HashSet<>();
for (int i = 0; i < size; i++) {
col.add(getCell(colNum, i));
}
return col;
}

@Override
public BinaryBoard copy() {
System.out.println("BinaryBoard copy()");
BinaryBoard copy = new BinaryBoard(dimension.width, dimension.height);
for (int x = 0; x < this.dimension.width; x++) {
for (int y = 0; y < this.dimension.height; y++) {
copy.setCell(x, y, getCell(x, y).copy());
}
}
for (PuzzleElement e : modifiedData) {
copy.getPuzzleElement(e).setModifiable(false);
}
return copy;
}
}
35 changes: 35 additions & 0 deletions src/main/java/edu/rpi/legup/puzzle/binary/BinaryCell.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package edu.rpi.legup.puzzle.binary;

import edu.rpi.legup.model.gameboard.GridCell;
import java.awt.Point;

public class BinaryCell extends GridCell<Integer> {
public BinaryCell(int valueInt, Point location) {
super(valueInt, location);
}

public BinaryType getType() {
switch (data) {
case 0:
return BinaryType.ZERO;
case 1:
return BinaryType.ONE;
case 2:
return BinaryType.UNKNOWN;
default:
if (data > 1) {
return BinaryType.UNKNOWN;
}
}
return null;
}

@Override
public BinaryCell copy() {
BinaryCell copy = new BinaryCell(data, (Point) location.clone());
copy.setIndex(index);
copy.setModifiable(isModifiable);
copy.setGiven(isGiven);
return copy;
}
}
Loading

0 comments on commit ecfbff6

Please sign in to comment.