Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
96b47cc
first commit for assingment 2
Mehul-Natu Jan 27, 2023
797e965
Added quadratic with calipers in benchmark
Mehul-Natu Jan 27, 2023
8bc3b60
Create Assignment
Mehul-Natu Jan 28, 2023
96c9298
Delete Assignment
Mehul-Natu Jan 28, 2023
b1f7cf0
Create test
Mehul-Natu Jan 28, 2023
441d0e4
Merge pull request #1 from Mehul-Natu/assingment_2
Mehul-Natu Jan 28, 2023
2348ccd
Add files via upload
Mehul-Natu Jan 28, 2023
e8fa3ee
Delete test
Mehul-Natu Jan 28, 2023
635ecd4
filewriter changes
Mehul-Natu Jan 28, 2023
83311dc
Merge branch 'Spring2023' of https://github.com/Mehul-Natu/INFO6205 i…
Mehul-Natu Jan 28, 2023
d3af3a1
insertion sort - sort changes
Mehul-Natu Jan 31, 2023
3299adf
Merge branch 'rchillyard:Spring2023' into Spring2023
Mehul-Natu Feb 4, 2023
8832bc7
Merge branch 'Spring2023' of https://github.com/Mehul-Natu/INFO6205 i…
Mehul-Natu Feb 4, 2023
bf7a4f7
final changes
Mehul-Natu Feb 4, 2023
385426f
Create test
Mehul-Natu Feb 4, 2023
41daaee
Merge branch 'Spring2023' of https://github.com/Mehul-Natu/INFO6205 i…
Mehul-Natu Feb 4, 2023
cc8a509
directory changes
Mehul-Natu Feb 4, 2023
d13802b
assingment 3 files added
Mehul-Natu Feb 4, 2023
8ebf83c
assingment 4 final commit
Mehul-Natu Feb 12, 2023
0747894
Create testfile
Mehul-Natu Feb 12, 2023
3348ec5
Add files via upload
Mehul-Natu Feb 12, 2023
183cf7a
Delete testfile
Mehul-Natu Feb 12, 2023
c5e6735
Assingment 5 commit
Mehul-Natu Feb 19, 2023
f1974d5
Merge branch 'Spring2023' of https://github.com/Mehul-Natu/INFO6205 i…
Mehul-Natu Feb 19, 2023
4818be0
added files to Assignment 5 folder
Mehul-Natu Feb 19, 2023
ddd6a5a
first game folder commit
Mehul-Natu Mar 7, 2023
6169b6c
With sudoku solver
Mehul-Natu Mar 9, 2023
da89a8b
solver working unoptimized
Mehul-Natu Mar 9, 2023
1346feb
sudoku game creater implemented
Mehul-Natu Mar 10, 2023
f2a2176
Added some generic code
rchillyard Mar 10, 2023
28d1228
integrated Generic Board
Mehul-Natu Mar 14, 2023
b5dd385
Running sudoku
Mehul-Natu Mar 15, 2023
b0ff885
Non-compiling cleanup based on Analysis and other stuff.
rchillyard Mar 15, 2023
11a8a83
changes in row and column in boardGrid and remved generic characters …
Mehul-Natu Mar 16, 2023
b0e5a27
Did some more genericizing
rchillyard Mar 17, 2023
2228822
generified move To MoveProcessor
Mehul-Natu Mar 23, 2023
d9b80a3
Refactored the move mechanism
rchillyard Apr 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions Assignments/Assignment-2/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

10 changes: 10 additions & 0 deletions Assignments/Assignment-3/Assignment_3_BenchMark_Insertion_Sort.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Number of Reps,N,Random,Ordered,Reverse Ordered,Partially Ordered
100,500,0.796886,0.411288,0.771079,0.351973,
100,1000,1.26744,0.211929,2.1041220000000003,0.38415900000000003,
100,2000,3.577124,0.196373,7.024915999999999,1.020151,
100,4000,13.394235000000002,0.164645,27.528134,3.6681,
100,8000,54.963801999999994,0.185653,109.694725,13.631863000000001,
100,16000,228.87135600000002,0.214038,439.061367,53.774669,
100,32000,1022.6707670000001,0.281978,1785.9298680000002,229.829533,
100,64000,5109.660646,0.48274700000000004,7166.697730000001,1041.272522,
100,128000,21258.790033999998,0.6721550000000001,30241.3736449,5653.250621,
Binary file not shown.
Binary file not shown.
Binary file added Assignments/Assignment-4/Benchmark.ods
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
19 changes: 19 additions & 0 deletions src/main/java/edu/neu/coe/info6205/game/Game.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package edu.neu.coe.info6205.game;

public interface Game<T, G> {
/**
* to make the next move
* <p>
* TODO this always returns null.
*/
Move<T> move();

void display();

boolean isGameOver();

Player<T, G> getWinner();

Player<T, G> checkWinner();

}
7 changes: 7 additions & 0 deletions src/main/java/edu/neu/coe/info6205/game/GameException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package edu.neu.coe.info6205.game;

public class GameException extends RuntimeException {
public GameException(String message) {
super(message);
}
}
30 changes: 30 additions & 0 deletions src/main/java/edu/neu/coe/info6205/game/Move.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package edu.neu.coe.info6205.game;

public class Move<T> {
final Integer row;
final Integer column;
T val;

public Move(int row, int column) {
this.row = row;
this.column = column;
}

public Move(int row, int column, T val) {
this.row = row;
this.column = column;
this.val = val;
}

public Integer getRow() {
return row;
}

public Integer getColumn() {
return column;
}

public T getVal() {
return val;
}
}
15 changes: 15 additions & 0 deletions src/main/java/edu/neu/coe/info6205/game/MoveStats.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package edu.neu.coe.info6205.game;

public class MoveStats<T> {

final Move<T> move;
final Long timeInMillis;

final Boolean validMove;

MoveStats(Move<T> move, long timeInMillis, boolean validMove) {
this.move = move;
this.timeInMillis = timeInMillis;
this.validMove = validMove;
}
}
6 changes: 6 additions & 0 deletions src/main/java/edu/neu/coe/info6205/game/MultiPlayerGame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package edu.neu.coe.info6205.game;


public abstract class MultiPlayerGame<T> implements Game<T, Object> {

}
55 changes: 55 additions & 0 deletions src/main/java/edu/neu/coe/info6205/game/Player.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package edu.neu.coe.info6205.game;

public class Player<T, G> {
private final int playerId;
private final boolean isBot;

private final PlayerStats<T> playerStats;
private Solver<T, G> moveGenerator;

public Player(int playerId, boolean isBot) {
this.playerId = playerId;
this.isBot = isBot;
playerStats = new PlayerStats<>();
}

public Player(int playerId, boolean isBot, Solver<T, G> moveGenerator) {
this.playerId = playerId;
this.isBot = isBot;
this.moveGenerator = moveGenerator;
playerStats = new PlayerStats<>();
}

public void addMove(Move<T> move, long timeInMilli, boolean validMove) {
this.playerStats.add(new MoveStats<>(move, timeInMilli, validMove));
}

public int getPlayerId() {
return playerId;
}

public boolean isBot() {
return isBot;
}

public int getNumberOfMoves() {
return playerStats.getNumberOfMoves();
}

public int getValidNumberOfMoves() {
return playerStats.getNumberOfValidMoves();
}

public Solver<T, G> getMoveGenerator() {
return moveGenerator;
}

public long getTotalTime() {
return playerStats.getTotalTime();
}

public double getAverageTimePerMove() {
return playerStats.getAverageTimePerMove();
}

}
39 changes: 39 additions & 0 deletions src/main/java/edu/neu/coe/info6205/game/PlayerStats.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package edu.neu.coe.info6205.game;

import java.util.ArrayList;
import java.util.List;

public class PlayerStats<T> {

private int numberOfMoves = 0;
private int numberOfValidMoves = 0;
private final List<MoveStats<T>> moveStatsList;

PlayerStats() {
moveStatsList = new ArrayList<>();
}

public void add(MoveStats<T> move) {
moveStatsList.add(move);
numberOfMoves++;
if (move.validMove) numberOfValidMoves++;
}

public int getNumberOfMoves() {
return numberOfMoves;
}

public int getNumberOfValidMoves() { return numberOfValidMoves; }

public List<MoveStats<T>> getMoveStatsList() {
return moveStatsList;
}

public long getTotalTime() {
return moveStatsList.stream().map(p -> p.timeInMillis).reduce(0L, Long::sum);
}

public double getAverageTimePerMove() {
return (double) getTotalTime()/moveStatsList.size();
}
}
48 changes: 48 additions & 0 deletions src/main/java/edu/neu/coe/info6205/game/Runner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package edu.neu.coe.info6205.game;

import edu.neu.coe.info6205.game.generics.Board;
import edu.neu.coe.info6205.game.generics.GridPosition;
import edu.neu.coe.info6205.game.generics.StateTransition;
import edu.neu.coe.info6205.game.singlePlayerGame.Games.Sudoku.Sudoku;
import edu.neu.coe.info6205.game.singlePlayerGame.Games.Sudoku.SudokuCreator;
import edu.neu.coe.info6205.game.singlePlayerGame.Games.Sudoku.SudokuSolver;
import edu.neu.coe.info6205.game.singlePlayerGame.UserGame;

public class Runner {

public static void main(String[] args) {


Sudoku game = new Sudoku(
new SudokuCreator(), true, new SudokuSolver(3), 3);
game.display();
/*System.out.println(game.getGrid().hashCode());
game.fillWrapper(new StateTransition<>(0, 0, 3));
System.out.println("after adding 3 - " + getHash(game.getGrid()));
game.fillWrapper(new StateTransition<>(0, 0, 4));
System.out.println("after adding 4 - " + getHash(game.getGrid()));
game.fillWrapper(new StateTransition<>(0, 0, 3));
System.out.println("after adding 3 - " + getHash(game.getGrid()));

*/
game.run();
game.checkWinner();
game.display();
// TODO check this assignment
Player<Integer, UserGame<Board<Integer, GridPosition, StateTransition<Integer, GridPosition>>, Integer>> winner = game.getWinner();
System.out.println(winner.getTotalTime());
System.out.println(winner.getAverageTimePerMove());

}

private static int getHash(Integer[][] grid) {
StringBuilder sb = new StringBuilder();

for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
sb.append(grid[i][j] != null ? grid[i][j] : "_");
}
}
return sb.toString().hashCode();
}
}
18 changes: 18 additions & 0 deletions src/main/java/edu/neu/coe/info6205/game/Solver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package edu.neu.coe.info6205.game;


public interface Solver<T, G> {

void solve(G game);

/**
* TODO this always returns null.
*
* @param grid the grid.
* @return a StateTransition.
*/
Move<T> getMove(T[][] grid);

SolverType getType();

}
7 changes: 7 additions & 0 deletions src/main/java/edu/neu/coe/info6205/game/SolverType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package edu.neu.coe.info6205.game;

public enum SolverType {

SingleTurnSolver,
MultiTurnSolver
}
9 changes: 9 additions & 0 deletions src/main/java/edu/neu/coe/info6205/game/generics/Board.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package edu.neu.coe.info6205.game.generics;

public interface Board<StateType, Position, BoardMove> {

StateType getState(Position position);

Board<StateType, Position, BoardMove> move(BoardMove move);

}
67 changes: 67 additions & 0 deletions src/main/java/edu/neu/coe/info6205/game/generics/Board_Grid.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package edu.neu.coe.info6205.game.generics;

import java.util.Arrays;

public class Board_Grid<StateType> implements Board<StateType, GridPosition, StateTransition<StateType, GridPosition>> {
public Board_Grid(Object[][] grid) {
this.grid = grid;
}

public Board_Grid(int rows, int columns) {
this.grid = new Object[rows][columns];
}

@Override
public StateType getState(GridPosition gridPosition) {
if (gridPosition != null)
// TODO this cast is OK -- it's because we have to store the grid as an array of Object
//noinspection unchecked
return (StateType) grid[gridPosition.x][gridPosition.y];
else return null;
}

/**
* Method to generate a new Board from <code>this</code>> Board, by applying the transitions defined by the given <code>move</code>>.
*
* @param move a move in the current game.
* @return a new Board based on <code>this</code> board and the effects of <code>move</code>.
*/
@Override
public Board<StateType, GridPosition, StateTransition<StateType, GridPosition>> move(StateTransition<StateType, GridPosition> move) {
Object[][] newGrid = Arrays.copyOf(grid, grid.length); // TODO check this
Board_Grid<StateType> newBoard = new Board_Grid<>(newGrid);
StateTransition<StateType, GridPosition> current = move;
while (current != null) {
// NOTE: the endPosition is not necessarily different from the startPosition.
// If the two positions are the same, then the state must be different.
GridPosition endPosition = current.endPosition();
// TODO create a method to update the state of the board at some position.
newBoard.grid[endPosition.x][endPosition.y] = current.transitionFunction().apply(getState(current.startPosition()));
current = current.next();
}
return newBoard;
}

// @Override
// public Board<StateType, GridPosition, StateTransition> move(StateTransition move) {
// Object[][] newGrid = Arrays.copyOf(grid,grid.length); // TODO check this
// Board_Grid<StateType, StateTransition> newBoard = new Board_Grid<>(newGrid);
// StateTransition current = move;
// while (current != null) {
//
// }
// return null;
// }

//
// @Override
// public Board<T, GridPosition, StateTransition<T>> move(StateTransition<T> move) {
// Object[][] newGrid = Arrays.copyOf(grid,grid.length); // TODO check this
// Board_Grid<T> newBoard = new Board_Grid<>(newGrid);
// newBoard.move(move);
// return newBoard;
// }

// This is essentially a StateType[][]. It's just that Java doesn't really support that concept.
protected final Object[][] grid;
}
Loading